ms-vite-plugin 0.2.0 → 0.2.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 -6
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -74,7 +74,7 @@ async function findEntryFiles(src, baseDir) {
|
|
|
74
74
|
* 用于支持后续的 promise 调用
|
|
75
75
|
* @returns 返回 Vite 插件实例
|
|
76
76
|
*/
|
|
77
|
-
function
|
|
77
|
+
function devReturnMain() {
|
|
78
78
|
return {
|
|
79
79
|
name: "return-main",
|
|
80
80
|
generateBundle(_, bundle) {
|
|
@@ -87,6 +87,22 @@ function returnMain() {
|
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* 插件:将 main 函数调用替换为 return main();
|
|
92
|
+
* 用于生产环境,压缩后执行
|
|
93
|
+
* @returns 返回 Vite 插件实例
|
|
94
|
+
*/
|
|
95
|
+
function prodReturnMain() {
|
|
96
|
+
return {
|
|
97
|
+
name: "return-main",
|
|
98
|
+
renderChunk(code, chunk) {
|
|
99
|
+
if (chunk.isEntry) {
|
|
100
|
+
return code.replace(/\bmain\s*\(\s*\)\s*;/g, "return main();");
|
|
101
|
+
}
|
|
102
|
+
return code;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
90
106
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
91
107
|
const obfuscatorConfig = await fsExtra.readJSON(path.join(workspacePath, "obfuscator.json"));
|
|
92
108
|
const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
|
|
@@ -110,13 +126,10 @@ const buildAll = async (isDev = true, workspacePath) => {
|
|
|
110
126
|
sourcemap: isDev,
|
|
111
127
|
minify: !isDev, // 开发环境不压缩变量名
|
|
112
128
|
},
|
|
113
|
-
esbuild: {
|
|
114
|
-
keepNames: true,
|
|
115
|
-
},
|
|
116
129
|
plugins: isDev
|
|
117
|
-
? [
|
|
130
|
+
? [devReturnMain()]
|
|
118
131
|
: [
|
|
119
|
-
|
|
132
|
+
prodReturnMain(),
|
|
120
133
|
(0, vite_plugin_bundle_obfuscator_1.default)({
|
|
121
134
|
autoExcludeNodeModules: true,
|
|
122
135
|
threadPool: true,
|