ms-vite-plugin 0.2.5 → 0.2.6
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/build.js +35 -31
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -108,39 +108,43 @@ function prodReturnMain() {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
await (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
111
|
+
const isJs = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.js"));
|
|
112
|
+
if (isJs) {
|
|
113
|
+
console.log("🚀 开始构建JavaScript项目...");
|
|
114
|
+
const obfuscatorConfig = await fsExtra.readJSON(path.join(workspacePath, "obfuscator.json"));
|
|
115
|
+
const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
|
|
116
|
+
const baseDir = path.join(workspacePath, "scripts");
|
|
117
|
+
const entryFiles = await findEntryFiles(baseDir, baseDir);
|
|
118
|
+
await fsExtra.remove(outputDir);
|
|
119
|
+
for (const entry of entryFiles) {
|
|
120
|
+
await (0, vite_1.build)({
|
|
121
|
+
root: workspacePath,
|
|
122
|
+
build: {
|
|
123
|
+
lib: {
|
|
124
|
+
entry: {
|
|
125
|
+
[path.basename(entry, path.extname(entry))]: `./scripts/${entry}`,
|
|
126
|
+
},
|
|
127
|
+
fileName: () => entry,
|
|
128
|
+
formats: ["iife"],
|
|
129
|
+
name: "KuaiJS", // IIFE 格式必需的全局变量名
|
|
123
130
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
outDir: isDev ? "dist/scripts" : "msbundle/scripts",
|
|
132
|
+
emptyOutDir: false, // 不要每次清空输出目录
|
|
133
|
+
sourcemap: isDev,
|
|
134
|
+
minify: !isDev, // 开发环境不压缩变量名
|
|
127
135
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
options: obfuscatorConfig,
|
|
141
|
-
}),
|
|
142
|
-
],
|
|
143
|
-
});
|
|
136
|
+
plugins: isDev
|
|
137
|
+
? [devReturnMain()]
|
|
138
|
+
: [
|
|
139
|
+
prodReturnMain(),
|
|
140
|
+
(0, vite_plugin_bundle_obfuscator_1.default)({
|
|
141
|
+
autoExcludeNodeModules: true,
|
|
142
|
+
threadPool: true,
|
|
143
|
+
options: obfuscatorConfig,
|
|
144
|
+
}),
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
144
148
|
}
|
|
145
149
|
if (isDev) {
|
|
146
150
|
return;
|