ms-vite-plugin 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/build.js +20 -1
  2. package/package.json +1 -1
package/dist/build.js CHANGED
@@ -69,6 +69,24 @@ async function findEntryFiles(src, baseDir) {
69
69
  await walk(src);
70
70
  return result;
71
71
  }
72
+ /**
73
+ * 插件:将 main 函数调用替换为 return main();
74
+ * 用于支持后续的 promise 调用
75
+ * @returns 返回 Vite 插件实例
76
+ */
77
+ function returnMain() {
78
+ return {
79
+ name: "return-main",
80
+ generateBundle(_, bundle) {
81
+ for (const fileName in bundle) {
82
+ const chunk = bundle[fileName];
83
+ if (chunk.type === "chunk") {
84
+ chunk.code = chunk.code.replace(/\bmain\s*\(\s*\)\s*;/g, "return main();");
85
+ }
86
+ }
87
+ },
88
+ };
89
+ }
72
90
  const buildAll = async (isDev = true, workspacePath) => {
73
91
  const obfuscatorConfig = await fsExtra.readJSON(path.join(workspacePath, "obfuscator.json"));
74
92
  const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
@@ -93,13 +111,14 @@ const buildAll = async (isDev = true, workspacePath) => {
93
111
  minify: !isDev, // 开发环境不压缩变量名
94
112
  },
95
113
  plugins: isDev
96
- ? []
114
+ ? [returnMain()]
97
115
  : [
98
116
  (0, vite_plugin_bundle_obfuscator_1.default)({
99
117
  autoExcludeNodeModules: true,
100
118
  threadPool: true,
101
119
  options: obfuscatorConfig,
102
120
  }),
121
+ returnMain(),
103
122
  ],
104
123
  });
105
124
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {