ms-vite-plugin 0.2.5 → 0.2.7
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 +42 -31
- package/dist/cli.js +2 -5
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -108,39 +108,50 @@ function prodReturnMain() {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
111
|
+
const isJs = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.js"));
|
|
112
|
+
if (isJs) {
|
|
113
|
+
console.log("🚀 开始构建JavaScript项目...");
|
|
114
|
+
const obfuscatorConfigPath = path.join(workspacePath, "obfuscator.json");
|
|
115
|
+
if (!(await fsExtra.pathExists(obfuscatorConfigPath))) {
|
|
116
|
+
console.error("❌ 错误: 当前目录不是有效的 快点JS 项目");
|
|
117
|
+
console.error("请确保目录包含以下文件:");
|
|
118
|
+
console.error(" - obfuscator.json");
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
const obfuscatorConfig = await fsExtra.readJSON(obfuscatorConfigPath);
|
|
122
|
+
const outputDir = path.join(workspacePath, isDev ? "dist" : "msbundle");
|
|
123
|
+
const baseDir = path.join(workspacePath, "scripts");
|
|
124
|
+
const entryFiles = await findEntryFiles(baseDir, baseDir);
|
|
125
|
+
await fsExtra.remove(outputDir);
|
|
126
|
+
for (const entry of entryFiles) {
|
|
127
|
+
await (0, vite_1.build)({
|
|
128
|
+
root: workspacePath,
|
|
129
|
+
build: {
|
|
130
|
+
lib: {
|
|
131
|
+
entry: {
|
|
132
|
+
[path.basename(entry, path.extname(entry))]: `./scripts/${entry}`,
|
|
133
|
+
},
|
|
134
|
+
fileName: () => entry,
|
|
135
|
+
formats: ["iife"],
|
|
136
|
+
name: "KuaiJS", // IIFE 格式必需的全局变量名
|
|
123
137
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
138
|
+
outDir: isDev ? "dist/scripts" : "msbundle/scripts",
|
|
139
|
+
emptyOutDir: false, // 不要每次清空输出目录
|
|
140
|
+
sourcemap: isDev,
|
|
141
|
+
minify: !isDev, // 开发环境不压缩变量名
|
|
127
142
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
options: obfuscatorConfig,
|
|
141
|
-
}),
|
|
142
|
-
],
|
|
143
|
-
});
|
|
143
|
+
plugins: isDev
|
|
144
|
+
? [devReturnMain()]
|
|
145
|
+
: [
|
|
146
|
+
prodReturnMain(),
|
|
147
|
+
(0, vite_plugin_bundle_obfuscator_1.default)({
|
|
148
|
+
autoExcludeNodeModules: true,
|
|
149
|
+
threadPool: true,
|
|
150
|
+
options: obfuscatorConfig,
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
144
155
|
}
|
|
145
156
|
if (isDev) {
|
|
146
157
|
return;
|
package/dist/cli.js
CHANGED
|
@@ -47,13 +47,11 @@ async function isValidKuaiJSProject(workspacePath) {
|
|
|
47
47
|
try {
|
|
48
48
|
const packageJsonPath = path.join(workspacePath, "package.json");
|
|
49
49
|
const scriptsPath = path.join(workspacePath, "scripts");
|
|
50
|
-
const
|
|
51
|
-
const [packageExists, scriptsExists, obfuscatorExists] = await Promise.all([
|
|
50
|
+
const [packageExists, scriptsExists] = await Promise.all([
|
|
52
51
|
fsExtra.pathExists(packageJsonPath),
|
|
53
52
|
fsExtra.pathExists(scriptsPath),
|
|
54
|
-
fsExtra.pathExists(obfuscatorPath),
|
|
55
53
|
]);
|
|
56
|
-
return packageExists && scriptsExists
|
|
54
|
+
return packageExists && scriptsExists;
|
|
57
55
|
}
|
|
58
56
|
catch {
|
|
59
57
|
return false;
|
|
@@ -75,7 +73,6 @@ async function buildCommand(options) {
|
|
|
75
73
|
console.error("请确保目录包含以下文件:");
|
|
76
74
|
console.error(" - package.json");
|
|
77
75
|
console.error(" - scripts/ 目录");
|
|
78
|
-
console.error(" - obfuscator.json");
|
|
79
76
|
process.exit(1);
|
|
80
77
|
}
|
|
81
78
|
console.log(`🚀 开始构建项目 (${isDev ? "开发模式" : "生产模式"})...`);
|