@tuya-sat/micro-script 2.3.1 → 2.3.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.
@@ -1,9 +1,5 @@
1
1
  import { Configuration } from "webpack";
2
- import { ThemeCat } from "@tuya-sat/micro-dev-loader/dist/less/utils/index";
3
- declare type ThemeEnv = ThemeCat | undefined;
4
- export declare const validateMicroTheme: () => ThemeEnv;
5
2
  export default function getCommonConfig({ isDev, isBuild, }: {
6
3
  isDev: boolean;
7
4
  isBuild: boolean;
8
5
  }): Configuration;
9
- export {};
@@ -12,7 +12,7 @@ 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
- exports.validateMicroTheme = void 0;
15
+ const path_1 = __importDefault(require("path"));
16
16
  //@ts-ignore
17
17
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
18
18
  //@ts-ignore
@@ -23,25 +23,15 @@ const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
23
23
  const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
24
24
  const micro_utils_1 = require("@tuya-sat/micro-utils");
25
25
  const paths_1 = __importDefault(require("./paths"));
26
+ const theme_1 = require("../utils/theme");
27
+ const DYNAMIC_CHUNK_PREFIX = "micro_app_lazy";
26
28
  const toArray = (value) => {
27
29
  return Array.isArray(value) ? value : [value];
28
30
  };
29
- const validateMicroTheme = () => {
30
- const microTheme = process.env.MICRO_THEME;
31
- if (microTheme && ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(microTheme)) {
32
- console.error(`请设置正确的MICRO_THEME环境变量,当前值为${microTheme},请修改为${index_1.LIGHT_THEME}或${index_1.DARK_THEME}`);
33
- return process.exit(1);
34
- }
35
- return microTheme;
36
- };
37
- exports.validateMicroTheme = validateMicroTheme;
38
31
  function getCommonConfig({ isDev, isBuild, }) {
39
32
  const { name: packageName } = require(paths_1.default.appPkg);
40
33
  const { annotations } = (0, micro_utils_1.parseManifest)();
41
- const devMicroTheme = (0, exports.validateMicroTheme)();
42
- const enableThemeCompile = isDev
43
- ? !!devMicroTheme
44
- : annotations["sdf.feat:colorTheme"];
34
+ const enableThemeCompile = annotations["sdf.feat:colorTheme"];
45
35
  //获取style处理的loader
46
36
  const getStyleLoaders = (extraLoader = []) => {
47
37
  extraLoader = toArray(extraLoader);
@@ -73,7 +63,7 @@ function getCommonConfig({ isDev, isBuild, }) {
73
63
  ? "static/js/[name].[contenthash:8].js"
74
64
  : "static/js/[name].bundle.js",
75
65
  chunkFilename: isBuild
76
- ? "static/js/[name].[contenthash:8].chunk.js"
66
+ ? `static/js/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.js`
77
67
  : "static/js/[name].chunk.js",
78
68
  path: paths_1.default.dist,
79
69
  clean: true,
@@ -94,19 +84,18 @@ function getCommonConfig({ isDev, isBuild, }) {
94
84
  {
95
85
  loader: require.resolve("less-loader"),
96
86
  options: {
97
- lessOptions: Object.assign(Object.assign({}, (isDev
98
- ? enableThemeCompile
99
- ? (0, index_1.getLessOptions)(devMicroTheme)
100
- : {}
101
- : annotations["sdf.feat:colorTheme"]
102
- ? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
103
- : {})), { javascriptEnabled: true }),
87
+ lessOptions: Object.assign(Object.assign({}, (enableThemeCompile
88
+ ? isDev
89
+ ? (0, index_1.getLessOptions)((0, theme_1.getBaseTheme)())
90
+ : (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
91
+ : {})), { javascriptEnabled: true }),
104
92
  },
105
93
  },
106
94
  enableThemeCompile &&
107
95
  require("@tuya-sat/micro-dev-loader").changeAntdGlobalImport,
108
96
  enableThemeCompile &&
109
- require("@tuya-sat/micro-dev-loader").changeTuyaSatComponentImport
97
+ require("@tuya-sat/micro-dev-loader")
98
+ .changeTuyaSatComponentImport,
110
99
  ].filter(Boolean)),
111
100
  },
112
101
  {
@@ -162,7 +151,8 @@ function getCommonConfig({ isDev, isBuild, }) {
162
151
  patterns: [
163
152
  {
164
153
  from: paths_1.default.publicDir,
165
- filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return resourcePath !== paths_1.default.spaHtml; }),
154
+ // 使用path.resolve纠正resourcePath,因为这个resourcePath值在windows平台显示的是POSIX值;
155
+ filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return path_1.default.resolve(resourcePath) !== paths_1.default.spaHtml; }),
166
156
  noErrorOnMissing: true,
167
157
  },
168
158
  ],
@@ -170,7 +160,7 @@ function getCommonConfig({ isDev, isBuild, }) {
170
160
  isBuild &&
171
161
  new mini_css_extract_plugin_1.default({
172
162
  filename: "static/css/[name].[contenthash:8].css",
173
- chunkFilename: "static/css/[name].[contenthash:8].chunk.css",
163
+ chunkFilename: `static/css/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.css`,
174
164
  }),
175
165
  isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
176
166
  ].filter((value) => Boolean(value)),
@@ -39,7 +39,7 @@ const cheerio_1 = __importDefault(require("cheerio"));
39
39
  const axios_1 = __importDefault(require("axios"));
40
40
  const fakeSaas_1 = __importStar(require("./fakeSaas"));
41
41
  const paths_1 = __importDefault(require("../../config/paths"));
42
- const webpack_common_1 = require("../../config/webpack.common");
42
+ const theme_1 = require("../../utils/theme");
43
43
  const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.1.516/";
44
44
  function staticMain(app, debuggerConfig) {
45
45
  app.get([
@@ -95,7 +95,7 @@ function insertScript($, debuggerConfig) {
95
95
  let themeConfig = saas.custom_configs.find((item) => {
96
96
  return item.config_key === "dynamic_theme";
97
97
  }) || initalCustom_configs(saas);
98
- const theme = (0, webpack_common_1.validateMicroTheme)();
98
+ const theme = (0, theme_1.getBaseTheme)();
99
99
  themeConfig.config_value_json = JSON.stringify(Object.assign(Object.assign(Object.assign({}, JSON.parse(themeConfig.config_value_json)), (theme ? {
100
100
  supportedTheme: theme,
101
101
  } : {})), readThemeConfig()));
@@ -30,11 +30,16 @@ const config = (0, webpack_config_1.default)();
30
30
  console.log(warnings.map((item) => item.message).join("\n"));
31
31
  }
32
32
  console.log(chalk_1.default.yellow(`当前打包工具:webpack@${version}`));
33
- console.log(chalk_1.default.blue("资源清单:"));
34
- const assetsInfo = assets.map(({ size, name }) => {
35
- return ` ${name} ${chalk_1.default.white(size > 1024 ? `~${Math.floor(size / 1024)}KB` : `${size}B`)}`;
36
- });
37
- assetsInfo.map((item) => {
38
- console.log(chalk_1.default.blue(item));
39
- });
33
+ if (assets) {
34
+ console.log(chalk_1.default.blue("资源清单:"));
35
+ const assetsInfo = assets.map(({ size, name }) => {
36
+ return ` ${name} ${chalk_1.default.white(size > 1024 ? `~${Math.floor(size / 1024)}KB` : `${size}B`)}`;
37
+ });
38
+ assetsInfo.map((item) => {
39
+ console.log(chalk_1.default.blue(item));
40
+ });
41
+ }
42
+ else {
43
+ console.log(chalk_1.default.blue("无资源清单"));
44
+ }
40
45
  });
@@ -0,0 +1,2 @@
1
+ import { ThemeCat } from "@tuya-sat/micro-dev-loader/dist/less/utils/index";
2
+ export declare const getBaseTheme: () => ThemeCat;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBaseTheme = void 0;
4
+ const index_1 = require("@tuya-sat/micro-dev-loader/dist/less/utils/index");
5
+ const getBaseTheme = () => {
6
+ const microTheme = process.env.MICRO_THEME;
7
+ if (!microTheme || ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(microTheme))
8
+ return index_1.LIGHT_THEME;
9
+ return microTheme;
10
+ };
11
+ exports.getBaseTheme = getBaseTheme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "2.3.1",
3
+ "version": "2.3.4",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -20,9 +20,9 @@
20
20
  "@babel/preset-react": "7.16.7",
21
21
  "@babel/preset-typescript": "7.16.7",
22
22
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
23
- "@tuya-sat/micro-dev-loader": "2.3.1",
24
- "@tuya-sat/micro-dev-proxy": "2.3.1",
25
- "@tuya-sat/micro-utils": "2.3.1",
23
+ "@tuya-sat/micro-dev-loader": "2.3.4",
24
+ "@tuya-sat/micro-dev-proxy": "2.3.4",
25
+ "@tuya-sat/micro-utils": "2.3.4",
26
26
  "babel-loader": "8.2.4",
27
27
  "babel-plugin-import": "1.13.3",
28
28
  "chalk": "4.1.2",