ms-vite-plugin 0.1.1 → 0.1.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.
- package/dist/build.js +19 -1
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -69,6 +69,23 @@ async function findEntryFiles(src, baseDir) {
|
|
|
69
69
|
await walk(src);
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 插件:将 main 函数调用替换为 return main();
|
|
74
|
+
* @returns 返回 Vite 插件实例
|
|
75
|
+
*/
|
|
76
|
+
function returnMain() {
|
|
77
|
+
return {
|
|
78
|
+
name: "return-main",
|
|
79
|
+
generateBundle(_, bundle) {
|
|
80
|
+
for (const fileName in bundle) {
|
|
81
|
+
const chunk = bundle[fileName];
|
|
82
|
+
if (chunk.type === "chunk") {
|
|
83
|
+
chunk.code = chunk.code.replace(/\bmain\s*\(\s*\)\s*;/g, "return main();");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
72
89
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
73
90
|
const obfuscatorConfig = await fsExtra.readJSON(path.join(workspacePath, "obfuscator.json"));
|
|
74
91
|
const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
|
|
@@ -93,8 +110,9 @@ const buildAll = async (isDev = true, workspacePath) => {
|
|
|
93
110
|
minify: !isDev, // 开发环境不压缩变量名
|
|
94
111
|
},
|
|
95
112
|
plugins: isDev
|
|
96
|
-
? []
|
|
113
|
+
? [returnMain()]
|
|
97
114
|
: [
|
|
115
|
+
returnMain(),
|
|
98
116
|
(0, vite_plugin_bundle_obfuscator_1.default)({
|
|
99
117
|
autoExcludeNodeModules: true,
|
|
100
118
|
threadPool: true,
|