@tuya-sat/micro-script 3.0.0-beta.3 → 3.0.2
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
|
-
|
|
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,26 +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
|
|
26
|
+
const theme_1 = require("../utils/theme");
|
|
27
|
+
const DYNAMIC_CHUNK_PREFIX = "micro_app_lazy";
|
|
27
28
|
const toArray = (value) => {
|
|
28
29
|
return Array.isArray(value) ? value : [value];
|
|
29
30
|
};
|
|
30
|
-
const validateMicroTheme = () => {
|
|
31
|
-
const microTheme = process.env.MICRO_THEME;
|
|
32
|
-
if (microTheme && ![index_1.DARK_THEME, index_1.LIGHT_THEME].includes(microTheme)) {
|
|
33
|
-
console.error(`请设置正确的MICRO_THEME环境变量,当前值为${microTheme},请修改为${index_1.LIGHT_THEME}或${index_1.DARK_THEME}`);
|
|
34
|
-
return process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
return microTheme;
|
|
37
|
-
};
|
|
38
|
-
exports.validateMicroTheme = validateMicroTheme;
|
|
39
31
|
function getCommonConfig({ isDev, isBuild, }) {
|
|
40
32
|
const { name: packageName } = require(paths_1.default.appPkg);
|
|
41
33
|
const { annotations } = (0, micro_utils_1.parseManifest)();
|
|
42
|
-
const
|
|
43
|
-
const enableThemeCompile = isDev
|
|
44
|
-
? !!devMicroTheme
|
|
45
|
-
: annotations["sdf.feat:colorTheme"];
|
|
34
|
+
const enableThemeCompile = annotations["sdf.feat:colorTheme"];
|
|
46
35
|
//获取style处理的loader
|
|
47
36
|
const getStyleLoaders = (extraLoader = []) => {
|
|
48
37
|
extraLoader = toArray(extraLoader);
|
|
@@ -74,7 +63,7 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
74
63
|
? "static/js/[name].[contenthash:8].js"
|
|
75
64
|
: "static/js/[name].bundle.js",
|
|
76
65
|
chunkFilename: isBuild
|
|
77
|
-
?
|
|
66
|
+
? `static/js/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.js`
|
|
78
67
|
: "static/js/[name].chunk.js",
|
|
79
68
|
path: paths_1.default.dist,
|
|
80
69
|
clean: true,
|
|
@@ -95,13 +84,11 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
95
84
|
{
|
|
96
85
|
loader: require.resolve("less-loader"),
|
|
97
86
|
options: {
|
|
98
|
-
lessOptions: Object.assign(Object.assign({}, (
|
|
99
|
-
?
|
|
100
|
-
? (0, index_1.getLessOptions)(
|
|
101
|
-
:
|
|
102
|
-
:
|
|
103
|
-
? (0, index_1.getLessOptions)(index_1.LIGHT_THEME)
|
|
104
|
-
: {})), { 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 }),
|
|
105
92
|
},
|
|
106
93
|
},
|
|
107
94
|
enableThemeCompile &&
|
|
@@ -130,28 +117,18 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
130
117
|
].filter(Boolean),
|
|
131
118
|
},
|
|
132
119
|
optimization: {
|
|
133
|
-
runtimeChunk: "single",
|
|
134
120
|
splitChunks: {
|
|
135
|
-
cacheGroups: Object.assign(
|
|
121
|
+
cacheGroups: Object.assign({}, (enableThemeCompile
|
|
136
122
|
? {
|
|
137
123
|
vendorCss: {
|
|
138
124
|
test: /([\\/]node_modules[\\/][\s\S]+(\.less|\.css)$)|([\\/]src[\\/]styles[\\/]global\.less)/,
|
|
139
125
|
name: "light",
|
|
140
126
|
chunks: "all",
|
|
127
|
+
minSize: 0,
|
|
141
128
|
priority: 2,
|
|
142
129
|
},
|
|
143
130
|
}
|
|
144
|
-
: {})),
|
|
145
|
-
test: /[\\/]node_modules[\\/]/,
|
|
146
|
-
name: "vendors-others",
|
|
147
|
-
chunks: "all",
|
|
148
|
-
priority: 0,
|
|
149
|
-
}, react: {
|
|
150
|
-
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
|
|
151
|
-
name: "react-related",
|
|
152
|
-
chunks: "all",
|
|
153
|
-
priority: 1,
|
|
154
|
-
} }),
|
|
131
|
+
: {})),
|
|
155
132
|
},
|
|
156
133
|
minimizer: ["...", new css_minimizer_webpack_plugin_1.default()],
|
|
157
134
|
},
|
|
@@ -164,7 +141,8 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
164
141
|
patterns: [
|
|
165
142
|
{
|
|
166
143
|
from: paths_1.default.publicDir,
|
|
167
|
-
|
|
144
|
+
// 使用path.resolve纠正resourcePath,因为这个resourcePath值在windows平台显示的是POSIX值;
|
|
145
|
+
filter: (resourcePath) => __awaiter(this, void 0, void 0, function* () { return path_1.default.resolve(resourcePath) !== paths_1.default.spaHtml; }),
|
|
168
146
|
noErrorOnMissing: true,
|
|
169
147
|
},
|
|
170
148
|
],
|
|
@@ -172,10 +150,9 @@ function getCommonConfig({ isDev, isBuild, }) {
|
|
|
172
150
|
isBuild &&
|
|
173
151
|
new mini_css_extract_plugin_1.default({
|
|
174
152
|
filename: "static/css/[name].[contenthash:8].css",
|
|
175
|
-
chunkFilename:
|
|
153
|
+
chunkFilename: `static/css/${DYNAMIC_CHUNK_PREFIX}-[name].[contenthash:8].chunk.css`,
|
|
176
154
|
}),
|
|
177
155
|
isBuild && enableThemeCompile && new micro_dev_loader_1.ThemePlugin(),
|
|
178
|
-
isBuild && new locales_1.default(),
|
|
179
156
|
].filter((value) => Boolean(value)),
|
|
180
157
|
};
|
|
181
158
|
}
|
|
@@ -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
|
|
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,
|
|
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
|
? {
|
|
101
101
|
supportedTheme: theme,
|
package/dist/scripts/build.js
CHANGED
|
@@ -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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
|
|
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,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": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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": "3.0.
|
|
24
|
-
"@tuya-sat/micro-dev-proxy": "3.0.
|
|
25
|
-
"@tuya-sat/micro-utils": "3.0.
|
|
23
|
+
"@tuya-sat/micro-dev-loader": "3.0.2",
|
|
24
|
+
"@tuya-sat/micro-dev-proxy": "3.0.2",
|
|
25
|
+
"@tuya-sat/micro-utils": "3.0.2",
|
|
26
26
|
"babel-loader": "8.2.4",
|
|
27
27
|
"babel-plugin-import": "1.13.3",
|
|
28
28
|
"chalk": "4.1.2",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"webpack-merge": "5.8.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@types/express": "4.17.
|
|
63
|
+
"@types/express": "4.17.14",
|
|
64
64
|
"@types/jest": "27.4.1",
|
|
65
65
|
"@types/uuid": "8.3.4",
|
|
66
66
|
"jest": "27.5.1",
|