ms-vite-plugin 0.2.1 → 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.
Files changed (2) hide show
  1. package/dist/build.js +21 -3
  2. package/package.json +1 -1
package/dist/build.js CHANGED
@@ -74,7 +74,25 @@ async function findEntryFiles(src, baseDir) {
74
74
  * 用于支持后续的 promise 调用
75
75
  * @returns 返回 Vite 插件实例
76
76
  */
77
- function returnMain() {
77
+ function devReturnMain() {
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
+ }
90
+ /**
91
+ * 插件:将 main 函数调用替换为 return main();
92
+ * 用于生产环境,压缩后执行
93
+ * @returns 返回 Vite 插件实例
94
+ */
95
+ function prodReturnMain() {
78
96
  return {
79
97
  name: "return-main",
80
98
  renderChunk(code, chunk) {
@@ -109,9 +127,9 @@ const buildAll = async (isDev = true, workspacePath) => {
109
127
  minify: !isDev, // 开发环境不压缩变量名
110
128
  },
111
129
  plugins: isDev
112
- ? [returnMain()]
130
+ ? [devReturnMain()]
113
131
  : [
114
- returnMain(),
132
+ prodReturnMain(),
115
133
  (0, vite_plugin_bundle_obfuscator_1.default)({
116
134
  autoExcludeNodeModules: true,
117
135
  threadPool: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {