@tuya-sat/micro-script 0.0.4 → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  const PORXY_SIGN = "--proxy";
3
4
  const params = process.argv.slice(2);
4
5
  const [action, ...rest] = params;
@@ -6,8 +7,10 @@ if (rest.includes(PORXY_SIGN)) {
6
7
  process.env.MICRO_DEBUGGER = "true";
7
8
  }
8
9
  if (action === "start") {
10
+ process.env.NODE_ENV = "development";
9
11
  require("../scripts/start");
10
12
  }
11
13
  else {
14
+ process.env.NODE_ENV = "production";
12
15
  require("../scripts/build");
13
16
  }
@@ -1,63 +1,5 @@
1
- export default function getCommonConfig({ isDev, isBuild }: {
2
- isDev: any;
3
- isBuild: any;
4
- }): {
5
- mode: string;
6
- output: {
7
- filename: string;
8
- chunkFilename: string;
9
- path: string;
10
- clean: boolean;
11
- library: {
12
- name: any;
13
- type: string;
14
- };
15
- };
16
- module: {
17
- rules: ({
18
- test: RegExp;
19
- use: any[];
20
- loader?: undefined;
21
- options?: undefined;
22
- } | {
23
- test: RegExp;
24
- use: {
25
- loader: string;
26
- options: {
27
- iesafe: boolean;
28
- };
29
- };
30
- loader?: undefined;
31
- options?: undefined;
32
- } | {
33
- test: RegExp[];
34
- loader: string;
35
- options: {
36
- limit: number;
37
- name: string;
38
- };
39
- use?: undefined;
40
- })[];
41
- };
42
- optimization: {
43
- runtimeChunk: string;
44
- splitChunks: {
45
- cacheGroups: {
46
- vendor: {
47
- test: RegExp;
48
- name: string;
49
- chunks: string;
50
- priority: number;
51
- };
52
- react: {
53
- test: RegExp;
54
- name: string;
55
- chunks: string;
56
- priority: number;
57
- };
58
- };
59
- };
60
- minimizer: (string | import("css-minimizer-webpack-plugin/types").default<import("css-minimizer-webpack-plugin/types").CssNanoOptionsExtended>)[];
61
- };
62
- plugins: any[];
63
- };
1
+ import { Configuration } from "webpack";
2
+ export default function getCommonConfig({ isDev, isBuild, }: {
3
+ isDev: boolean;
4
+ isBuild: boolean;
5
+ }): Configuration;
@@ -12,20 +12,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ //@ts-ignore
15
16
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
16
- const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
17
+ //@ts-ignore
17
18
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
19
+ const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
18
20
  const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
19
21
  const paths_1 = __importDefault(require("./paths"));
20
- function getCommonConfig({ isDev, isBuild }) {
22
+ function getCommonConfig({ isDev, isBuild, }) {
21
23
  const { name: packageName } = require(paths_1.default.appPkg);
22
24
  //获取style处理的loader
23
25
  const getStyleLoaders = (cssOptions, extraLoader) => {
24
26
  isBuild && cssOptions.importLoaders++;
25
27
  const loaders = [
26
- isBuild ? mini_css_extract_plugin_1.default.loader : "style-loader",
28
+ isBuild ? mini_css_extract_plugin_1.default.loader : require.resolve("style-loader"),
27
29
  {
28
- loader: "css-loader",
30
+ loader: require.resolve("css-loader"),
29
31
  options: Object.assign({ modules: {
30
32
  auto: true,
31
33
  localIdentName: isDev ? "[path][name]__[local]" : "[hash:base64]",
@@ -37,7 +39,7 @@ function getCommonConfig({ isDev, isBuild }) {
37
39
  * 默认应该比较新的浏览器了
38
40
  */
39
41
  isBuild && {
40
- loader: "postcss-loader",
42
+ loader: require.resolve("postcss-loader"),
41
43
  options: {
42
44
  postcssOptions: {
43
45
  plugins: ["postcss-preset-env"],
@@ -76,29 +78,24 @@ function getCommonConfig({ isDev, isBuild }) {
76
78
  test: /\.less$/,
77
79
  use: getStyleLoaders({
78
80
  importLoaders: 1,
79
- }, "less-loader"),
81
+ }, require.resolve("less-loader")),
80
82
  },
81
83
  {
82
84
  test: /\.(scss|sass)$/,
83
85
  use: getStyleLoaders({
84
86
  importLoaders: 1,
85
- }, "sass-loader"),
87
+ }, require.resolve("sass-loader")),
86
88
  },
87
89
  {
88
- test: /\.svg/,
89
- use: {
90
- loader: "svg-url-loader",
91
- options: {
92
- iesafe: true,
90
+ test: /\.(bmp|png|svg|jpg|jpeg|gif)$/i,
91
+ type: "asset",
92
+ parser: {
93
+ dataUrlCondition: {
94
+ maxSize: 10 * 1024,
93
95
  },
94
96
  },
95
- },
96
- {
97
- test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
98
- loader: "url-loader",
99
- options: {
100
- limit: 1024 * 10,
101
- name: "static/media/[name].[hash:8].[ext]",
97
+ generator: {
98
+ filename: "static/img/[hash][ext][query]",
102
99
  },
103
100
  },
104
101
  ].filter(Boolean),
@@ -133,6 +130,7 @@ function getCommonConfig({ isDev, isBuild }) {
133
130
  {
134
131
  from: paths_1.default.publicDir,
135
132
  filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return !resourcePath.includes(".html"); }),
133
+ noErrorOnMissing: true,
136
134
  },
137
135
  ],
138
136
  }),
@@ -1,2 +1,10 @@
1
- declare const _default: () => any;
1
+ import { Configuration } from "webpack";
2
+ export interface BaseParams {
3
+ isDev: boolean;
4
+ isBuild: boolean;
5
+ }
6
+ export interface WebpackCombineFunction {
7
+ (arg0: Configuration, arg1: BaseParams): Configuration;
8
+ }
9
+ declare const _default: () => Configuration;
2
10
  export default _default;
@@ -12,9 +12,6 @@ exports.default = () => {
12
12
  const isBuild = process.env.NODE_ENV === "production";
13
13
  const isDev = process.env.NODE_ENV === "development";
14
14
  const { annotations: { ["sdf.cli:microFramework"]: currentFramework }, } = fs_extra_1.default.readJSONSync(paths_1.default.manifest);
15
- const { setAdditionalWebpackConfig } = require(paths_1.default.microConfig);
16
- //额外的webpack配置
17
- const additionalWebpackConfig = (setAdditionalWebpackConfig === null || setAdditionalWebpackConfig === void 0 ? void 0 : setAdditionalWebpackConfig({ isDev, isBuild })) || {};
18
15
  //框架的webpack配置
19
16
  const frameworkConfig = (0, framework_1.default)({
20
17
  currentFramework,
@@ -23,7 +20,11 @@ exports.default = () => {
23
20
  });
24
21
  //公用的webpack配置
25
22
  const commonConfig = (0, webpack_common_1.default)({ isDev, isBuild });
26
- const outpotConfig = (0, webpack_merge_1.merge)(frameworkConfig, commonConfig, additionalWebpackConfig);
27
- //最后的配置
28
- return outpotConfig;
23
+ const baseConfig = (0, webpack_merge_1.merge)(frameworkConfig, commonConfig);
24
+ //额外的webpack结合function
25
+ const webpackCombineFunction = require(paths_1.default.microConfig).webpack;
26
+ if (webpackCombineFunction && typeof webpackCombineFunction === "function") {
27
+ return webpackCombineFunction(baseConfig, { isDev, isBuild });
28
+ }
29
+ return baseConfig;
29
30
  };
@@ -1,7 +1,12 @@
1
+ import { Configuration } from "webpack";
2
+ import { BaseParams } from "../config/webpack.config";
3
+ export interface Params extends BaseParams {
4
+ currentFramework: MICRO_FRAMEWORKS_TYPE;
5
+ }
6
+ export interface ParamsWithTs extends Params {
7
+ isTs: boolean;
8
+ }
1
9
  export declare type MICRO_FRAMEWORKS_TYPE = "REACT_TS" | "REACT_JS" | "VUE_TS" | "VUE_JS";
2
- declare const _default: ({ currentFramework, isDev, isBuild, }: {
3
- currentFramework: any;
4
- isDev: boolean;
5
- isBuild: boolean;
6
- }) => any;
10
+ export declare type FrameworkFunction = (arg0: Params) => Configuration;
11
+ declare const _default: ({ currentFramework, isDev, isBuild }: Params) => Configuration;
7
12
  export default _default;
@@ -8,7 +8,7 @@ const MICRO_FRAMEWORKS = new Map([
8
8
  ["VUE_TS", vue_config_1.vueTsConfig],
9
9
  ["VUE_JS", vue_config_1.vueJsConfig],
10
10
  ]);
11
- exports.default = ({ currentFramework, isDev, isBuild, }) => {
11
+ exports.default = ({ currentFramework, isDev, isBuild }) => {
12
12
  if (!MICRO_FRAMEWORKS.has(currentFramework)) {
13
13
  throw new Error("package.json需要配置microFramework字段");
14
14
  }
@@ -1,99 +1,4 @@
1
- import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
2
- import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
3
- import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
4
- declare const reactTsConfig: ({ isDev, isBuild, currentFramework }: {
5
- isDev: any;
6
- isBuild: any;
7
- currentFramework: any;
8
- }) => {
9
- module: {
10
- rules: ({
11
- test: RegExp;
12
- include: string;
13
- use: {
14
- loader: string;
15
- options: {
16
- presets: (string | (string | {
17
- useBuiltIns: string;
18
- corejs: number;
19
- })[] | (string | {
20
- runtime: string;
21
- })[])[];
22
- plugins: string[];
23
- };
24
- }[];
25
- exclude?: undefined;
26
- } | {
27
- test: RegExp;
28
- exclude: string;
29
- use: {
30
- loader: string;
31
- }[];
32
- include?: undefined;
33
- } | {
34
- test: string;
35
- include: string;
36
- use: {
37
- loader: string;
38
- options: {
39
- microFramework: any;
40
- };
41
- }[];
42
- exclude?: undefined;
43
- })[];
44
- };
45
- plugins: (ReactRefreshWebpackPlugin | ForkTsCheckerWebpackPlugin)[];
46
- entry: string;
47
- resolve: {
48
- extensions: string[];
49
- plugins: TsconfigPathsPlugin[];
50
- };
51
- };
52
- declare const reactJsConfig: ({ isDev, isBuild, currentFramework }: {
53
- isDev: any;
54
- isBuild: any;
55
- currentFramework: any;
56
- }) => {
57
- module: {
58
- rules: ({
59
- test: RegExp;
60
- include: string;
61
- use: {
62
- loader: string;
63
- options: {
64
- presets: (string | (string | {
65
- useBuiltIns: string;
66
- corejs: number;
67
- })[] | (string | {
68
- runtime: string;
69
- })[])[];
70
- plugins: string[];
71
- };
72
- }[];
73
- exclude?: undefined;
74
- } | {
75
- test: RegExp;
76
- exclude: string;
77
- use: {
78
- loader: string;
79
- }[];
80
- include?: undefined;
81
- } | {
82
- test: string;
83
- include: string;
84
- use: {
85
- loader: string;
86
- options: {
87
- microFramework: any;
88
- };
89
- }[];
90
- exclude?: undefined;
91
- })[];
92
- };
93
- plugins: (ReactRefreshWebpackPlugin | ForkTsCheckerWebpackPlugin)[];
94
- entry: string;
95
- resolve: {
96
- extensions: string[];
97
- };
98
- };
1
+ import { FrameworkFunction } from "./index";
2
+ declare const reactTsConfig: FrameworkFunction;
3
+ declare const reactJsConfig: FrameworkFunction;
99
4
  export { reactTsConfig, reactJsConfig };
@@ -8,7 +8,7 @@ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-re
8
8
  const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
9
9
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
10
10
  const paths_1 = __importDefault(require("../config/paths"));
11
- const reactConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
11
+ const reactConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
12
12
  return {
13
13
  module: {
14
14
  rules: [
@@ -17,25 +17,27 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
17
17
  include: paths_1.default.appSrc,
18
18
  use: [
19
19
  {
20
- loader: "babel-loader",
20
+ loader: require.resolve("babel-loader"),
21
21
  options: {
22
22
  presets: [
23
23
  [
24
- "@babel/preset-env",
24
+ require.resolve("@babel/preset-env"),
25
25
  {
26
26
  useBuiltIns: "entry",
27
27
  corejs: 3,
28
28
  },
29
29
  ],
30
30
  [
31
- "@babel/preset-react",
31
+ require.resolve("@babel/preset-react"),
32
32
  {
33
33
  runtime: "automatic",
34
34
  },
35
35
  ],
36
- isTs && "@babel/preset-typescript",
36
+ isTs && require.resolve("@babel/preset-typescript"),
37
+ ].filter(Boolean),
38
+ plugins: [
39
+ isDev && require.resolve("react-refresh/babel"),
37
40
  ].filter(Boolean),
38
- plugins: [isDev && "react-refresh/babel"].filter(Boolean),
39
41
  },
40
42
  },
41
43
  ],
@@ -46,7 +48,7 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
46
48
  exclude: paths_1.default.appSrc,
47
49
  use: [
48
50
  {
49
- loader: "babel-loader",
51
+ loader: require.resolve("babel-loader"),
50
52
  },
51
53
  ],
52
54
  },
@@ -55,14 +57,14 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
55
57
  include: paths_1.default.appSrc,
56
58
  use: [
57
59
  {
58
- loader: "@tuya-sat/micro-dev-loader",
60
+ loader: require.resolve("@tuya-sat/micro-dev-loader"),
59
61
  options: {
60
62
  microFramework: currentFramework,
61
63
  },
62
64
  },
63
65
  ],
64
66
  },
65
- ].filter(Boolean),
67
+ ].filter((value) => Boolean(value)),
66
68
  },
67
69
  plugins: [
68
70
  isDev && new react_refresh_webpack_plugin_1.default(),
@@ -77,15 +79,15 @@ const reactConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
77
79
  mode: "write-references",
78
80
  },
79
81
  }),
80
- ].filter(Boolean),
82
+ ].filter((value) => Boolean(value)),
81
83
  };
82
84
  };
83
- const reactTsConfig = ({ isDev, isBuild, currentFramework }) => (Object.assign({ entry: paths_1.default.ReactTsEntryFile, resolve: {
85
+ const reactTsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactTsEntryFile, resolve: {
84
86
  extensions: [".tsx", ".ts", ".js"],
85
87
  plugins: [new tsconfig_paths_webpack_plugin_1.default()],
86
88
  } }, reactConfig({ isDev, isBuild, currentFramework, isTs: true })));
87
89
  exports.reactTsConfig = reactTsConfig;
88
- const reactJsConfig = ({ isDev, isBuild, currentFramework }) => (Object.assign({ entry: paths_1.default.ReactJsEntryFile, resolve: {
90
+ const reactJsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_1.default.ReactJsEntryFile, resolve: {
89
91
  extensions: [".jsx", ".js"],
90
92
  } }, reactConfig({ isDev, isBuild, currentFramework, isTs: false })));
91
93
  exports.reactJsConfig = reactJsConfig;
@@ -1,115 +1,4 @@
1
- import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
2
- declare const vueTsConfig: ({ isDev, isBuild, currentFramework }: {
3
- isDev: any;
4
- isBuild: any;
5
- currentFramework: any;
6
- }) => {
7
- module: {
8
- rules: ({
9
- test: RegExp;
10
- include: string;
11
- use: {
12
- loader: string;
13
- options: {
14
- presets: (string | {
15
- useBuiltIns: string;
16
- corejs: number;
17
- })[][];
18
- };
19
- }[];
20
- loader?: undefined;
21
- options?: undefined;
22
- } | {
23
- test: RegExp;
24
- include: string;
25
- use: {
26
- loader: string;
27
- }[];
28
- loader?: undefined;
29
- options?: undefined;
30
- } | {
31
- test: RegExp;
32
- include: string;
33
- loader: string;
34
- options: {
35
- appendTsSuffixTo: RegExp[];
36
- transpileOnly: boolean;
37
- };
38
- use?: undefined;
39
- } | {
40
- test: string;
41
- include: string;
42
- use: {
43
- loader: string;
44
- options: {
45
- microFramework: any;
46
- };
47
- }[];
48
- loader?: undefined;
49
- options?: undefined;
50
- })[];
51
- };
52
- plugins: any[];
53
- entry: string;
54
- resolve: {
55
- extensions: string[];
56
- plugins: TsconfigPathsPlugin[];
57
- };
58
- };
59
- declare const vueJsConfig: ({ isDev, isBuild, currentFramework }: {
60
- isDev: any;
61
- isBuild: any;
62
- currentFramework: any;
63
- }) => {
64
- module: {
65
- rules: ({
66
- test: RegExp;
67
- include: string;
68
- use: {
69
- loader: string;
70
- options: {
71
- presets: (string | {
72
- useBuiltIns: string;
73
- corejs: number;
74
- })[][];
75
- };
76
- }[];
77
- loader?: undefined;
78
- options?: undefined;
79
- } | {
80
- test: RegExp;
81
- include: string;
82
- use: {
83
- loader: string;
84
- }[];
85
- loader?: undefined;
86
- options?: undefined;
87
- } | {
88
- test: RegExp;
89
- include: string;
90
- loader: string;
91
- options: {
92
- appendTsSuffixTo: RegExp[];
93
- transpileOnly: boolean;
94
- };
95
- use?: undefined;
96
- } | {
97
- test: string;
98
- include: string;
99
- use: {
100
- loader: string;
101
- options: {
102
- microFramework: any;
103
- };
104
- }[];
105
- loader?: undefined;
106
- options?: undefined;
107
- })[];
108
- };
109
- plugins: any[];
110
- entry: string;
111
- resolve: {
112
- extensions: string[];
113
- };
114
- };
1
+ import { FrameworkFunction } from "./index";
2
+ declare const vueTsConfig: FrameworkFunction;
3
+ declare const vueJsConfig: FrameworkFunction;
115
4
  export { vueTsConfig, vueJsConfig };
@@ -7,7 +7,7 @@ exports.vueJsConfig = exports.vueTsConfig = void 0;
7
7
  const paths_js_1 = __importDefault(require("../config/paths.js"));
8
8
  const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
9
9
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
10
- const vueConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
10
+ const vueConfig = ({ isDev, isBuild, currentFramework, isTs, }) => {
11
11
  /**
12
12
  * 运行时引入以避免vue-loader检查
13
13
  */
@@ -16,21 +16,27 @@ const vueConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
16
16
  module: {
17
17
  rules: [
18
18
  {
19
- test: /\.js$/,
19
+ test: /\.(js|ts)$/,
20
20
  include: paths_js_1.default.appSrc,
21
21
  use: [
22
22
  {
23
- loader: "babel-loader",
23
+ loader: require.resolve("babel-loader"),
24
24
  options: {
25
25
  presets: [
26
26
  [
27
- "@babel/preset-env",
27
+ require.resolve("@babel/preset-env"),
28
28
  {
29
29
  useBuiltIns: "entry",
30
30
  corejs: 3,
31
31
  },
32
32
  ],
33
- ],
33
+ isTs && [
34
+ require.resolve("@babel/preset-typescript"),
35
+ {
36
+ allExtensions: true,
37
+ },
38
+ ],
39
+ ].filter(Boolean),
34
40
  },
35
41
  },
36
42
  ],
@@ -40,29 +46,23 @@ const vueConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
40
46
  include: paths_js_1.default.appSrc,
41
47
  use: [
42
48
  {
43
- loader: "vue-loader",
49
+ loader: require.resolve("vue-loader"),
44
50
  },
45
51
  ],
46
52
  },
47
- isTs && {
48
- test: /\.ts$/,
49
- include: paths_js_1.default.appSrc,
50
- loader: "ts-loader",
51
- options: { appendTsSuffixTo: [/\.vue$/], transpileOnly: true },
52
- },
53
53
  isDev && {
54
54
  test: isTs ? paths_js_1.default.vueTsEntryFile : paths_js_1.default.vueJsEntryFile,
55
55
  include: paths_js_1.default.appSrc,
56
56
  use: [
57
57
  {
58
- loader: "@tuya-sat/micro-dev-loader",
58
+ loader: require.resolve("@tuya-sat/micro-dev-loader"),
59
59
  options: {
60
60
  microFramework: currentFramework,
61
61
  },
62
62
  },
63
63
  ],
64
64
  },
65
- ].filter(Boolean),
65
+ ].filter((value) => Boolean(value)),
66
66
  },
67
67
  plugins: [
68
68
  new VueLoaderPlugin(),
@@ -70,12 +70,12 @@ const vueConfig = ({ isDev, isBuild, currentFramework, isTs }) => {
70
70
  ].filter(Boolean),
71
71
  };
72
72
  };
73
- const vueTsConfig = ({ isDev, isBuild, currentFramework }) => (Object.assign({ entry: paths_js_1.default.vueTsEntryFile, resolve: {
73
+ const vueTsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_js_1.default.vueTsEntryFile, resolve: {
74
74
  extensions: [".vue", ".ts", ".js"],
75
75
  plugins: [new tsconfig_paths_webpack_plugin_1.default()],
76
76
  } }, vueConfig({ isDev, isBuild, currentFramework, isTs: true })));
77
77
  exports.vueTsConfig = vueTsConfig;
78
- const vueJsConfig = ({ isDev, isBuild, currentFramework }) => (Object.assign({ entry: paths_js_1.default.vueJsEntryFile, resolve: {
78
+ const vueJsConfig = ({ isDev, isBuild, currentFramework, }) => (Object.assign({ entry: paths_js_1.default.vueJsEntryFile, resolve: {
79
79
  extensions: [".vue", ".js"],
80
80
  } }, vueConfig({ isDev, isBuild, currentFramework, isTs: false })));
81
81
  exports.vueJsConfig = vueJsConfig;
@@ -1 +1,2 @@
1
- export default function useMocks(app: any): void;
1
+ import Server from "webpack-dev-server";
2
+ export default function useMocks(app: Server["app"]): void;
@@ -3,12 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- process.env.NODE_ENV = "production";
7
6
  const webpack_1 = __importDefault(require("webpack"));
8
7
  const chalk_1 = __importDefault(require("chalk"));
9
8
  const ora_1 = __importDefault(require("ora"));
10
9
  const webpack_config_1 = __importDefault(require("../config/webpack.config"));
11
- const THROW_ERR_INFO = "只是为了阻断进程,忽略这行报错,往上看";
12
10
  const BUILD_FAIL_TIP = "糟糕:打包失败了,下面是具体信息";
13
11
  const spinner = (0, ora_1.default)("building").start();
14
12
  const config = (0, webpack_config_1.default)();
@@ -17,14 +15,14 @@ const config = (0, webpack_config_1.default)();
17
15
  spinner.fail();
18
16
  console.log(chalk_1.default.red(BUILD_FAIL_TIP));
19
17
  console.log(err.stack || err);
20
- return;
18
+ process.exit(1);
21
19
  }
22
20
  const { version, assets, warnings, errors } = stats.toJson();
23
21
  if (stats.hasErrors()) {
24
22
  spinner.fail();
25
23
  console.log(chalk_1.default.red(BUILD_FAIL_TIP));
26
24
  console.log(errors);
27
- return;
25
+ process.exit(1);
28
26
  }
29
27
  spinner.succeed();
30
28
  if (stats.hasWarnings()) {
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- process.env.NODE_ENV = "development";
16
15
  const webpack_1 = __importDefault(require("webpack"));
17
16
  const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
18
17
  const ora_1 = __importDefault(require("ora"));
@@ -21,7 +20,6 @@ const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
21
20
  const paths_1 = __importDefault(require("../config/paths"));
22
21
  const webpack_config_1 = __importDefault(require("../config/webpack.config"));
23
22
  const mock_1 = __importDefault(require("../module/mock"));
24
- const isProxy = process.env.MICRO_DEBUGGER === "true";
25
23
  const config = Object.assign(Object.assign({}, (0, webpack_config_1.default)()), {
26
24
  //下面所有配置都是为了精简terminal输出
27
25
  infrastructureLogging: {
@@ -47,14 +45,15 @@ new micro_dev_loader_1.LayoutMockPlugin().apply(compiler);
47
45
  "Access-Control-Allow-Origin": "*",
48
46
  "Access-Control-Allow-Headers": "*",
49
47
  },
50
- onBeforeSetupMiddleware({ app }) {
48
+ setupMiddlewares(middlewares, { app }) {
51
49
  micro_dev_loader_1.LayoutMockPlugin.useLayoutStatic(app);
52
50
  (0, mock_1.default)(app);
53
- if (isProxy) {
51
+ if (process.env.MICRO_DEBUGGER === "true") {
54
52
  const createProxy = require("@tuya-sat/micro-dev-proxy").default;
55
53
  const { debuggerConfig } = require(paths_1.default.microConfig);
56
54
  createProxy(debuggerConfig)(app);
57
55
  }
56
+ return middlewares;
58
57
  },
59
58
  }, compiler);
60
59
  compiler.hooks.watchRun.tap("MyPlugin", () => {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "0.0.4",
3
+ "version": "1.0.0-rc.4",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "dev": "tsc --watch",
8
+ "dev": "rm -rf dist/ && tsc --watch",
9
9
  "build": "rm -rf dist/ && tsc",
10
10
  "prepublish": "yarn build"
11
11
  },
@@ -15,10 +15,11 @@
15
15
  "@babel/preset-react": "^7.14.5",
16
16
  "@babel/preset-typescript": "^7.15.0",
17
17
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
18
- "@tuya-sat/micro-dev-loader": "0.0.4",
19
- "@tuya-sat/micro-dev-proxy": "0.0.4",
18
+ "@tuya-sat/micro-dev-loader": "1.0.0-rc.4",
19
+ "@tuya-sat/micro-dev-proxy": "1.0.0-rc.4",
20
20
  "babel-loader": "^8.2.2",
21
21
  "babel-plugin-import": "^1.13.3",
22
+ "chalk": "4.1.2",
22
23
  "copy-webpack-plugin": "^9.0.1",
23
24
  "css-loader": "^6.4.0",
24
25
  "css-minimizer-webpack-plugin": "^3.2.0",
@@ -30,6 +31,7 @@
30
31
  "ora": "5.4.1",
31
32
  "path-to-regexp": "^6.2.0",
32
33
  "portfinder": "^1.0.28",
34
+ "postcss": "^8.4.5",
33
35
  "postcss-loader": "^6.1.1",
34
36
  "postcss-preset-env": "^6.7.0",
35
37
  "react-refresh": "^0.10.0",
@@ -38,7 +40,6 @@
38
40
  "sass-loader": "^12.1.0",
39
41
  "style-loader": "^3.3.0",
40
42
  "svg-url-loader": "^7.1.1",
41
- "ts-loader": "^9.2.6",
42
43
  "tsconfig-paths-webpack-plugin": "^3.5.1",
43
44
  "url-loader": "^4.1.1",
44
45
  "vue-loader": "16.8.2",
@@ -57,5 +58,6 @@
57
58
  "saas",
58
59
  "cloud",
59
60
  "tuya"
60
- ]
61
+ ],
62
+ "stableVersion": "0.0.4"
61
63
  }