ms-vite-plugin 0.1.0 → 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.
Files changed (2) hide show
  1. package/dist/build.js +21 -3
  2. package/package.json +1 -1
package/dist/build.js CHANGED
@@ -69,9 +69,26 @@ 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
- const outputDir = path.join(workspacePath, "msbundle");
91
+ const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
75
92
  const baseDir = path.join(workspacePath, "scripts");
76
93
  const entryFiles = await findEntryFiles(baseDir, baseDir);
77
94
  await fsExtra.remove(outputDir);
@@ -88,13 +105,14 @@ const buildAll = async (isDev = true, workspacePath) => {
88
105
  name: "KuaiJS", // IIFE 格式必需的全局变量名
89
106
  },
90
107
  outDir: isDev ? "dist/scripts" : "msbundle/scripts",
91
- emptyOutDir: isDev, // 不要每次清空输出目录
108
+ emptyOutDir: false, // 不要每次清空输出目录
92
109
  sourcemap: isDev,
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {