@empjs/cli 3.0.0-rc.0 → 3.0.0-rc.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/index.js +16 -2476
- package/dist/store/rspack/hook.d.ts +4 -2
- package/dist/types/config.d.ts +1 -0
- package/package.json +8 -10
- package/dist/index.js.map +0 -7
package/dist/index.js
CHANGED
|
@@ -1,2476 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { readFile } from "node:fs/promises";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var __filename, __dirname, getFileJson, require2, importResolve, empRoot;
|
|
18
|
-
var init_nodePolyfill = __esm({
|
|
19
|
-
"src/helper/nodePolyfill.ts"() {
|
|
20
|
-
"use strict";
|
|
21
|
-
__filename = fileURLToPath(import.meta.url);
|
|
22
|
-
__dirname = dirname(__filename);
|
|
23
|
-
getFileJson = async (url2) => {
|
|
24
|
-
try {
|
|
25
|
-
const str = await readFile(url2);
|
|
26
|
-
const json = JSON.parse(str);
|
|
27
|
-
return json;
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error(e);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
require2 = Module.createRequire(import.meta.url);
|
|
33
|
-
importResolve = (scope, importMetaUrl) => {
|
|
34
|
-
let rq = require2;
|
|
35
|
-
if (importMetaUrl) {
|
|
36
|
-
rq = Module.createRequire(importMetaUrl);
|
|
37
|
-
}
|
|
38
|
-
return rq.resolve(scope);
|
|
39
|
-
};
|
|
40
|
-
empRoot = path.resolve(__dirname, __filename).replace(`${path.sep}dist${path.sep}index.js`, "");
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// src/store/rspack/plugin.ts
|
|
45
|
-
import rspack from "@rspack/core";
|
|
46
|
-
import fs from "fs";
|
|
47
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
48
|
-
var RspackPlugin, plugin_default;
|
|
49
|
-
var init_plugin = __esm({
|
|
50
|
-
"src/store/rspack/plugin.ts"() {
|
|
51
|
-
"use strict";
|
|
52
|
-
RspackPlugin = class {
|
|
53
|
-
store;
|
|
54
|
-
async setup(store) {
|
|
55
|
-
this.store = store;
|
|
56
|
-
const runFuns = [
|
|
57
|
-
this.define(),
|
|
58
|
-
this.anylayze(),
|
|
59
|
-
this.progress(),
|
|
60
|
-
this.copy(),
|
|
61
|
-
this.empShare(),
|
|
62
|
-
// this.html()
|
|
63
|
-
///////////////////////
|
|
64
|
-
// this.minJs(),
|
|
65
|
-
// this.minCss(),
|
|
66
|
-
this.minify()
|
|
67
|
-
];
|
|
68
|
-
await this.store.empConfig.lifeCycle.beforePlugin();
|
|
69
|
-
await Promise.all(runFuns);
|
|
70
|
-
await this.store.empConfig.lifeCycle.afterPlugin();
|
|
71
|
-
}
|
|
72
|
-
async anylayze() {
|
|
73
|
-
if (!this.store.cliOptions.analyze)
|
|
74
|
-
return;
|
|
75
|
-
const {
|
|
76
|
-
default: { BundleAnalyzerPlugin }
|
|
77
|
-
} = await import("webpack-bundle-analyzer");
|
|
78
|
-
this.store.chain.plugin("bundleAnalyzerPlugin").use(BundleAnalyzerPlugin, [{}]);
|
|
79
|
-
}
|
|
80
|
-
// async html() {
|
|
81
|
-
// const htmlPlugin: any = await import('@rspack/plugin-html')
|
|
82
|
-
// //TODO 修正 两个 default
|
|
83
|
-
// const HtmlRspackPlugin = htmlPlugin.default.default
|
|
84
|
-
// const op = this.store.empConfig.html
|
|
85
|
-
// this.store.chain.plugin('htmlPlugin').use(HtmlRspackPlugin, [op])
|
|
86
|
-
// }
|
|
87
|
-
async define() {
|
|
88
|
-
this.store.chain.plugin("definePlugin").use(rspack.DefinePlugin, [this.store.empConfig.define]);
|
|
89
|
-
}
|
|
90
|
-
async copy() {
|
|
91
|
-
const publicFrom = this.store.resolve("public");
|
|
92
|
-
if (fs.existsSync(publicFrom) && fs.readdirSync(publicFrom).length > 0)
|
|
93
|
-
this.store.chain.plugin("copyRspackPlugin").use(rspack.CopyRspackPlugin, [
|
|
94
|
-
{
|
|
95
|
-
patterns: [
|
|
96
|
-
{
|
|
97
|
-
from: publicFrom,
|
|
98
|
-
to: this.store.resolve("dist")
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
]);
|
|
103
|
-
}
|
|
104
|
-
async progress() {
|
|
105
|
-
if (!this.store.empConfig.debug.progress)
|
|
106
|
-
return;
|
|
107
|
-
this.store.chain.plugin("progressPlugin").use(rspack.ProgressPlugin, [
|
|
108
|
-
{
|
|
109
|
-
prefix: "EMP"
|
|
110
|
-
}
|
|
111
|
-
]);
|
|
112
|
-
}
|
|
113
|
-
async empShare() {
|
|
114
|
-
const { isEmpshare } = this.store.empConfig.empShareLib;
|
|
115
|
-
if (!isEmpshare)
|
|
116
|
-
return;
|
|
117
|
-
const mfp = ModuleFederationPlugin;
|
|
118
|
-
this.store.chain.plugin("empShare").use(mfp, [this.store.empConfig.empShareLib.pluginConfig]);
|
|
119
|
-
}
|
|
120
|
-
// production plugin
|
|
121
|
-
minify() {
|
|
122
|
-
this.store.chain.optimization.minimize(this.store.mode === "production");
|
|
123
|
-
this.store.chain.optimization.minimizer("minJs").use(rspack.SwcJsMinimizerRspackPlugin, [this.store.empConfig.build.minOptions]);
|
|
124
|
-
this.store.chain.optimization.minimizer("minCss").use(rspack.SwcCssMinimizerRspackPlugin, [{}]);
|
|
125
|
-
}
|
|
126
|
-
/* minJs() {
|
|
127
|
-
if (this.store.mode !== 'production') return
|
|
128
|
-
this.store.chain.plugin('minJs').use(rspack.SwcJsMinimizerRspackPlugin, [this.store.empConfig.build.minOptions])
|
|
129
|
-
}
|
|
130
|
-
minCss() {
|
|
131
|
-
if (this.store.mode !== 'production') return
|
|
132
|
-
this.store.chain.plugin('minCss').use(rspack.SwcCssMinimizerRspackPlugin, [{}])
|
|
133
|
-
} */
|
|
134
|
-
};
|
|
135
|
-
plugin_default = new RspackPlugin();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// src/helper/utils.ts
|
|
140
|
-
import chalk from "chalk";
|
|
141
|
-
import fs2 from "fs-extra";
|
|
142
|
-
import { ip } from "address";
|
|
143
|
-
import { gateway4sync } from "default-gateway";
|
|
144
|
-
function clearConsole() {
|
|
145
|
-
process.stdout.write(process.platform === "win32" ? "\x1B[2J\x1B[0f" : "\x1B[2J\x1B[3J\x1B[H");
|
|
146
|
-
}
|
|
147
|
-
function deepAssign(target, ...sources) {
|
|
148
|
-
for (const source of sources) {
|
|
149
|
-
for (const k in source) {
|
|
150
|
-
const vs = source[k], vt = target[k];
|
|
151
|
-
if (Object(vs) == vs && Object(vt) === vt) {
|
|
152
|
-
target[k] = deepAssign(vt, vs);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
target[k] = source[k];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return target;
|
|
159
|
-
}
|
|
160
|
-
var getLanIp, getPkgVersion, vCompare, timeFormat, importJsVm;
|
|
161
|
-
var init_utils = __esm({
|
|
162
|
-
"src/helper/utils.ts"() {
|
|
163
|
-
"use strict";
|
|
164
|
-
getLanIp = () => {
|
|
165
|
-
const { int } = gateway4sync();
|
|
166
|
-
return ip(int || "") || "127.0.0.1";
|
|
167
|
-
};
|
|
168
|
-
getPkgVersion = (pkgPath) => {
|
|
169
|
-
try {
|
|
170
|
-
const { version } = fs2.readJSONSync(pkgPath);
|
|
171
|
-
return version;
|
|
172
|
-
} catch (err) {
|
|
173
|
-
return void 0;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
vCompare = (preVersion = "", lastVersion = "") => {
|
|
177
|
-
const sources = preVersion.replace("^", "").split(".");
|
|
178
|
-
const dests = lastVersion.replace("^", "").split(".");
|
|
179
|
-
const maxL = Math.max(sources.length, dests.length);
|
|
180
|
-
let result = 0;
|
|
181
|
-
for (let i = 0; i < maxL; i++) {
|
|
182
|
-
const preValue = sources.length > i ? sources[i] : 0;
|
|
183
|
-
const preNum = isNaN(Number(preValue)) ? preValue.charCodeAt() : Number(preValue);
|
|
184
|
-
const lastValue = dests.length > i ? dests[i] : 0;
|
|
185
|
-
const lastNum = isNaN(Number(lastValue)) ? lastValue.charCodeAt() : Number(lastValue);
|
|
186
|
-
if (preNum < lastNum) {
|
|
187
|
-
result = -1;
|
|
188
|
-
break;
|
|
189
|
-
} else if (preNum > lastNum) {
|
|
190
|
-
result = 1;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
};
|
|
196
|
-
timeFormat = (seconds) => {
|
|
197
|
-
seconds = seconds / 1e3;
|
|
198
|
-
const format = (time) => chalk.bold(time);
|
|
199
|
-
if (seconds < 1) {
|
|
200
|
-
return `${seconds * 1e3} ms`;
|
|
201
|
-
}
|
|
202
|
-
if (seconds < 10) {
|
|
203
|
-
const digits = seconds >= 0.01 ? 2 : 3;
|
|
204
|
-
return `${format(seconds.toFixed(digits))} s`;
|
|
205
|
-
}
|
|
206
|
-
if (seconds < 60) {
|
|
207
|
-
return `${format(seconds.toFixed(1))} s`;
|
|
208
|
-
}
|
|
209
|
-
const minutes = seconds / 60;
|
|
210
|
-
return `${format(minutes.toFixed(2))} m`;
|
|
211
|
-
};
|
|
212
|
-
importJsVm = (content) => `data:text/javascript,${content}`;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// src/store/rspack/module.ts
|
|
217
|
-
import path2 from "node:path";
|
|
218
|
-
var RspackModule, module_default;
|
|
219
|
-
var init_module = __esm({
|
|
220
|
-
"src/store/rspack/module.ts"() {
|
|
221
|
-
"use strict";
|
|
222
|
-
init_nodePolyfill();
|
|
223
|
-
init_utils();
|
|
224
|
-
RspackModule = class {
|
|
225
|
-
store;
|
|
226
|
-
swcJsOptions = {};
|
|
227
|
-
swcTsOptions = {};
|
|
228
|
-
coreJs = {
|
|
229
|
-
version: "3",
|
|
230
|
-
alias: "",
|
|
231
|
-
path: ""
|
|
232
|
-
};
|
|
233
|
-
async setup(store) {
|
|
234
|
-
this.store = store;
|
|
235
|
-
const runFuns = [this.files(), this.scripts(), this.rspackGenerator(), this.rspackParser()];
|
|
236
|
-
await Promise.all(runFuns);
|
|
237
|
-
}
|
|
238
|
-
rspackGenerator() {
|
|
239
|
-
const localIdentName = this.store.isDev ? "[path][name]-[local]-[hash:5]" : "[local]-[hash:5]";
|
|
240
|
-
this.store.chain.merge({
|
|
241
|
-
module: {
|
|
242
|
-
generator: {
|
|
243
|
-
css: { localIdentName },
|
|
244
|
-
"css/auto": { localIdentName },
|
|
245
|
-
"css/module": { localIdentName }
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
rspackParser() {
|
|
251
|
-
const namedExports = false;
|
|
252
|
-
this.store.chain.merge({
|
|
253
|
-
module: {
|
|
254
|
-
parser: {
|
|
255
|
-
css: { namedExports },
|
|
256
|
-
"css/auto": { namedExports },
|
|
257
|
-
"css/module": { namedExports }
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
get isPolyfill() {
|
|
263
|
-
return this.store.empConfig.build.polyfill;
|
|
264
|
-
}
|
|
265
|
-
swcParser(lang) {
|
|
266
|
-
switch (lang) {
|
|
267
|
-
case "js":
|
|
268
|
-
return {
|
|
269
|
-
syntax: "ecmascript",
|
|
270
|
-
jsx: true,
|
|
271
|
-
decorators: true,
|
|
272
|
-
decoratorsBeforeExport: false
|
|
273
|
-
};
|
|
274
|
-
case "ts":
|
|
275
|
-
return {
|
|
276
|
-
syntax: "typescript",
|
|
277
|
-
decorators: true,
|
|
278
|
-
tsx: true,
|
|
279
|
-
dynamicImport: true
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
swcJsc(lang) {
|
|
284
|
-
const { target, externalHelpers } = this.store.empConfig.build;
|
|
285
|
-
return {
|
|
286
|
-
parser: this.swcParser(lang),
|
|
287
|
-
transform: {},
|
|
288
|
-
target,
|
|
289
|
-
externalHelpers,
|
|
290
|
-
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
|
|
291
|
-
// keepClassNames: true,
|
|
292
|
-
// https://github.com/swc-project/swc/issues/6403 Avoid the webpack magic comment to be removed
|
|
293
|
-
preserveAllComments: true
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
get swcCoreVersion() {
|
|
297
|
-
const [major, minor] = this.coreJs.version.split(".");
|
|
298
|
-
return `${major}.${minor}`;
|
|
299
|
-
}
|
|
300
|
-
swcOptions(lang) {
|
|
301
|
-
const op = {
|
|
302
|
-
jsc: this.swcJsc(lang),
|
|
303
|
-
/**
|
|
304
|
-
* externalHelpers *
|
|
305
|
-
* mode usage *
|
|
306
|
-
*/
|
|
307
|
-
// Source Type
|
|
308
|
-
isModule: "unknown"
|
|
309
|
-
};
|
|
310
|
-
if (this.isPolyfill) {
|
|
311
|
-
delete op.jsc.target;
|
|
312
|
-
op.env = {
|
|
313
|
-
coreJs: this.swcCoreVersion,
|
|
314
|
-
// modules: false,
|
|
315
|
-
// loose: true,
|
|
316
|
-
// debug: true,
|
|
317
|
-
targets: this.store.empConfig.build.browserslist
|
|
318
|
-
};
|
|
319
|
-
if (!this.store.empConfig.isESM) {
|
|
320
|
-
op.env.mode = this.store.empConfig.build.polyfill;
|
|
321
|
-
}
|
|
322
|
-
if (this.store.empConfig.build.polyfill === "usage") {
|
|
323
|
-
op.env.shippedProposals = true;
|
|
324
|
-
op.env.include = ["es.object.values", "es.array.flat"];
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return op;
|
|
328
|
-
}
|
|
329
|
-
swcInitOptions() {
|
|
330
|
-
const { externalHelpers } = this.store.empConfig.build;
|
|
331
|
-
if (externalHelpers) {
|
|
332
|
-
this.store.chain.resolve.alias.set("@swc/helpers", path2.dirname(require2.resolve("@swc/helpers/package.json")));
|
|
333
|
-
}
|
|
334
|
-
this.coreJs.path = require2.resolve("core-js/package.json");
|
|
335
|
-
const version = getPkgVersion(this.coreJs.path);
|
|
336
|
-
if (version)
|
|
337
|
-
this.coreJs.version = version;
|
|
338
|
-
this.coreJs.alias = path2.dirname(this.coreJs.path);
|
|
339
|
-
if (this.store.empConfig.build.polyfill) {
|
|
340
|
-
this.store.chain.resolve.alias.set("core-js", this.coreJs.alias);
|
|
341
|
-
this.store.chain.module.rule("javascript").exclude.add(/core-js/);
|
|
342
|
-
this.store.chain.module.rule("typescript").exclude.add(/core-js/);
|
|
343
|
-
}
|
|
344
|
-
this.swcTsOptions = this.swcOptions("ts");
|
|
345
|
-
this.swcJsOptions = this.swcOptions("js");
|
|
346
|
-
}
|
|
347
|
-
async scripts() {
|
|
348
|
-
this.swcInitOptions();
|
|
349
|
-
const sideEffects = false;
|
|
350
|
-
const exclude = [];
|
|
351
|
-
this.store.chain.merge({
|
|
352
|
-
module: {
|
|
353
|
-
parser: {
|
|
354
|
-
javascript: {
|
|
355
|
-
exportsPresence: "error",
|
|
356
|
-
importExportsPresence: "error"
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
rule: {
|
|
360
|
-
mjs: {
|
|
361
|
-
test: /\.m?js/,
|
|
362
|
-
resolve: {
|
|
363
|
-
fullySpecified: false
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
typescript: {
|
|
367
|
-
test: /\.(ts|tsx)$/,
|
|
368
|
-
exclude,
|
|
369
|
-
sideEffects,
|
|
370
|
-
// 标记模块是否存在副作用。
|
|
371
|
-
use: {
|
|
372
|
-
swc: {
|
|
373
|
-
loader: "builtin:swc-loader",
|
|
374
|
-
options: this.swcTsOptions
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
javascript: {
|
|
379
|
-
test: /\.(js|jsx)$/,
|
|
380
|
-
exclude,
|
|
381
|
-
sideEffects,
|
|
382
|
-
// 标记模块是否存在副作用。
|
|
383
|
-
use: {
|
|
384
|
-
swc: {
|
|
385
|
-
loader: "builtin:swc-loader",
|
|
386
|
-
options: this.swcJsOptions
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
async files() {
|
|
395
|
-
this.store.chain.merge({
|
|
396
|
-
module: {
|
|
397
|
-
rule: {
|
|
398
|
-
svg: {
|
|
399
|
-
test: /\.svg$/,
|
|
400
|
-
type: "asset/resource"
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
this.store.chain.merge({
|
|
406
|
-
module: {
|
|
407
|
-
rule: {
|
|
408
|
-
inline: {
|
|
409
|
-
resourceQuery: /inline/,
|
|
410
|
-
type: "asset/inline"
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
this.store.chain.merge({
|
|
416
|
-
module: {
|
|
417
|
-
rule: {
|
|
418
|
-
image: {
|
|
419
|
-
test: /\.(png|jpe?g|gif|webp|ico)$/i,
|
|
420
|
-
type: "asset/resource"
|
|
421
|
-
},
|
|
422
|
-
fonts: {
|
|
423
|
-
test: /\.(|otf|ttf|eot|woff|woff2)$/i,
|
|
424
|
-
type: "asset/resource"
|
|
425
|
-
},
|
|
426
|
-
svga: {
|
|
427
|
-
test: /\.(svga)$/i,
|
|
428
|
-
type: "asset/resource"
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
module_default = new RspackModule();
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
// src/store/rspack/common.ts
|
|
440
|
-
var RspackCommon, common_default;
|
|
441
|
-
var init_common = __esm({
|
|
442
|
-
"src/store/rspack/common.ts"() {
|
|
443
|
-
"use strict";
|
|
444
|
-
RspackCommon = class {
|
|
445
|
-
store;
|
|
446
|
-
async setup(store) {
|
|
447
|
-
this.store = store;
|
|
448
|
-
const runFuns = [
|
|
449
|
-
this.common(),
|
|
450
|
-
this.stats(),
|
|
451
|
-
this.devServer(),
|
|
452
|
-
// this.assets(),
|
|
453
|
-
this.optimization()
|
|
454
|
-
];
|
|
455
|
-
await Promise.all(runFuns);
|
|
456
|
-
}
|
|
457
|
-
async common() {
|
|
458
|
-
this.store.merge({
|
|
459
|
-
node: {
|
|
460
|
-
global: true
|
|
461
|
-
},
|
|
462
|
-
experiments: {
|
|
463
|
-
rspackFuture: {
|
|
464
|
-
// disableTransformByDefault: false, // 开启默认转换
|
|
465
|
-
// 移除 experiments.rspackFuture.disableApplyEntryLazily
|
|
466
|
-
// disableApplyEntryLazily: true,
|
|
467
|
-
// rspack 0.6 默认开启新版 tree shaking
|
|
468
|
-
// newTreeshaking: this.store.empConfig.isESM, // 该功能启用了与 webpack 相同的新摇树优化实现,可以生成更高效和更小的代码。
|
|
469
|
-
},
|
|
470
|
-
outputModule: this.store.empConfig.isESM,
|
|
471
|
-
//将尽可能输出符合 ECMAScript 语法的代码
|
|
472
|
-
topLevelAwait: true
|
|
473
|
-
},
|
|
474
|
-
target: this.store.empConfig.target,
|
|
475
|
-
// default [web,es5]
|
|
476
|
-
infrastructureLogging: this.store.empConfig.debug.infrastructureLogging,
|
|
477
|
-
context: this.store.root,
|
|
478
|
-
mode: this.store.mode,
|
|
479
|
-
cache: this.store.empConfig.debug.rspackCache,
|
|
480
|
-
devtool: this.store.empConfig.build.sourcemap ? "source-map" : false,
|
|
481
|
-
//Recommended
|
|
482
|
-
builtins: {
|
|
483
|
-
/**
|
|
484
|
-
'builtins.devFriendlySplitChunks = true' has been deprecated, please switch to 'builtins.devFriendlySplitChunks = false' to use webpack's behavior.
|
|
485
|
-
Set env `RSPACK_DEP_WARNINGS` to 'false' to temporarily disable deprecation warnings.
|
|
486
|
-
*/
|
|
487
|
-
// devFriendlySplitChunks: true,
|
|
488
|
-
// css: {
|
|
489
|
-
// modules: {
|
|
490
|
-
// // exportsOnly: false,
|
|
491
|
-
// localIdentName: this.store.isDev ? '[path][name]-[local]-[hash:5]' : '[local]-[hash:5]',
|
|
492
|
-
// },
|
|
493
|
-
// },
|
|
494
|
-
},
|
|
495
|
-
output: this.store.empConfig.output,
|
|
496
|
-
resolve: this.store.empConfig.resolve,
|
|
497
|
-
externals: this.store.empConfig.externals
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
async stats() {
|
|
501
|
-
this.store.merge({
|
|
502
|
-
stats: {
|
|
503
|
-
colors: true,
|
|
504
|
-
all: false,
|
|
505
|
-
assets: false,
|
|
506
|
-
chunks: false,
|
|
507
|
-
timings: true,
|
|
508
|
-
version: true
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
async devServer() {
|
|
513
|
-
this.store.merge({
|
|
514
|
-
devServer: this.store.empConfig.server
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
/* async assets() {
|
|
518
|
-
this.store.chain.merge({
|
|
519
|
-
module: {
|
|
520
|
-
rule: {
|
|
521
|
-
assets: {
|
|
522
|
-
test: /\.(png|jpe?g|gif|webp|ico|otf|ttf|eot|woff|woff2|svga)$/i,
|
|
523
|
-
type: 'asset/resource',
|
|
524
|
-
},
|
|
525
|
-
},
|
|
526
|
-
},
|
|
527
|
-
})
|
|
528
|
-
} */
|
|
529
|
-
async optimization() {
|
|
530
|
-
const optimization = {
|
|
531
|
-
// moduleIds: 'named',
|
|
532
|
-
// chunkIds: 'named',
|
|
533
|
-
moduleIds: this.store.empConfig.build.moduleIds,
|
|
534
|
-
chunkIds: this.store.empConfig.build.chunkIds,
|
|
535
|
-
minimize: this.store.empConfig.build.minify,
|
|
536
|
-
splitChunks: {
|
|
537
|
-
chunks: "async",
|
|
538
|
-
// chunks: 'all',
|
|
539
|
-
cacheGroups: {
|
|
540
|
-
// defaultVendors: {
|
|
541
|
-
// filename: 'vendors-[name].js',
|
|
542
|
-
// },
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
if (this.store.empConfig.build.polyfill) {
|
|
547
|
-
optimization.splitChunks.cacheGroups = {
|
|
548
|
-
// empShare: {
|
|
549
|
-
// test: /[\\/]node_modules[\\/](@module-federation)[\\/]/,
|
|
550
|
-
// name: 'empShare',
|
|
551
|
-
// chunks: 'all',
|
|
552
|
-
// },
|
|
553
|
-
// coreJs: {
|
|
554
|
-
// test: /[\\/]node_modules[\\/](core-js)[\\/]/,
|
|
555
|
-
// name: 'coreJs',
|
|
556
|
-
// chunks: 'all',
|
|
557
|
-
// enforce: true,
|
|
558
|
-
// },
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
this.store.chain.merge({
|
|
562
|
-
optimization
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
common_default = new RspackCommon();
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// src/store/rspack/hook.ts
|
|
571
|
-
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
572
|
-
var HtmlImportMapPluginName, HtmlImportMapPlugin, HtmlEmpShareLibPluginName, HtmlEmpShareLibPlugin, getPolyfillEntry, EmpPolyfillPlugin;
|
|
573
|
-
var init_hook = __esm({
|
|
574
|
-
"src/store/rspack/hook.ts"() {
|
|
575
|
-
"use strict";
|
|
576
|
-
init_utils();
|
|
577
|
-
init_store();
|
|
578
|
-
HtmlImportMapPluginName = "HtmlImportMapPlugin";
|
|
579
|
-
HtmlImportMapPlugin = class {
|
|
580
|
-
importMap;
|
|
581
|
-
constructor(importMap) {
|
|
582
|
-
this.importMap = importMap;
|
|
583
|
-
}
|
|
584
|
-
apply(compiler) {
|
|
585
|
-
compiler.hooks.compilation.tap(HtmlImportMapPluginName, (compilation) => {
|
|
586
|
-
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync(HtmlImportMapPluginName, (data, cb) => {
|
|
587
|
-
data.headTags.push({
|
|
588
|
-
tagName: "script",
|
|
589
|
-
attributes: { type: "importmap" },
|
|
590
|
-
innerHTML: `${JSON.stringify(this.importMap, null, 2)}`,
|
|
591
|
-
voidTag: false,
|
|
592
|
-
meta: {
|
|
593
|
-
plugin: void 0
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
cb(null, data);
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
HtmlEmpShareLibPluginName = "HtmlEmpShareLibPlugin";
|
|
602
|
-
HtmlEmpShareLibPlugin = class {
|
|
603
|
-
files;
|
|
604
|
-
constructor(files) {
|
|
605
|
-
this.files = deepAssign({ js: [], css: [] }, files);
|
|
606
|
-
}
|
|
607
|
-
apply(compiler) {
|
|
608
|
-
compiler.hooks.compilation.tap(HtmlEmpShareLibPluginName, (compilation) => {
|
|
609
|
-
const files = this.files;
|
|
610
|
-
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync(HtmlEmpShareLibPluginName, (data, cb) => {
|
|
611
|
-
files.js.map((js) => {
|
|
612
|
-
data.headTags.push({
|
|
613
|
-
tagName: "script",
|
|
614
|
-
attributes: { src: js },
|
|
615
|
-
voidTag: false,
|
|
616
|
-
meta: {
|
|
617
|
-
plugin: void 0
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
files.css.map((css) => {
|
|
622
|
-
data.headTags.push({
|
|
623
|
-
tagName: "link",
|
|
624
|
-
attributes: { rel: "stylesheet", href: css },
|
|
625
|
-
voidTag: false,
|
|
626
|
-
meta: {
|
|
627
|
-
plugin: void 0
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
});
|
|
631
|
-
cb(null, data);
|
|
632
|
-
});
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
getPolyfillEntry = () => {
|
|
637
|
-
const content = [`import 'core-js/${store_default.empConfig.build.coreJsFeatures}'`].join("\n");
|
|
638
|
-
return importJsVm(content);
|
|
639
|
-
};
|
|
640
|
-
EmpPolyfillPlugin = class {
|
|
641
|
-
constructor() {
|
|
642
|
-
}
|
|
643
|
-
apply(compiler) {
|
|
644
|
-
const { webpack } = compiler;
|
|
645
|
-
new webpack.EntryPlugin(compiler.context, getPolyfillEntry(), {
|
|
646
|
-
name: void 0
|
|
647
|
-
}).apply(compiler);
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
// src/store/rspack/entries.ts
|
|
654
|
-
import HtmlWebpackPlugin2 from "html-webpack-plugin";
|
|
655
|
-
import glob from "fast-glob";
|
|
656
|
-
import path3 from "node:path";
|
|
657
|
-
var RspackEntries, entries_default;
|
|
658
|
-
var init_entries = __esm({
|
|
659
|
-
"src/store/rspack/entries.ts"() {
|
|
660
|
-
"use strict";
|
|
661
|
-
init_utils();
|
|
662
|
-
init_hook();
|
|
663
|
-
RspackEntries = class {
|
|
664
|
-
store;
|
|
665
|
-
entriesConfig = {};
|
|
666
|
-
async setup(store) {
|
|
667
|
-
this.store = store;
|
|
668
|
-
await this.init();
|
|
669
|
-
this.toConfig();
|
|
670
|
-
}
|
|
671
|
-
setHtmlConfig(c, chunks) {
|
|
672
|
-
c.template = this.setTemplate(c.template);
|
|
673
|
-
c.favicon = this.setFavicion(c.favicon);
|
|
674
|
-
c.chunks = chunks;
|
|
675
|
-
c.filename = `${chunks[0]}.html`;
|
|
676
|
-
if (this.store.empConfig.base)
|
|
677
|
-
c.publicPath = this.store.empConfig.base;
|
|
678
|
-
c.tags = c.tags || {};
|
|
679
|
-
return c;
|
|
680
|
-
}
|
|
681
|
-
setChunk(filename) {
|
|
682
|
-
return filename.replace(path3.extname(filename), "").replace(`${this.store.empConfig.appSrc}${path3.sep}`, "");
|
|
683
|
-
}
|
|
684
|
-
setTemplate(template) {
|
|
685
|
-
return template ? this.store.resolve(template) : this.store.empResolve(path3.join("template", "index.html"));
|
|
686
|
-
}
|
|
687
|
-
setFavicion(favicon) {
|
|
688
|
-
return favicon ? this.store.resolve(favicon) : this.store.empResolve(path3.join("template", "favicon.ico"));
|
|
689
|
-
}
|
|
690
|
-
setEntryItem(filename, op, absPath) {
|
|
691
|
-
absPath = absPath ? absPath : this.store.resolve(path3.join(this.store.empConfig.appSrc, filename));
|
|
692
|
-
const chunkName = this.setChunk(filename);
|
|
693
|
-
const chunks = [absPath];
|
|
694
|
-
this.entriesConfig[chunkName] = {
|
|
695
|
-
entry: { [chunkName]: chunks },
|
|
696
|
-
html: this.setHtmlConfig(op, [chunkName])
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
setRspackHtmlPlugin(config, chunk) {
|
|
700
|
-
this.store.chain.plugin(`html-plugin-${chunk}`).use(HtmlWebpackPlugin2, [config]);
|
|
701
|
-
if (this.store.empConfig.empShareLib)
|
|
702
|
-
config.files = deepAssign(config.files, this.store.empConfig.empShareLib.externalAssets);
|
|
703
|
-
this.store.chain.plugin(`html-plugin-empShare-${chunk}`).use(HtmlEmpShareLibPlugin, [config.files]);
|
|
704
|
-
if (this.store.empConfig.empShareLib.useImportMap) {
|
|
705
|
-
this.store.chain.plugin(`html-plugin-import-map-${chunk}`).use(HtmlImportMapPlugin, [this.store.empConfig.empShareLib.importMap]);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
setRspackEntry(entry) {
|
|
709
|
-
this.store.merge({ entry });
|
|
710
|
-
}
|
|
711
|
-
async init() {
|
|
712
|
-
const appEntry = path3.join(this.store.appSrc, this.store.empConfig.appEntry ? this.store.empConfig.appEntry : `index.{ts,tsx,jsx,js}`).replace(/\\/g, "/");
|
|
713
|
-
const elist = await glob([appEntry]);
|
|
714
|
-
if (elist[0]) {
|
|
715
|
-
const filename = path3.join(
|
|
716
|
-
this.store.empConfig.appSrc,
|
|
717
|
-
Object.keys(this.store.empConfig.entries).length > 0 && this.store.empConfig.appEntry ? this.store.empConfig.appEntry : "index"
|
|
718
|
-
);
|
|
719
|
-
this.setEntryItem(filename, this.store.empConfig.html, elist[0]);
|
|
720
|
-
}
|
|
721
|
-
if (Object.keys(this.store.empConfig.entries).length > 0) {
|
|
722
|
-
for (const [filename, op] of Object.entries(this.store.empConfig.entries)) {
|
|
723
|
-
this.setEntryItem(filename, { ...this.store.empConfig.html, ...op });
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
toConfig() {
|
|
728
|
-
for (const [chunk, op] of Object.entries(this.entriesConfig)) {
|
|
729
|
-
this.setRspackHtmlPlugin(op.html, chunk);
|
|
730
|
-
this.setRspackEntry(op.entry);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
entries_default = new RspackEntries();
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
// src/store/rspack/css.ts
|
|
739
|
-
var RspackCss, css_default;
|
|
740
|
-
var init_css = __esm({
|
|
741
|
-
"src/store/rspack/css.ts"() {
|
|
742
|
-
"use strict";
|
|
743
|
-
RspackCss = class {
|
|
744
|
-
store;
|
|
745
|
-
async setup(store) {
|
|
746
|
-
this.store = store;
|
|
747
|
-
const runFuns = [this.sass(), this.less(), this.css()];
|
|
748
|
-
await Promise.all(runFuns);
|
|
749
|
-
}
|
|
750
|
-
async sass() {
|
|
751
|
-
const sassLoader = {
|
|
752
|
-
loader: this.store.importResolve("sass-loader"),
|
|
753
|
-
options: {}
|
|
754
|
-
};
|
|
755
|
-
this.store.chain.merge({
|
|
756
|
-
module: {
|
|
757
|
-
rule: {
|
|
758
|
-
sass: {
|
|
759
|
-
test: /\.(sass|scss)$/,
|
|
760
|
-
use: {
|
|
761
|
-
// postcss: this.postcss,
|
|
762
|
-
sassLoader
|
|
763
|
-
},
|
|
764
|
-
type: "css/auto"
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
async less() {
|
|
771
|
-
const lessLoader = {
|
|
772
|
-
loader: this.store.importResolve("less-loader"),
|
|
773
|
-
options: {
|
|
774
|
-
lessOptions: {
|
|
775
|
-
javascriptEnabled: true
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
this.store.chain.merge({
|
|
780
|
-
module: {
|
|
781
|
-
rule: {
|
|
782
|
-
less: {
|
|
783
|
-
test: /\.less$/,
|
|
784
|
-
use: {
|
|
785
|
-
// postcss: this.postcss,
|
|
786
|
-
lessLoader
|
|
787
|
-
},
|
|
788
|
-
type: "css/auto"
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
async css() {
|
|
795
|
-
this.store.chain.merge({
|
|
796
|
-
module: {
|
|
797
|
-
rule: {
|
|
798
|
-
css: {
|
|
799
|
-
test: /\.css$/,
|
|
800
|
-
use: {
|
|
801
|
-
// postcss: this.postcss,
|
|
802
|
-
},
|
|
803
|
-
type: "css/auto"
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
// get postcss() {
|
|
810
|
-
// return {
|
|
811
|
-
// loader: this.store.importResolve('postcss-loader'),
|
|
812
|
-
// options: {
|
|
813
|
-
// postcssOptions: {
|
|
814
|
-
// plugins: this.store.empConfig.css.postcss,
|
|
815
|
-
// },
|
|
816
|
-
// },
|
|
817
|
-
// }
|
|
818
|
-
// }
|
|
819
|
-
};
|
|
820
|
-
css_default = new RspackCss();
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
// src/store/rspack/index.ts
|
|
825
|
-
var RspackStore, rspack_default;
|
|
826
|
-
var init_rspack = __esm({
|
|
827
|
-
"src/store/rspack/index.ts"() {
|
|
828
|
-
"use strict";
|
|
829
|
-
init_plugin();
|
|
830
|
-
init_module();
|
|
831
|
-
init_common();
|
|
832
|
-
init_entries();
|
|
833
|
-
init_css();
|
|
834
|
-
RspackStore = class {
|
|
835
|
-
store;
|
|
836
|
-
async setup(store) {
|
|
837
|
-
this.store = store;
|
|
838
|
-
const runFuns = [
|
|
839
|
-
common_default.setup(this.store),
|
|
840
|
-
module_default.setup(this.store),
|
|
841
|
-
plugin_default.setup(this.store),
|
|
842
|
-
entries_default.setup(this.store),
|
|
843
|
-
css_default.setup(this.store)
|
|
844
|
-
];
|
|
845
|
-
await Promise.all(runFuns);
|
|
846
|
-
await this.store.empConfig.plugins();
|
|
847
|
-
await this.store.empConfig.chain();
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
rspack_default = new RspackStore();
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
// src/helper/logger.ts
|
|
855
|
-
import chalk2 from "chalk";
|
|
856
|
-
var Logger, logger_default;
|
|
857
|
-
var init_logger = __esm({
|
|
858
|
-
"src/helper/logger.ts"() {
|
|
859
|
-
"use strict";
|
|
860
|
-
Logger = class {
|
|
861
|
-
pname = "";
|
|
862
|
-
logLevel = "debug";
|
|
863
|
-
setup({ pname, logLevel }) {
|
|
864
|
-
this.pname = pname;
|
|
865
|
-
if (logLevel)
|
|
866
|
-
this.logLevel = logLevel;
|
|
867
|
-
}
|
|
868
|
-
debug = (...args) => ["debug"].includes(this.logLevel) && console.log(...args);
|
|
869
|
-
info = (...args) => ["debug", "info"].includes(this.logLevel) && console.log(...args);
|
|
870
|
-
warn = (...args) => ["debug", "info", "warn"].includes(this.logLevel) && console.warn(...args);
|
|
871
|
-
error = (...args) => ["debug", "info", "warn", "error"].includes(this.logLevel) && console.error(...args);
|
|
872
|
-
blue = (msg) => {
|
|
873
|
-
console.log(`${chalk2.white.bgBlue(this.pname)}${chalk2.blue.bgWhite(` ${msg} `)}
|
|
874
|
-
`);
|
|
875
|
-
};
|
|
876
|
-
cyan = (msg) => {
|
|
877
|
-
console.log(`${chalk2.white.bgCyan(this.pname)}${chalk2.cyan.bgWhite(` ${msg} `)}
|
|
878
|
-
`);
|
|
879
|
-
};
|
|
880
|
-
magenta = (msg) => {
|
|
881
|
-
console.log(`${chalk2.white.bgMagenta(this.pname)}${chalk2.magenta.bgWhite(` ${msg} `)}
|
|
882
|
-
`);
|
|
883
|
-
};
|
|
884
|
-
green = (msg) => {
|
|
885
|
-
console.log(`${chalk2.white.bgGreen(this.pname)}${chalk2.green.bgWhite(` ${msg} `)}
|
|
886
|
-
`);
|
|
887
|
-
};
|
|
888
|
-
yellow = (msg) => {
|
|
889
|
-
console.log(`${chalk2.white.bgYellow(this.pname)}${chalk2.yellow.bgWhite(` ${msg} `)}
|
|
890
|
-
`);
|
|
891
|
-
};
|
|
892
|
-
red = (msg) => {
|
|
893
|
-
console.log(`${chalk2.white.bgRed(this.pname)}${chalk2.red.bgWhite(` ${msg} `)}
|
|
894
|
-
`);
|
|
895
|
-
};
|
|
896
|
-
sysError = (msg) => {
|
|
897
|
-
console.log(`${chalk2.white.bgRed(` System Error Tips `)}${chalk2.red.bgWhite(` ${msg} `)}
|
|
898
|
-
`);
|
|
899
|
-
};
|
|
900
|
-
//
|
|
901
|
-
link = (msg) => {
|
|
902
|
-
return chalk2.hex("#3498db")(msg);
|
|
903
|
-
};
|
|
904
|
-
title = (msg) => {
|
|
905
|
-
console.log(`${chalk2.greenBright.bold(`${this.pname}`)} ${chalk2.bgGreenBright(` ${msg} `)}
|
|
906
|
-
`);
|
|
907
|
-
};
|
|
908
|
-
};
|
|
909
|
-
logger_default = new Logger();
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
// src/store/empShareLib.ts
|
|
914
|
-
var EMPShareLib;
|
|
915
|
-
var init_empShareLib = __esm({
|
|
916
|
-
"src/store/empShareLib.ts"() {
|
|
917
|
-
"use strict";
|
|
918
|
-
init_store();
|
|
919
|
-
EMPShareLib = class {
|
|
920
|
-
externals = {};
|
|
921
|
-
externalAssets = { js: [], css: [] };
|
|
922
|
-
exp = /^([0-9a-zA-Z_\s]+)@(.*)/;
|
|
923
|
-
// 匹配库内容如 React@http://
|
|
924
|
-
config;
|
|
925
|
-
importMap = { imports: {} };
|
|
926
|
-
version;
|
|
927
|
-
isEmpshare = false;
|
|
928
|
-
async setup() {
|
|
929
|
-
this.config = store_default.empConfig.empShare;
|
|
930
|
-
this.version = store_default.empConfig.empShare.mfVersion;
|
|
931
|
-
this.isEmpshare = !!store_default.empConfig.empShare.name;
|
|
932
|
-
if (this.config.shareLib) {
|
|
933
|
-
this.setShareLib();
|
|
934
|
-
}
|
|
935
|
-
this.prepareEsm();
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* 是否取用 importMap
|
|
939
|
-
*/
|
|
940
|
-
get useImportMap() {
|
|
941
|
-
return this.config.useImportMap && store_default.empConfig.isESM;
|
|
942
|
-
}
|
|
943
|
-
get pluginConfig() {
|
|
944
|
-
const cf = { ...{}, ...this.config };
|
|
945
|
-
delete cf.mfVersion;
|
|
946
|
-
delete cf.shareLib;
|
|
947
|
-
delete cf.useImportMap;
|
|
948
|
-
const sc = {
|
|
949
|
-
manifest: false,
|
|
950
|
-
dts: false,
|
|
951
|
-
dev: false,
|
|
952
|
-
...cf
|
|
953
|
-
// runtimePlugins: [store.empResolve('resource/empSharePlugin.js')],
|
|
954
|
-
// @module-federation/runtime-tools
|
|
955
|
-
// implementation: store.importResolve('@module-federation/runtime-tools'),
|
|
956
|
-
// implementation: store.importResolve('@module-federation/runtime'),
|
|
957
|
-
// implementation: store.empResolve('resource/empShareRuntime.js'),
|
|
958
|
-
};
|
|
959
|
-
return sc;
|
|
960
|
-
}
|
|
961
|
-
prepareEsm() {
|
|
962
|
-
if (store_default.empConfig.isESM) {
|
|
963
|
-
this.config.library = { type: "module" };
|
|
964
|
-
const remotes = this.config.remotes || {};
|
|
965
|
-
for (const [k, v] of Object.entries(remotes)) {
|
|
966
|
-
if (typeof v === "string") {
|
|
967
|
-
const cb = v.match(this.exp) || [];
|
|
968
|
-
if (cb.length > 0) {
|
|
969
|
-
remotes[k] = cb[2];
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
this.config.remotes = remotes;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
async setShareLib() {
|
|
977
|
-
const mf = this.config;
|
|
978
|
-
const externals = [];
|
|
979
|
-
if (typeof mf.shareLib === "object") {
|
|
980
|
-
for (const [k, v] of Object.entries(mf.shareLib)) {
|
|
981
|
-
let externalsItem = {};
|
|
982
|
-
externalsItem.module = k;
|
|
983
|
-
if (typeof v === "string") {
|
|
984
|
-
const cb = v.match(this.exp) || [];
|
|
985
|
-
if (cb.length > 0) {
|
|
986
|
-
externalsItem.global = cb[1];
|
|
987
|
-
externalsItem.entry = cb[2];
|
|
988
|
-
externalsItem.type = "js";
|
|
989
|
-
externals.push(externalsItem);
|
|
990
|
-
externalsItem = {};
|
|
991
|
-
} else {
|
|
992
|
-
externalsItem.global = "";
|
|
993
|
-
externalsItem.entry = v;
|
|
994
|
-
externalsItem.type = "js";
|
|
995
|
-
externals.push(externalsItem);
|
|
996
|
-
externalsItem = {};
|
|
997
|
-
}
|
|
998
|
-
} else if (Array.isArray(v)) {
|
|
999
|
-
v.map((vo) => {
|
|
1000
|
-
if (!vo)
|
|
1001
|
-
return;
|
|
1002
|
-
const isCSS = vo.split("?")[0].endsWith(".css");
|
|
1003
|
-
if (isCSS) {
|
|
1004
|
-
externalsItem.entry = vo;
|
|
1005
|
-
externalsItem.type = "css";
|
|
1006
|
-
} else {
|
|
1007
|
-
const cb = vo.match(this.exp) || [];
|
|
1008
|
-
if (cb.length > 0) {
|
|
1009
|
-
externalsItem.global = cb[1];
|
|
1010
|
-
externalsItem.entry = cb[2];
|
|
1011
|
-
externalsItem.type = "js";
|
|
1012
|
-
} else {
|
|
1013
|
-
externalsItem.global = "";
|
|
1014
|
-
externalsItem.entry = vo;
|
|
1015
|
-
externalsItem.type = "js";
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
externals.push(externalsItem);
|
|
1019
|
-
externalsItem = {};
|
|
1020
|
-
});
|
|
1021
|
-
} else if (typeof v === "object" && v.entry) {
|
|
1022
|
-
externalsItem.entry = v.entry;
|
|
1023
|
-
externalsItem.global = v.global;
|
|
1024
|
-
externalsItem.type = v.type;
|
|
1025
|
-
externals.push(externalsItem);
|
|
1026
|
-
externalsItem = {};
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
await Promise.all([this.setExternalAssets(externals)]);
|
|
1031
|
-
}
|
|
1032
|
-
async setExternalAssets(externals = []) {
|
|
1033
|
-
if (externals.length > 0) {
|
|
1034
|
-
let list = [];
|
|
1035
|
-
list = list.concat(externals);
|
|
1036
|
-
list.map((v) => {
|
|
1037
|
-
v.type = v.type || "js";
|
|
1038
|
-
if (v.type === "js" && v.module) {
|
|
1039
|
-
if (v.global) {
|
|
1040
|
-
this.externals[v.module] = v.global;
|
|
1041
|
-
} else if (store_default.empConfig.isESM) {
|
|
1042
|
-
if (!this.useImportMap) {
|
|
1043
|
-
this.externals[v.module] = v.entry;
|
|
1044
|
-
} else {
|
|
1045
|
-
this.externals[v.module] = v.module;
|
|
1046
|
-
this.importMap.imports[v.module] = v.entry;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
if (v.entry && !store_default.empConfig.isESM) {
|
|
1050
|
-
this.externalAssets.js.push(v.entry);
|
|
1051
|
-
}
|
|
1052
|
-
} else if (v.type === "css" && v.entry) {
|
|
1053
|
-
this.externalAssets.css.push(v.entry);
|
|
1054
|
-
}
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
1061
|
-
|
|
1062
|
-
// src/helper/ipAddress.ts
|
|
1063
|
-
import url from "url";
|
|
1064
|
-
import chalk3 from "chalk";
|
|
1065
|
-
var IpAdress, ipAddress_default;
|
|
1066
|
-
var init_ipAddress = __esm({
|
|
1067
|
-
"src/helper/ipAddress.ts"() {
|
|
1068
|
-
"use strict";
|
|
1069
|
-
init_utils();
|
|
1070
|
-
IpAdress = class {
|
|
1071
|
-
imf = {
|
|
1072
|
-
protocol: "",
|
|
1073
|
-
port: 8e3,
|
|
1074
|
-
pathname: "/"
|
|
1075
|
-
};
|
|
1076
|
-
host = "0.0.0.0";
|
|
1077
|
-
urls = {
|
|
1078
|
-
lanUrlForConfig: "",
|
|
1079
|
-
lanUrlForTerminal: chalk3.gray("unavailable"),
|
|
1080
|
-
localUrlForTerminal: "",
|
|
1081
|
-
localUrlForBrowser: ""
|
|
1082
|
-
};
|
|
1083
|
-
setup(o) {
|
|
1084
|
-
if (o.host)
|
|
1085
|
-
this.host = o.host;
|
|
1086
|
-
if (o.protocol)
|
|
1087
|
-
this.imf.protocol = o.protocol;
|
|
1088
|
-
if (o.pathname)
|
|
1089
|
-
this.imf.pathname = o.pathname;
|
|
1090
|
-
if (o.port)
|
|
1091
|
-
this.imf.port = o.port;
|
|
1092
|
-
this.setupUrls();
|
|
1093
|
-
}
|
|
1094
|
-
setupUrls() {
|
|
1095
|
-
const { host } = this;
|
|
1096
|
-
const isUnspecifiedHost = host === "0.0.0.0" || host === "::";
|
|
1097
|
-
let prettyHost;
|
|
1098
|
-
if (isUnspecifiedHost) {
|
|
1099
|
-
prettyHost = "localhost";
|
|
1100
|
-
try {
|
|
1101
|
-
this.urls.lanUrlForConfig = this.getLanIp();
|
|
1102
|
-
if (this.urls.lanUrlForConfig) {
|
|
1103
|
-
if (/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(this.urls.lanUrlForConfig)) {
|
|
1104
|
-
this.urls.lanUrlForTerminal = this.prettyPrintUrl(this.urls.lanUrlForConfig);
|
|
1105
|
-
} else {
|
|
1106
|
-
this.urls.lanUrlForConfig = "";
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
} catch (_e) {
|
|
1110
|
-
}
|
|
1111
|
-
} else {
|
|
1112
|
-
prettyHost = host;
|
|
1113
|
-
this.urls.lanUrlForConfig = host;
|
|
1114
|
-
this.urls.lanUrlForTerminal = this.prettyPrintUrl(this.urls.lanUrlForConfig);
|
|
1115
|
-
}
|
|
1116
|
-
this.urls.localUrlForTerminal = this.prettyPrintUrl(prettyHost);
|
|
1117
|
-
this.urls.localUrlForBrowser = this.formatUrl(prettyHost);
|
|
1118
|
-
}
|
|
1119
|
-
getLanIp = getLanIp;
|
|
1120
|
-
formatUrl(hostname) {
|
|
1121
|
-
const { protocol, port, pathname } = this.imf;
|
|
1122
|
-
return url.format({
|
|
1123
|
-
protocol,
|
|
1124
|
-
hostname,
|
|
1125
|
-
port,
|
|
1126
|
-
pathname
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
prettyPrintUrl(hostname) {
|
|
1130
|
-
const { protocol, port, pathname } = this.imf;
|
|
1131
|
-
return url.format({
|
|
1132
|
-
protocol,
|
|
1133
|
-
hostname,
|
|
1134
|
-
port: chalk3.bold(port),
|
|
1135
|
-
pathname
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
};
|
|
1139
|
-
ipAddress_default = new IpAdress();
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
|
|
1143
|
-
// src/store/cycle/autoDevBase.ts
|
|
1144
|
-
var AutoDevBase, autoDevBase_default;
|
|
1145
|
-
var init_autoDevBase = __esm({
|
|
1146
|
-
"src/store/cycle/autoDevBase.ts"() {
|
|
1147
|
-
"use strict";
|
|
1148
|
-
init_ipAddress();
|
|
1149
|
-
init_utils();
|
|
1150
|
-
init_store();
|
|
1151
|
-
AutoDevBase = class {
|
|
1152
|
-
isADB = false;
|
|
1153
|
-
isHttps = false;
|
|
1154
|
-
get isHttpBase() {
|
|
1155
|
-
const base = store_default.empOptions.base || "";
|
|
1156
|
-
return base.indexOf("http://") > -1 || base.indexOf("https://") > -1;
|
|
1157
|
-
}
|
|
1158
|
-
setup() {
|
|
1159
|
-
this.isADB = !!store_default.empOptions.autoDevBase && store_default.mode === "development" && !this.isHttpBase;
|
|
1160
|
-
if (!this.isADB)
|
|
1161
|
-
return;
|
|
1162
|
-
const { server, https: https2 } = store_default.empOptions.server || {};
|
|
1163
|
-
this.isHttps = server === "https" || typeof server === "object" && server.type === "https" || https2 === true;
|
|
1164
|
-
const host = ipAddress_default.getLanIp();
|
|
1165
|
-
const protocol = this.isHttps ? "https" : "http";
|
|
1166
|
-
const port = store_default.empOptions.server?.port || 8e3;
|
|
1167
|
-
store_default.empOptions.base = `${protocol}://${host}:${port}/`;
|
|
1168
|
-
store_default.empOptions.server = deepAssign(
|
|
1169
|
-
{
|
|
1170
|
-
// host: host,//允许所有host 访问
|
|
1171
|
-
port,
|
|
1172
|
-
client: { webSocketURL: `${this.isHttps ? "wss" : "ws"}://${host}:${port}/ws` }
|
|
1173
|
-
},
|
|
1174
|
-
store_default.empOptions.server
|
|
1175
|
-
);
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
autoDevBase_default = new AutoDevBase();
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
// src/store/lifeCycle.ts
|
|
1183
|
-
var LifeCycle;
|
|
1184
|
-
var init_lifeCycle = __esm({
|
|
1185
|
-
"src/store/lifeCycle.ts"() {
|
|
1186
|
-
"use strict";
|
|
1187
|
-
init_autoDevBase();
|
|
1188
|
-
init_store();
|
|
1189
|
-
init_hook();
|
|
1190
|
-
LifeCycle = class {
|
|
1191
|
-
op = {};
|
|
1192
|
-
constructor(op = {}) {
|
|
1193
|
-
this.op = op;
|
|
1194
|
-
}
|
|
1195
|
-
// 获取 empOptions 之后、初始化 empConfig 之前
|
|
1196
|
-
async afterGetEmpOptions() {
|
|
1197
|
-
autoDevBase_default.setup();
|
|
1198
|
-
if (this.op.afterGetEmpOptions)
|
|
1199
|
-
await this.op.afterGetEmpOptions();
|
|
1200
|
-
}
|
|
1201
|
-
async beforePlugin() {
|
|
1202
|
-
if (store_default.empConfig.build.polyfill === "entry") {
|
|
1203
|
-
store_default.chain.plugin("empPolyfill").use(EmpPolyfillPlugin);
|
|
1204
|
-
}
|
|
1205
|
-
if (this.op.beforePlugin)
|
|
1206
|
-
await this.op.beforePlugin();
|
|
1207
|
-
}
|
|
1208
|
-
async afterPlugin() {
|
|
1209
|
-
if (this.op.afterPlugin)
|
|
1210
|
-
await this.op.afterPlugin();
|
|
1211
|
-
}
|
|
1212
|
-
async beforeBuild() {
|
|
1213
|
-
if (this.op.beforeBuild)
|
|
1214
|
-
await this.op.beforeBuild();
|
|
1215
|
-
}
|
|
1216
|
-
async afterBulid() {
|
|
1217
|
-
if (this.op.afterBulid)
|
|
1218
|
-
await this.op.afterBulid();
|
|
1219
|
-
}
|
|
1220
|
-
async beforeDevServe() {
|
|
1221
|
-
console.log(this.op);
|
|
1222
|
-
if (this.op.beforeDevServe)
|
|
1223
|
-
await this.op.beforeDevServe();
|
|
1224
|
-
}
|
|
1225
|
-
async afterDevServe() {
|
|
1226
|
-
if (this.op.afterDevServe)
|
|
1227
|
-
await this.op.afterDevServe();
|
|
1228
|
-
}
|
|
1229
|
-
async beforeServe() {
|
|
1230
|
-
if (this.op.beforeServe)
|
|
1231
|
-
await this.op.beforeServe();
|
|
1232
|
-
}
|
|
1233
|
-
async afterServe() {
|
|
1234
|
-
if (this.op.afterServe)
|
|
1235
|
-
await this.op.afterServe();
|
|
1236
|
-
}
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
});
|
|
1240
|
-
|
|
1241
|
-
// src/store/empConfig.ts
|
|
1242
|
-
import fs3 from "node:fs";
|
|
1243
|
-
var EmpConfig, empConfig_default;
|
|
1244
|
-
var init_empConfig = __esm({
|
|
1245
|
-
"src/store/empConfig.ts"() {
|
|
1246
|
-
"use strict";
|
|
1247
|
-
init_utils();
|
|
1248
|
-
init_empShareLib();
|
|
1249
|
-
init_lifeCycle();
|
|
1250
|
-
EmpConfig = class {
|
|
1251
|
-
store;
|
|
1252
|
-
/**
|
|
1253
|
-
* 项目代码路径
|
|
1254
|
-
* @default 'src'
|
|
1255
|
-
*/
|
|
1256
|
-
appSrc = "src";
|
|
1257
|
-
/**
|
|
1258
|
-
* 项目代码入口文件 如 `src/index.js`
|
|
1259
|
-
* (*)entries 设置后 该选项失效
|
|
1260
|
-
* @default 'index.js'
|
|
1261
|
-
*/
|
|
1262
|
-
appEntry = "";
|
|
1263
|
-
/**
|
|
1264
|
-
* publicPath 根路径 可参考webpack,业务模式默认为 auto
|
|
1265
|
-
* html 部分 publicPath 默认为 undefined,可设置全量域名或子目录适配,也可以单独在html设置 Public
|
|
1266
|
-
*
|
|
1267
|
-
* @default undefined
|
|
1268
|
-
*/
|
|
1269
|
-
base = "";
|
|
1270
|
-
target = [];
|
|
1271
|
-
assign(t, s) {
|
|
1272
|
-
s = s || {};
|
|
1273
|
-
return deepAssign(t, s);
|
|
1274
|
-
}
|
|
1275
|
-
empShareLib = new EMPShareLib();
|
|
1276
|
-
/**
|
|
1277
|
-
* 是否启动 esm 模块
|
|
1278
|
-
* @default true
|
|
1279
|
-
*/
|
|
1280
|
-
isESM = false;
|
|
1281
|
-
async autoDevSet() {
|
|
1282
|
-
if (this.store.mode === "development" && this.store.empOptions.autoDevBase) {
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
checkIsESM(target) {
|
|
1286
|
-
return ["es3", "es5"].indexOf(target) === -1;
|
|
1287
|
-
}
|
|
1288
|
-
lifeCycle;
|
|
1289
|
-
async setup(store) {
|
|
1290
|
-
this.store = store;
|
|
1291
|
-
await this.syncEmpOptions();
|
|
1292
|
-
this.lifeCycle = new LifeCycle(this.store.empOptions.lifeCycle);
|
|
1293
|
-
await this.lifeCycle.afterGetEmpOptions();
|
|
1294
|
-
this.isESM = this.checkIsESM(this.build.target);
|
|
1295
|
-
if (this.store.empOptions.target) {
|
|
1296
|
-
this.target = this.store.empOptions.target;
|
|
1297
|
-
if (Array.isArray(this.target) && !this.target.includes(this.build.target)) {
|
|
1298
|
-
this.target.push(this.build.target);
|
|
1299
|
-
}
|
|
1300
|
-
} else {
|
|
1301
|
-
this.target = ["web", this.build.target];
|
|
1302
|
-
}
|
|
1303
|
-
const { appSrc, base, appEntry } = this.store.empOptions;
|
|
1304
|
-
if (appSrc)
|
|
1305
|
-
this.appSrc = appSrc;
|
|
1306
|
-
if (base)
|
|
1307
|
-
this.base = base;
|
|
1308
|
-
if (appEntry)
|
|
1309
|
-
this.appEntry = appEntry;
|
|
1310
|
-
if (this.store.empConfig.empShare) {
|
|
1311
|
-
await this.empShareLib.setup();
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
async chain() {
|
|
1315
|
-
if (this.store.empOptions.chain) {
|
|
1316
|
-
await this.store.empOptions.chain(this.store.chain);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
async plugins() {
|
|
1320
|
-
const runPromiseFuns = [];
|
|
1321
|
-
if (this.store.empOptions.plugins && Array.isArray(this.store.empOptions.plugins) && this.store.empOptions.plugins.length > 0) {
|
|
1322
|
-
this.store.empOptions.plugins.map((fn) => {
|
|
1323
|
-
runPromiseFuns.push(fn.rsConfig(this.store));
|
|
1324
|
-
});
|
|
1325
|
-
await Promise.all(runPromiseFuns);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
get debug() {
|
|
1329
|
-
return this.assign(
|
|
1330
|
-
{
|
|
1331
|
-
loggerLevel: "info",
|
|
1332
|
-
clearLog: true,
|
|
1333
|
-
progress: true,
|
|
1334
|
-
showRsconfig: false,
|
|
1335
|
-
showPerformance: false,
|
|
1336
|
-
rspackCache: true,
|
|
1337
|
-
infrastructureLogging: {
|
|
1338
|
-
appendOnly: true,
|
|
1339
|
-
level: "warn"
|
|
1340
|
-
}
|
|
1341
|
-
},
|
|
1342
|
-
this.store.empOptions.debug
|
|
1343
|
-
);
|
|
1344
|
-
}
|
|
1345
|
-
get build() {
|
|
1346
|
-
const staticDir = this.store.empOptions.build?.staticDir ? `${this.store.empOptions.build?.staticDir}/` : "";
|
|
1347
|
-
return this.assign(
|
|
1348
|
-
{
|
|
1349
|
-
outDir: "dist",
|
|
1350
|
-
staticDir,
|
|
1351
|
-
assetsDir: "assets",
|
|
1352
|
-
publicDir: "public",
|
|
1353
|
-
chunkIds: this.store.isDev ? "named" : "deterministic",
|
|
1354
|
-
moduleIds: this.store.isDev ? "named" : "deterministic",
|
|
1355
|
-
sourcemap: true,
|
|
1356
|
-
minify: !this.store.isDev,
|
|
1357
|
-
minOptions: {},
|
|
1358
|
-
target: "es5",
|
|
1359
|
-
polyfill: false,
|
|
1360
|
-
coreJsFeatures: "stable",
|
|
1361
|
-
externalHelpers: false,
|
|
1362
|
-
browserslist: this.store.browserslistOptions.default
|
|
1363
|
-
},
|
|
1364
|
-
{ ...this.store.empOptions.build, staticDir }
|
|
1365
|
-
);
|
|
1366
|
-
}
|
|
1367
|
-
get html() {
|
|
1368
|
-
const meta = this.store.empOptions.html?.template ? [] : {
|
|
1369
|
-
charset: { charset: "utf-8" },
|
|
1370
|
-
"http-equiv": { "http-equiv": "X-UA-Compatible", content: "IE=edge" },
|
|
1371
|
-
viewport: {
|
|
1372
|
-
content: "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"
|
|
1373
|
-
},
|
|
1374
|
-
keywords: { keywords: "" },
|
|
1375
|
-
description: { description: "" }
|
|
1376
|
-
};
|
|
1377
|
-
const op = this.assign(
|
|
1378
|
-
{
|
|
1379
|
-
lang: "zh-CN",
|
|
1380
|
-
title: "EMP",
|
|
1381
|
-
inject: "body",
|
|
1382
|
-
minify: !this.store.isDev,
|
|
1383
|
-
scriptLoading: !this.isESM ? "defer" : "module",
|
|
1384
|
-
meta,
|
|
1385
|
-
files: {
|
|
1386
|
-
css: [],
|
|
1387
|
-
js: []
|
|
1388
|
-
},
|
|
1389
|
-
tags: {
|
|
1390
|
-
headTags: [],
|
|
1391
|
-
bodyTags: []
|
|
1392
|
-
}
|
|
1393
|
-
},
|
|
1394
|
-
this.store.empOptions.html
|
|
1395
|
-
);
|
|
1396
|
-
return op;
|
|
1397
|
-
}
|
|
1398
|
-
get entries() {
|
|
1399
|
-
return this.store.empOptions.entries ? this.store.empOptions.entries : {};
|
|
1400
|
-
}
|
|
1401
|
-
get server() {
|
|
1402
|
-
const sf = {
|
|
1403
|
-
host: `0.0.0.0`,
|
|
1404
|
-
port: 8e3,
|
|
1405
|
-
open: process.platform === "darwin",
|
|
1406
|
-
// open: false,
|
|
1407
|
-
// liveReload: false,
|
|
1408
|
-
hot: true,
|
|
1409
|
-
watchFiles: ["src/**/*.html"],
|
|
1410
|
-
static: [
|
|
1411
|
-
{
|
|
1412
|
-
directory: this.store.publicDir,
|
|
1413
|
-
watch: this.store.isDev
|
|
1414
|
-
}
|
|
1415
|
-
// 暴露 d.ts 文件
|
|
1416
|
-
/* {
|
|
1417
|
-
directory: this.store.outDir,
|
|
1418
|
-
watch: this.store.isDev,
|
|
1419
|
-
publicPath: this.base,
|
|
1420
|
-
staticOptions: {
|
|
1421
|
-
setHeaders: function (res: any, path: string) {
|
|
1422
|
-
if (path.toString().endsWith('.d.ts')) res?.set('Content-Type', 'application/javascript; charset=utf-8')
|
|
1423
|
-
},
|
|
1424
|
-
},
|
|
1425
|
-
}, */
|
|
1426
|
-
],
|
|
1427
|
-
allowedHosts: ["all"],
|
|
1428
|
-
historyApiFallback: true,
|
|
1429
|
-
headers: {
|
|
1430
|
-
"Access-Control-Allow-Origin": "*",
|
|
1431
|
-
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
1432
|
-
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
1433
|
-
}
|
|
1434
|
-
// client: {
|
|
1435
|
-
// webSocketURL: 'ws://172.29.104.208:8000/ws',
|
|
1436
|
-
// },
|
|
1437
|
-
};
|
|
1438
|
-
return this.assign(sf, this.store.empOptions.server);
|
|
1439
|
-
}
|
|
1440
|
-
get empShare() {
|
|
1441
|
-
return this.assign({ name: "", filename: "emp.js", shared: {}, mfVersion: 1.5 }, this.store.empOptions.empShare);
|
|
1442
|
-
}
|
|
1443
|
-
get css() {
|
|
1444
|
-
return this.assign({ postcss: [] }, this.store.empOptions.css);
|
|
1445
|
-
}
|
|
1446
|
-
get output() {
|
|
1447
|
-
const contenthashName = !this.store.isDev ? ".[contenthash:8]" : ".[contenthash:8]";
|
|
1448
|
-
const cssContentHashName = !this.store.isDev ? ".[contenthash:8]" : "";
|
|
1449
|
-
const { assetsDir, staticDir } = this.store.empConfig.build;
|
|
1450
|
-
const output = {
|
|
1451
|
-
publicPath: this.store.empConfig.base ? this.store.empConfig.base : "auto",
|
|
1452
|
-
// publicPath: this.base,
|
|
1453
|
-
crossOriginLoading: "anonymous",
|
|
1454
|
-
filename: `${staticDir}js/[name]${contenthashName}.js`,
|
|
1455
|
-
cssFilename: `${staticDir}css/[name]${cssContentHashName}.css`,
|
|
1456
|
-
cssChunkFilename: `${staticDir}css/[name]${cssContentHashName}.css`,
|
|
1457
|
-
assetModuleFilename: `${staticDir}${assetsDir}/[name]${contenthashName}[ext][query]`,
|
|
1458
|
-
path: this.store.outDir,
|
|
1459
|
-
clean: true
|
|
1460
|
-
};
|
|
1461
|
-
return this.assign(output, this.store.empOptions.output);
|
|
1462
|
-
}
|
|
1463
|
-
get define() {
|
|
1464
|
-
let dlist = { mode: this.store.mode, env: this.store.cliOptions.env };
|
|
1465
|
-
if (this.store.empOptions.define) {
|
|
1466
|
-
dlist = { ...dlist, ...this.store.empOptions.define };
|
|
1467
|
-
}
|
|
1468
|
-
return this.setDefine(dlist);
|
|
1469
|
-
}
|
|
1470
|
-
setDefine(o) {
|
|
1471
|
-
const defineFix = this.store.empOptions.defineFix ? this.store.empOptions.defineFix : this.isESM ? "esm" : "cjs";
|
|
1472
|
-
const options = {};
|
|
1473
|
-
Object.keys(o).map((key) => {
|
|
1474
|
-
if (defineFix === "all" || defineFix === "esm")
|
|
1475
|
-
options[`import.meta.env.${key}`] = JSON.stringify(o[key]);
|
|
1476
|
-
if (defineFix === "all" || defineFix === "cjs")
|
|
1477
|
-
options[`process.env.${key}`] = JSON.stringify(o[key]);
|
|
1478
|
-
options[`${key}`] = JSON.stringify(o[key]);
|
|
1479
|
-
});
|
|
1480
|
-
return options;
|
|
1481
|
-
}
|
|
1482
|
-
get externals() {
|
|
1483
|
-
const o = this.assign(this.empShareLib.externals, this.store.empOptions.externals);
|
|
1484
|
-
return o;
|
|
1485
|
-
}
|
|
1486
|
-
get resolve() {
|
|
1487
|
-
const rl = deepAssign(
|
|
1488
|
-
{
|
|
1489
|
-
alias: {
|
|
1490
|
-
src: this.store.resolve("src"),
|
|
1491
|
-
"@": this.store.resolve("src")
|
|
1492
|
-
},
|
|
1493
|
-
extensions: [
|
|
1494
|
-
"...",
|
|
1495
|
-
".js",
|
|
1496
|
-
".jsx",
|
|
1497
|
-
".mjs",
|
|
1498
|
-
".ts",
|
|
1499
|
-
".tsx",
|
|
1500
|
-
".css",
|
|
1501
|
-
".less",
|
|
1502
|
-
".scss",
|
|
1503
|
-
".sass",
|
|
1504
|
-
".json",
|
|
1505
|
-
".wasm",
|
|
1506
|
-
".vue",
|
|
1507
|
-
".svg",
|
|
1508
|
-
".svga"
|
|
1509
|
-
]
|
|
1510
|
-
},
|
|
1511
|
-
this.store.empOptions.resolve
|
|
1512
|
-
);
|
|
1513
|
-
return rl;
|
|
1514
|
-
}
|
|
1515
|
-
async syncEmpOptions() {
|
|
1516
|
-
const empConfigPath = this.store.resolve("emp-config.js");
|
|
1517
|
-
if (!fs3.existsSync(empConfigPath))
|
|
1518
|
-
return;
|
|
1519
|
-
const { default: empOptionsFn } = await import(this.store.importFileUrl(empConfigPath));
|
|
1520
|
-
if (typeof empOptionsFn === "function") {
|
|
1521
|
-
this.store.empOptions = await empOptionsFn(this.store);
|
|
1522
|
-
} else {
|
|
1523
|
-
this.store.empOptions = empOptionsFn || {};
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
get moduleTransformRule() {
|
|
1527
|
-
const { moduleTransform } = this.store.empOptions;
|
|
1528
|
-
const tf = this.assign({ defaultExclude: false }, moduleTransform);
|
|
1529
|
-
const moduleTransformExclude = { and: [], not: [] };
|
|
1530
|
-
if (tf.defaultExclude === true) {
|
|
1531
|
-
moduleTransformExclude.and.push(/(node_modules|bower_components)/);
|
|
1532
|
-
}
|
|
1533
|
-
if (tf?.exclude) {
|
|
1534
|
-
moduleTransformExclude.and = moduleTransformExclude.and.concat(tf.exclude);
|
|
1535
|
-
}
|
|
1536
|
-
if (moduleTransform?.include) {
|
|
1537
|
-
moduleTransformExclude.not = tf.include;
|
|
1538
|
-
}
|
|
1539
|
-
return moduleTransformExclude;
|
|
1540
|
-
}
|
|
1541
|
-
get cacheDir() {
|
|
1542
|
-
return this.store.empOptions.cacheDir ? this.store.empOptions.cacheDir : "node_modules/.emp-cache";
|
|
1543
|
-
}
|
|
1544
|
-
};
|
|
1545
|
-
empConfig_default = new EmpConfig();
|
|
1546
|
-
}
|
|
1547
|
-
});
|
|
1548
|
-
|
|
1549
|
-
// src/store/index.ts
|
|
1550
|
-
import path4 from "node:path";
|
|
1551
|
-
import fs4 from "node:fs/promises";
|
|
1552
|
-
import WPChain from "webpack-chain";
|
|
1553
|
-
import { pathToFileURL } from "node:url";
|
|
1554
|
-
import util from "node:util";
|
|
1555
|
-
var GlobalStore, store_default;
|
|
1556
|
-
var init_store = __esm({
|
|
1557
|
-
"src/store/index.ts"() {
|
|
1558
|
-
"use strict";
|
|
1559
|
-
init_nodePolyfill();
|
|
1560
|
-
init_rspack();
|
|
1561
|
-
init_logger();
|
|
1562
|
-
init_empConfig();
|
|
1563
|
-
init_utils();
|
|
1564
|
-
GlobalStore = class {
|
|
1565
|
-
/**
|
|
1566
|
-
* EMP Version
|
|
1567
|
-
* @default package version
|
|
1568
|
-
*/
|
|
1569
|
-
empPkg = { dependencies: {}, devDependencies: {}, version: "2.0.0", name: "" };
|
|
1570
|
-
/**
|
|
1571
|
-
* 项目pkg信息
|
|
1572
|
-
*/
|
|
1573
|
-
pkg = { dependencies: {}, devDependencies: {}, version: "0.0.0", name: "" };
|
|
1574
|
-
/**
|
|
1575
|
-
* 项目根目录绝对路径
|
|
1576
|
-
* @default process.cwd()
|
|
1577
|
-
*/
|
|
1578
|
-
root = process.cwd();
|
|
1579
|
-
/**
|
|
1580
|
-
* emp 内部根路径
|
|
1581
|
-
* @default path.resolve(__dirname, '../../')
|
|
1582
|
-
*/
|
|
1583
|
-
empRoot = empRoot;
|
|
1584
|
-
/**
|
|
1585
|
-
* emp 执行代码路径
|
|
1586
|
-
*/
|
|
1587
|
-
empSource = path4.resolve(this.empRoot, "dist");
|
|
1588
|
-
/**
|
|
1589
|
-
* 获取项目 根目录绝对路径
|
|
1590
|
-
* (*) relativePath 可以是绝对路径
|
|
1591
|
-
* @param relativePath
|
|
1592
|
-
* @returns
|
|
1593
|
-
*/
|
|
1594
|
-
resolve = (relativePath) => path4.isAbsolute(relativePath) ? relativePath : path4.resolve(this.root, relativePath);
|
|
1595
|
-
/**
|
|
1596
|
-
* 获取项目 emp内部根目录绝对路径
|
|
1597
|
-
* @param relativePath
|
|
1598
|
-
* @returns
|
|
1599
|
-
*/
|
|
1600
|
-
empResolve = (relativePath) => path4.resolve(this.empRoot, relativePath);
|
|
1601
|
-
/**
|
|
1602
|
-
* 源码地址 绝对路径
|
|
1603
|
-
*/
|
|
1604
|
-
appSrc = "";
|
|
1605
|
-
/**
|
|
1606
|
-
* 源码生成目录 绝对路径
|
|
1607
|
-
*/
|
|
1608
|
-
outDir = "";
|
|
1609
|
-
/**
|
|
1610
|
-
* 静态文件目录 绝对路径
|
|
1611
|
-
*/
|
|
1612
|
-
publicDir = "";
|
|
1613
|
-
/**
|
|
1614
|
-
* 静态资源
|
|
1615
|
-
*/
|
|
1616
|
-
resource = {
|
|
1617
|
-
dir: "",
|
|
1618
|
-
key: "",
|
|
1619
|
-
cert: ""
|
|
1620
|
-
};
|
|
1621
|
-
/**
|
|
1622
|
-
* 缓存目录 绝对路径
|
|
1623
|
-
*/
|
|
1624
|
-
cacheDir = "";
|
|
1625
|
-
mode = "development";
|
|
1626
|
-
cliMode = "dev";
|
|
1627
|
-
isDev = true;
|
|
1628
|
-
/**
|
|
1629
|
-
* 项目配置
|
|
1630
|
-
*/
|
|
1631
|
-
cliOptions;
|
|
1632
|
-
chain;
|
|
1633
|
-
rsConfig;
|
|
1634
|
-
empOptions = {};
|
|
1635
|
-
empConfig;
|
|
1636
|
-
// utils
|
|
1637
|
-
vCompare = vCompare;
|
|
1638
|
-
deepAssign = deepAssign;
|
|
1639
|
-
getLanIp = getLanIp;
|
|
1640
|
-
//
|
|
1641
|
-
//
|
|
1642
|
-
async setup(mode, cliOptions) {
|
|
1643
|
-
await this.initVars(mode, cliOptions);
|
|
1644
|
-
this.empConfig = empConfig_default;
|
|
1645
|
-
await this.empConfig.setup(this);
|
|
1646
|
-
this.initPaths();
|
|
1647
|
-
this.chain = new WPChain();
|
|
1648
|
-
await rspack_default.setup(this);
|
|
1649
|
-
this.setLogger();
|
|
1650
|
-
this.toConfig();
|
|
1651
|
-
this.logConfig();
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* 初始化 基础变量
|
|
1655
|
-
* @param mode cli名称
|
|
1656
|
-
* @param cliOptions cli配置
|
|
1657
|
-
*/
|
|
1658
|
-
async initVars(mode, cliOptions) {
|
|
1659
|
-
this.cliOptions = cliOptions || {};
|
|
1660
|
-
this.cliMode = "dev";
|
|
1661
|
-
this.mode = mode === "dev" ? "development" : "production";
|
|
1662
|
-
this.isDev = this.mode === "development";
|
|
1663
|
-
const empPkg = await getFileJson(this.empResolve("package.json"));
|
|
1664
|
-
const pkg = await getFileJson(this.resolve("package.json"));
|
|
1665
|
-
this.empPkg = { ...this.empPkg, ...empPkg };
|
|
1666
|
-
this.pkg = { ...this.pkg, ...pkg };
|
|
1667
|
-
}
|
|
1668
|
-
/**
|
|
1669
|
-
* 初始化 基础路径
|
|
1670
|
-
*/
|
|
1671
|
-
initPaths() {
|
|
1672
|
-
this.appSrc = this.resolve(this.empConfig.appSrc);
|
|
1673
|
-
this.outDir = this.resolve(this.empConfig.build.outDir);
|
|
1674
|
-
this.publicDir = this.resolve(this.empConfig.build.publicDir);
|
|
1675
|
-
this.cacheDir = this.resolve(this.empConfig.cacheDir);
|
|
1676
|
-
this.resource.dir = path4.join(this.empRoot, "resource");
|
|
1677
|
-
this.resource.cert = path4.join(this.resource.dir, "emp.cert");
|
|
1678
|
-
this.resource.key = path4.join(this.resource.dir, "emp.key");
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* 设置 日志等级
|
|
1682
|
-
*/
|
|
1683
|
-
setLogger() {
|
|
1684
|
-
let logLevel = this.cliMode === "dev" ? "debug" : "info";
|
|
1685
|
-
if (this.empConfig.debug.loggerLevel)
|
|
1686
|
-
logLevel = this.empConfig.debug.loggerLevel;
|
|
1687
|
-
logger_default.setup({
|
|
1688
|
-
pname: `EMP\u26A1${this.empPkg.version}${this.cliMode === "dev" ? ".DEV" : ""}`,
|
|
1689
|
-
logLevel
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
merge(o) {
|
|
1693
|
-
this.chain.merge(o);
|
|
1694
|
-
}
|
|
1695
|
-
importResolve(scope, importMetaUrl) {
|
|
1696
|
-
return importResolve(scope, importMetaUrl);
|
|
1697
|
-
}
|
|
1698
|
-
/**
|
|
1699
|
-
* windows import() 情况下 ES 的物理路径转换
|
|
1700
|
-
* pathToFileURL 是为了解决在window下,import文件路径解析异常
|
|
1701
|
-
* @param scope
|
|
1702
|
-
* @returns
|
|
1703
|
-
*/
|
|
1704
|
-
importFileUrl(scope) {
|
|
1705
|
-
return pathToFileURL(scope).toString();
|
|
1706
|
-
}
|
|
1707
|
-
/**
|
|
1708
|
-
* 同步 chain 配置到 rsConfig
|
|
1709
|
-
*/
|
|
1710
|
-
toConfig() {
|
|
1711
|
-
this.rsConfig = this.chain.toConfig();
|
|
1712
|
-
}
|
|
1713
|
-
/**
|
|
1714
|
-
* 打印 config
|
|
1715
|
-
*/
|
|
1716
|
-
logConfig() {
|
|
1717
|
-
if (this.empConfig.debug.showRsconfig) {
|
|
1718
|
-
if (typeof this.empConfig.debug.showRsconfig === "string") {
|
|
1719
|
-
const rsconfigPath = path4.join(this.root, this.empConfig.debug.showRsconfig);
|
|
1720
|
-
fs4.writeFile(rsconfigPath, JSON.stringify(this.rsConfig, null, 2));
|
|
1721
|
-
} else {
|
|
1722
|
-
const defaultOp = { colors: true, depth: null };
|
|
1723
|
-
const op = typeof this.empConfig.debug.showRsconfig === "object" ? deepAssign(defaultOp, this.empConfig.debug.showRsconfig) : defaultOp;
|
|
1724
|
-
console.log(logger_default.link(`[Compile Config]`));
|
|
1725
|
-
console.log(util.inspect(this.rsConfig, op));
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
get browserslistOptions() {
|
|
1730
|
-
return {
|
|
1731
|
-
default: ["chrome >= 87", "edge >= 88", "firefox >= 78", "safari >= 14"],
|
|
1732
|
-
h5: ["iOS >= 9", "Android >= 4.4", "last 2 versions", "> 0.2%", "not dead"],
|
|
1733
|
-
node: ["node >= 20"]
|
|
1734
|
-
};
|
|
1735
|
-
}
|
|
1736
|
-
};
|
|
1737
|
-
store_default = new GlobalStore();
|
|
1738
|
-
}
|
|
1739
|
-
});
|
|
1740
|
-
|
|
1741
|
-
// src/helper/openBrowser.ts
|
|
1742
|
-
import { exec } from "node:child_process";
|
|
1743
|
-
import { promisify } from "node:util";
|
|
1744
|
-
var execAsync, supportedChromiumBrowsers, getTargetBrowser, openBrowser, openBrowser_default;
|
|
1745
|
-
var init_openBrowser = __esm({
|
|
1746
|
-
"src/helper/openBrowser.ts"() {
|
|
1747
|
-
"use strict";
|
|
1748
|
-
init_logger();
|
|
1749
|
-
init_store();
|
|
1750
|
-
execAsync = promisify(exec);
|
|
1751
|
-
supportedChromiumBrowsers = [
|
|
1752
|
-
"Google Chrome Canary",
|
|
1753
|
-
"Google Chrome Dev",
|
|
1754
|
-
"Google Chrome Beta",
|
|
1755
|
-
"Google Chrome",
|
|
1756
|
-
"Microsoft Edge",
|
|
1757
|
-
"Brave Browser",
|
|
1758
|
-
"Vivaldi",
|
|
1759
|
-
"Chromium"
|
|
1760
|
-
];
|
|
1761
|
-
getTargetBrowser = async () => {
|
|
1762
|
-
let targetBrowser = process.env.BROWSER;
|
|
1763
|
-
if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
|
|
1764
|
-
const { stdout: ps } = await execAsync("ps cax");
|
|
1765
|
-
targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
|
|
1766
|
-
}
|
|
1767
|
-
return targetBrowser;
|
|
1768
|
-
};
|
|
1769
|
-
openBrowser = async (url2) => {
|
|
1770
|
-
const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
|
|
1771
|
-
if (shouldTryOpenChromeWithAppleScript) {
|
|
1772
|
-
try {
|
|
1773
|
-
const targetBrowser = await getTargetBrowser();
|
|
1774
|
-
if (targetBrowser) {
|
|
1775
|
-
const c = `osascript openChrome.applescript "${encodeURI(url2)}" "${targetBrowser}"`;
|
|
1776
|
-
await execAsync(c, {
|
|
1777
|
-
cwd: store_default.resource.dir
|
|
1778
|
-
});
|
|
1779
|
-
return true;
|
|
1780
|
-
}
|
|
1781
|
-
} catch (err) {
|
|
1782
|
-
logger_default.debug(err);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
try {
|
|
1786
|
-
const { default: open } = await import("open");
|
|
1787
|
-
await open(url2);
|
|
1788
|
-
return true;
|
|
1789
|
-
} catch (err) {
|
|
1790
|
-
logger_default.error("Failed to open start URL.");
|
|
1791
|
-
logger_default.error(err);
|
|
1792
|
-
return false;
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
openBrowser_default = openBrowser;
|
|
1796
|
-
}
|
|
1797
|
-
});
|
|
1798
|
-
|
|
1799
|
-
// src/helper/getPort.ts
|
|
1800
|
-
import net from "net";
|
|
1801
|
-
import os from "os";
|
|
1802
|
-
async function getPorts(basePort, host = "localhost") {
|
|
1803
|
-
if (basePort !== httpsPort && (basePort < minPort || basePort > maxPort)) {
|
|
1804
|
-
throw new Error(`Port number must lie between ${minPort} and ${maxPort}`);
|
|
1805
|
-
}
|
|
1806
|
-
let port = basePort;
|
|
1807
|
-
const localhosts = getLocalHosts();
|
|
1808
|
-
let hosts;
|
|
1809
|
-
if (host && !localhosts.has(host)) {
|
|
1810
|
-
hosts = /* @__PURE__ */ new Set([host]);
|
|
1811
|
-
} else {
|
|
1812
|
-
hosts = localhosts;
|
|
1813
|
-
}
|
|
1814
|
-
const portUnavailableErrors = /* @__PURE__ */ new Set(["EADDRINUSE", "EACCES"]);
|
|
1815
|
-
while (port <= maxPort) {
|
|
1816
|
-
try {
|
|
1817
|
-
const availablePort = await getAvailablePort(port, hosts);
|
|
1818
|
-
return availablePort;
|
|
1819
|
-
} catch (error) {
|
|
1820
|
-
if (!portUnavailableErrors.has(
|
|
1821
|
-
/** @type {NodeJS.ErrnoException} */
|
|
1822
|
-
error.code
|
|
1823
|
-
)) {
|
|
1824
|
-
throw error;
|
|
1825
|
-
}
|
|
1826
|
-
port += 1;
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
throw new Error("No available ports found");
|
|
1830
|
-
}
|
|
1831
|
-
var minPort, maxPort, httpsPort, getLocalHosts, checkAvailablePort, getAvailablePort;
|
|
1832
|
-
var init_getPort = __esm({
|
|
1833
|
-
"src/helper/getPort.ts"() {
|
|
1834
|
-
"use strict";
|
|
1835
|
-
minPort = 1024;
|
|
1836
|
-
maxPort = 65535;
|
|
1837
|
-
httpsPort = 443;
|
|
1838
|
-
getLocalHosts = () => {
|
|
1839
|
-
const interfaces = os.networkInterfaces();
|
|
1840
|
-
const results = /* @__PURE__ */ new Set([void 0, "0.0.0.0"]);
|
|
1841
|
-
for (const _interface of Object.values(interfaces)) {
|
|
1842
|
-
if (_interface) {
|
|
1843
|
-
for (const config of _interface) {
|
|
1844
|
-
results.add(config.address);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
return results;
|
|
1849
|
-
};
|
|
1850
|
-
checkAvailablePort = (basePort, host) => new Promise((resolve, reject) => {
|
|
1851
|
-
const server = net.createServer();
|
|
1852
|
-
server.unref();
|
|
1853
|
-
server.on("error", reject);
|
|
1854
|
-
server.listen(basePort, host, () => {
|
|
1855
|
-
const { port } = server.address();
|
|
1856
|
-
server.close(() => {
|
|
1857
|
-
resolve(port);
|
|
1858
|
-
});
|
|
1859
|
-
});
|
|
1860
|
-
});
|
|
1861
|
-
getAvailablePort = async (port, hosts) => {
|
|
1862
|
-
const nonExistentInterfaceErrors = /* @__PURE__ */ new Set(["EADDRNOTAVAIL", "EINVAL"]);
|
|
1863
|
-
for (const host of hosts) {
|
|
1864
|
-
try {
|
|
1865
|
-
await checkAvailablePort(port, host);
|
|
1866
|
-
} catch (error) {
|
|
1867
|
-
if (!nonExistentInterfaceErrors.has(
|
|
1868
|
-
/** @type {NodeJS.ErrnoException} */
|
|
1869
|
-
error.code
|
|
1870
|
-
)) {
|
|
1871
|
-
throw error;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
return port;
|
|
1876
|
-
};
|
|
1877
|
-
}
|
|
1878
|
-
});
|
|
1879
|
-
|
|
1880
|
-
// src/script/base.ts
|
|
1881
|
-
import fs5 from "node:fs/promises";
|
|
1882
|
-
import chalk4 from "chalk";
|
|
1883
|
-
var BaseScript;
|
|
1884
|
-
var init_base = __esm({
|
|
1885
|
-
"src/script/base.ts"() {
|
|
1886
|
-
"use strict";
|
|
1887
|
-
init_logger();
|
|
1888
|
-
init_store();
|
|
1889
|
-
init_utils();
|
|
1890
|
-
init_ipAddress();
|
|
1891
|
-
init_openBrowser();
|
|
1892
|
-
init_getPort();
|
|
1893
|
-
init_autoDevBase();
|
|
1894
|
-
BaseScript = class {
|
|
1895
|
-
sf = {
|
|
1896
|
-
protocol: "http",
|
|
1897
|
-
host: "0.0.0.0",
|
|
1898
|
-
port: 8e3,
|
|
1899
|
-
publicPath: "",
|
|
1900
|
-
publicHasHttp: false,
|
|
1901
|
-
isOpenBrower: false,
|
|
1902
|
-
url: "",
|
|
1903
|
-
urls: { localUrlForBrowser: "", localUrlForTerminal: "", lanUrlForTerminal: "", lanUrlForConfig: "" }
|
|
1904
|
-
};
|
|
1905
|
-
//重置服务信息
|
|
1906
|
-
async adaptServer() {
|
|
1907
|
-
this.sf.publicPath = store_default.rsConfig.output?.publicPath === "auto" ? "/" : store_default.rsConfig.output?.publicPath || "/";
|
|
1908
|
-
this.sf.isOpenBrower = !!store_default.empConfig.server.open;
|
|
1909
|
-
this.sf.protocol = this.isHttps ? "https" : "http";
|
|
1910
|
-
this.sf.host = store_default.empConfig.server.host ? store_default.empConfig.server.host : this.sf.host;
|
|
1911
|
-
this.sf.port = store_default.empConfig.server.port;
|
|
1912
|
-
await this.serverPort();
|
|
1913
|
-
ipAddress_default.setup(this.sf);
|
|
1914
|
-
if (this.sf.publicPath && (this.sf.publicPath.indexOf("http://") > -1 || this.sf.publicPath.indexOf("https://") > -1)) {
|
|
1915
|
-
this.sf.url = this.sf.publicPath;
|
|
1916
|
-
this.sf.publicHasHttp = true;
|
|
1917
|
-
this.sf.urls.localUrlForTerminal = ipAddress_default.prettyPrintUrl("localhost");
|
|
1918
|
-
} else {
|
|
1919
|
-
this.sf.urls = ipAddress_default.urls;
|
|
1920
|
-
this.sf.url = this.sf.urls.localUrlForBrowser;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
startOpen() {
|
|
1924
|
-
const { urls } = this.sf;
|
|
1925
|
-
if (this.sf.publicHasHttp) {
|
|
1926
|
-
logger_default.info(`${chalk4.greenBright("\u279C")} Local: ${logger_default.link(urls.localUrlForTerminal)}`);
|
|
1927
|
-
logger_default.info(`${chalk4.greenBright("\u279C")} Network: ${logger_default.link(this.sf.publicPath)}`);
|
|
1928
|
-
} else {
|
|
1929
|
-
logger_default.info(`${chalk4.greenBright("\u279C")} Local: ${logger_default.link(urls.localUrlForTerminal)}`);
|
|
1930
|
-
logger_default.info(`${chalk4.greenBright("\u279C")} Network: ${logger_default.link(urls.lanUrlForTerminal)}
|
|
1931
|
-
`);
|
|
1932
|
-
}
|
|
1933
|
-
if (this.sf.isOpenBrower)
|
|
1934
|
-
openBrowser_default(this.sf.url);
|
|
1935
|
-
}
|
|
1936
|
-
// 实现整体生命周期运转
|
|
1937
|
-
async setup(cliName, o) {
|
|
1938
|
-
await store_default.setup(cliName, o);
|
|
1939
|
-
if (store_default.empConfig.debug.clearLog) {
|
|
1940
|
-
clearConsole();
|
|
1941
|
-
}
|
|
1942
|
-
logger_default.title(`${cliName}`);
|
|
1943
|
-
await this.adaptServer();
|
|
1944
|
-
await this.run();
|
|
1945
|
-
this.afterRun();
|
|
1946
|
-
}
|
|
1947
|
-
async run() {
|
|
1948
|
-
}
|
|
1949
|
-
afterRun() {
|
|
1950
|
-
process.on("SIGINT", function() {
|
|
1951
|
-
process.exit();
|
|
1952
|
-
});
|
|
1953
|
-
}
|
|
1954
|
-
get isHttps() {
|
|
1955
|
-
const { server, https: https2 } = store_default.empConfig.server || {};
|
|
1956
|
-
return server === "https" || typeof server === "object" && server.type === "https" || https2 === true;
|
|
1957
|
-
}
|
|
1958
|
-
getcert() {
|
|
1959
|
-
return Promise.all([fs5.readFile(store_default.resource.key), fs5.readFile(store_default.resource.cert)]);
|
|
1960
|
-
}
|
|
1961
|
-
async serverPort() {
|
|
1962
|
-
if (autoDevBase_default.isADB)
|
|
1963
|
-
return;
|
|
1964
|
-
const { port, host } = this.sf;
|
|
1965
|
-
const serverPort = await getPorts(port, host);
|
|
1966
|
-
if (serverPort !== port) {
|
|
1967
|
-
this.sf.port = serverPort;
|
|
1968
|
-
if (store_default.rsConfig.devServer?.port)
|
|
1969
|
-
store_default.rsConfig.devServer.port = serverPort;
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
});
|
|
1975
|
-
|
|
1976
|
-
// src/helper/buildPrint.ts
|
|
1977
|
-
import chalk5 from "chalk";
|
|
1978
|
-
import path5 from "node:path";
|
|
1979
|
-
import { gzipSizeSync } from "gzip-size";
|
|
1980
|
-
import fs6 from "node:fs";
|
|
1981
|
-
function printHeader(longestFileLength, longestLabelLength) {
|
|
1982
|
-
const longestLengths = [longestFileLength, longestLabelLength];
|
|
1983
|
-
const headerRow = ["File", "Size", "Gzipped"].reduce((prev, cur, index) => {
|
|
1984
|
-
const length = longestLengths[index];
|
|
1985
|
-
let curLabel = cur;
|
|
1986
|
-
if (length) {
|
|
1987
|
-
curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
|
|
1988
|
-
}
|
|
1989
|
-
return `${prev + curLabel} `;
|
|
1990
|
-
}, " ");
|
|
1991
|
-
console.log(chalk5.bold.blue(headerRow));
|
|
1992
|
-
}
|
|
1993
|
-
async function printFileSizes(stats) {
|
|
1994
|
-
const origin = stats.toJson({
|
|
1995
|
-
all: false,
|
|
1996
|
-
assets: true,
|
|
1997
|
-
timings: true
|
|
1998
|
-
});
|
|
1999
|
-
timeDone(origin.time);
|
|
2000
|
-
const filteredAssets = origin.assets.filter((asset) => filterAsset(asset.name));
|
|
2001
|
-
const assets = filteredAssets.map(formatAsset);
|
|
2002
|
-
assets.sort((a, b) => a.size - b.size);
|
|
2003
|
-
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
2004
|
-
const longestFileLength = Math.max(...assets.map((a) => (a.folder + path5.sep + a.name).length));
|
|
2005
|
-
printHeader(longestFileLength, longestLabelLength);
|
|
2006
|
-
let totalSize = 0;
|
|
2007
|
-
let totalGzipSize = 0;
|
|
2008
|
-
assets.forEach((asset) => {
|
|
2009
|
-
let { sizeLabel } = asset;
|
|
2010
|
-
const { name, folder, gzipSizeLabel } = asset;
|
|
2011
|
-
const fileNameLength = (folder + path5.sep + name).length;
|
|
2012
|
-
const sizeLength = sizeLabel.length;
|
|
2013
|
-
totalSize += asset.size;
|
|
2014
|
-
totalGzipSize += asset.gzippedSize;
|
|
2015
|
-
if (sizeLength < longestLabelLength) {
|
|
2016
|
-
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
2017
|
-
sizeLabel += rightPadding;
|
|
2018
|
-
}
|
|
2019
|
-
let fileNameLabel = chalk5.gray(asset.folder + path5.sep) + coloringAssetName(asset.name);
|
|
2020
|
-
if (fileNameLength < longestFileLength) {
|
|
2021
|
-
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
2022
|
-
fileNameLabel += rightPadding;
|
|
2023
|
-
}
|
|
2024
|
-
logger_default.info(` ${fileNameLabel} ${chalk5.gray(sizeLabel)} ${gzipSizeLabel}`);
|
|
2025
|
-
});
|
|
2026
|
-
const totalSizeLabel = `${chalk5.bold.blue("Total size:")} ${calcFileSize(totalSize)}`;
|
|
2027
|
-
const gzippedSizeLabel = `${chalk5.bold.blue("Gzipped size:")} ${calcFileSize(totalGzipSize)}`;
|
|
2028
|
-
logger_default.info(`
|
|
2029
|
-
${totalSizeLabel}
|
|
2030
|
-
${gzippedSizeLabel}
|
|
2031
|
-
`);
|
|
2032
|
-
}
|
|
2033
|
-
function timeDone(mis = 0) {
|
|
2034
|
-
logger_default.info(`${chalk5.greenBright("\u2713")} Ready in ${timeFormat(Number(mis))}`);
|
|
2035
|
-
}
|
|
2036
|
-
var HTML_REGEX, JS_REGEX, CSS_REGEX, filterAsset, getAssetColor, formatAsset, calcFileSize, coloringAssetName;
|
|
2037
|
-
var init_buildPrint = __esm({
|
|
2038
|
-
"src/helper/buildPrint.ts"() {
|
|
2039
|
-
"use strict";
|
|
2040
|
-
init_store();
|
|
2041
|
-
init_logger();
|
|
2042
|
-
init_utils();
|
|
2043
|
-
HTML_REGEX = /\.html$/;
|
|
2044
|
-
JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
|
|
2045
|
-
CSS_REGEX = /\.css$/;
|
|
2046
|
-
filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
2047
|
-
getAssetColor = (size) => {
|
|
2048
|
-
if (size > 300 * 1e3) {
|
|
2049
|
-
return chalk5.red;
|
|
2050
|
-
}
|
|
2051
|
-
if (size > 100 * 1e3) {
|
|
2052
|
-
return chalk5.yellow;
|
|
2053
|
-
}
|
|
2054
|
-
return chalk5.white;
|
|
2055
|
-
};
|
|
2056
|
-
formatAsset = (asset) => {
|
|
2057
|
-
const fileName = asset.name.split("?")[0];
|
|
2058
|
-
const sizeLabel = calcFileSize(asset.size);
|
|
2059
|
-
const name = path5.basename(fileName);
|
|
2060
|
-
const folder = path5.join(path5.basename(store_default.empConfig.build.outDir), path5.dirname(fileName));
|
|
2061
|
-
const contents = fs6.readFileSync(path5.join(store_default.empConfig.build.outDir, fileName));
|
|
2062
|
-
const size = contents.length;
|
|
2063
|
-
const gzippedSize = gzipSizeSync(contents);
|
|
2064
|
-
const gzipSizeLabel = getAssetColor(gzippedSize)(calcFileSize(gzippedSize));
|
|
2065
|
-
return {
|
|
2066
|
-
size,
|
|
2067
|
-
folder,
|
|
2068
|
-
name,
|
|
2069
|
-
gzippedSize,
|
|
2070
|
-
sizeLabel,
|
|
2071
|
-
gzipSizeLabel
|
|
2072
|
-
};
|
|
2073
|
-
};
|
|
2074
|
-
calcFileSize = (len) => {
|
|
2075
|
-
const val = len / 1e3;
|
|
2076
|
-
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
2077
|
-
};
|
|
2078
|
-
coloringAssetName = (assetName) => {
|
|
2079
|
-
if (JS_REGEX.test(assetName)) {
|
|
2080
|
-
return chalk5.yellowBright(assetName);
|
|
2081
|
-
}
|
|
2082
|
-
if (CSS_REGEX.test(assetName)) {
|
|
2083
|
-
return chalk5.greenBright(assetName);
|
|
2084
|
-
}
|
|
2085
|
-
if (HTML_REGEX.test(assetName)) {
|
|
2086
|
-
return chalk5.blueBright(assetName);
|
|
2087
|
-
}
|
|
2088
|
-
return chalk5.magenta(assetName);
|
|
2089
|
-
};
|
|
2090
|
-
}
|
|
2091
|
-
});
|
|
2092
|
-
|
|
2093
|
-
// src/script/dev.ts
|
|
2094
|
-
var dev_exports = {};
|
|
2095
|
-
__export(dev_exports, {
|
|
2096
|
-
default: () => dev_default
|
|
2097
|
-
});
|
|
2098
|
-
import { rspack as rspack2 } from "@rspack/core";
|
|
2099
|
-
import { RspackDevServer } from "@rspack/dev-server";
|
|
2100
|
-
var DevScript, dev_default;
|
|
2101
|
-
var init_dev = __esm({
|
|
2102
|
-
"src/script/dev.ts"() {
|
|
2103
|
-
"use strict";
|
|
2104
|
-
init_store();
|
|
2105
|
-
init_base();
|
|
2106
|
-
init_logger();
|
|
2107
|
-
init_utils();
|
|
2108
|
-
init_buildPrint();
|
|
2109
|
-
DevScript = class extends BaseScript {
|
|
2110
|
-
get rspackDevConfig() {
|
|
2111
|
-
const cf = deepAssign(store_default.rsConfig, {
|
|
2112
|
-
stats: {
|
|
2113
|
-
all: false,
|
|
2114
|
-
colors: true,
|
|
2115
|
-
assets: false,
|
|
2116
|
-
chunks: false,
|
|
2117
|
-
entrypoints: false,
|
|
2118
|
-
timings: false,
|
|
2119
|
-
version: false,
|
|
2120
|
-
errors: true,
|
|
2121
|
-
warnings: true
|
|
2122
|
-
},
|
|
2123
|
-
devServer: {
|
|
2124
|
-
open: false,
|
|
2125
|
-
setupExitSignals: true
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
|
-
return cf;
|
|
2129
|
-
}
|
|
2130
|
-
async devServerConfig() {
|
|
2131
|
-
const devServer = Object.assign({}, store_default.rsConfig.devServer);
|
|
2132
|
-
if (this.isHttps) {
|
|
2133
|
-
if (devServer.https === true) {
|
|
2134
|
-
delete devServer.https;
|
|
2135
|
-
}
|
|
2136
|
-
if (!devServer.server) {
|
|
2137
|
-
const [key, cert] = await this.getcert();
|
|
2138
|
-
devServer.server = {
|
|
2139
|
-
type: "https",
|
|
2140
|
-
options: {
|
|
2141
|
-
key,
|
|
2142
|
-
cert
|
|
2143
|
-
// minVersion: 'TLSv1.1',
|
|
2144
|
-
// key: fs.readFileSync(path.join(__dirname, './server.key')),
|
|
2145
|
-
// pfx: fs.readFileSync(path.join(__dirname, './server.pfx')),
|
|
2146
|
-
// cert: fs.readFileSync(path.join(__dirname, './server.crt')),
|
|
2147
|
-
// ca: fs.readFileSync(path.join(__dirname, './ca.pem')),
|
|
2148
|
-
// passphrase: 'webpack-dev-server',
|
|
2149
|
-
// requestCert: true,
|
|
2150
|
-
}
|
|
2151
|
-
};
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
return devServer;
|
|
2155
|
-
}
|
|
2156
|
-
async run() {
|
|
2157
|
-
const compiler = rspack2(this.rspackDevConfig);
|
|
2158
|
-
if (!store_default.rsConfig.devServer) {
|
|
2159
|
-
logger_default.error("devServer is not defined in config");
|
|
2160
|
-
return;
|
|
2161
|
-
}
|
|
2162
|
-
const devServer = await this.devServerConfig();
|
|
2163
|
-
const serverApp = new RspackDevServer(devServer, compiler);
|
|
2164
|
-
this.startOpen();
|
|
2165
|
-
if (store_default.empConfig.lifeCycle.beforeDevServe)
|
|
2166
|
-
await store_default.empConfig.lifeCycle.beforeDevServe();
|
|
2167
|
-
await serverApp.start();
|
|
2168
|
-
const showTimeDone = (s) => {
|
|
2169
|
-
const d = s?.toJson({ all: false, colors: false, assets: false, chunks: false, timings: true });
|
|
2170
|
-
timeDone(d.time);
|
|
2171
|
-
};
|
|
2172
|
-
if (store_default.empConfig.debug.showPerformance)
|
|
2173
|
-
compiler.hooks.afterDone.tap("done", showTimeDone);
|
|
2174
|
-
serverApp.middleware?.waitUntilValid((s) => {
|
|
2175
|
-
if (!store_default.empConfig.debug.showPerformance)
|
|
2176
|
-
showTimeDone(s);
|
|
2177
|
-
if (store_default.empConfig.lifeCycle.afterDevServe)
|
|
2178
|
-
store_default.empConfig.lifeCycle.afterDevServe();
|
|
2179
|
-
});
|
|
2180
|
-
}
|
|
2181
|
-
};
|
|
2182
|
-
dev_default = new DevScript();
|
|
2183
|
-
}
|
|
2184
|
-
});
|
|
2185
|
-
|
|
2186
|
-
// src/script/build.ts
|
|
2187
|
-
var build_exports = {};
|
|
2188
|
-
__export(build_exports, {
|
|
2189
|
-
default: () => build_default
|
|
2190
|
-
});
|
|
2191
|
-
import { rspack as rspack3 } from "@rspack/core";
|
|
2192
|
-
var BuildScript, build_default;
|
|
2193
|
-
var init_build = __esm({
|
|
2194
|
-
"src/script/build.ts"() {
|
|
2195
|
-
"use strict";
|
|
2196
|
-
init_logger();
|
|
2197
|
-
init_store();
|
|
2198
|
-
init_base();
|
|
2199
|
-
init_buildPrint();
|
|
2200
|
-
BuildScript = class extends BaseScript {
|
|
2201
|
-
async run() {
|
|
2202
|
-
if (store_default.empConfig.lifeCycle.beforeBuild)
|
|
2203
|
-
await store_default.empConfig.lifeCycle.beforeBuild();
|
|
2204
|
-
rspack3(store_default.rsConfig, async (err, stats) => {
|
|
2205
|
-
if (err !== null) {
|
|
2206
|
-
logger_default.error(err.stack || err);
|
|
2207
|
-
if (err.message) {
|
|
2208
|
-
logger_default.error(err.message);
|
|
2209
|
-
}
|
|
2210
|
-
return;
|
|
2211
|
-
}
|
|
2212
|
-
if (!stats) {
|
|
2213
|
-
logger_default.red("Stats is Undefined.");
|
|
2214
|
-
return;
|
|
2215
|
-
}
|
|
2216
|
-
if (stats.hasErrors()) {
|
|
2217
|
-
logger_default.error(
|
|
2218
|
-
stats.toString({
|
|
2219
|
-
colors: true,
|
|
2220
|
-
children: true
|
|
2221
|
-
})
|
|
2222
|
-
);
|
|
2223
|
-
logger_default.red("Failed to compile.");
|
|
2224
|
-
process.exit(1);
|
|
2225
|
-
}
|
|
2226
|
-
if (stats.hasWarnings()) {
|
|
2227
|
-
logger_default.yellow(`Compiled with warnings.`);
|
|
2228
|
-
logger_default.warn(
|
|
2229
|
-
stats.toString({
|
|
2230
|
-
colors: true,
|
|
2231
|
-
children: true
|
|
2232
|
-
})
|
|
2233
|
-
);
|
|
2234
|
-
}
|
|
2235
|
-
await printFileSizes(stats);
|
|
2236
|
-
if (store_default.empConfig.lifeCycle.afterBulid)
|
|
2237
|
-
await store_default.empConfig.lifeCycle.afterBulid();
|
|
2238
|
-
});
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
build_default = new BuildScript();
|
|
2242
|
-
}
|
|
2243
|
-
});
|
|
2244
|
-
|
|
2245
|
-
// src/script/httpBase.ts
|
|
2246
|
-
import express from "express";
|
|
2247
|
-
import cors from "cors";
|
|
2248
|
-
import compression from "compression";
|
|
2249
|
-
import https from "https";
|
|
2250
|
-
var HttpServer;
|
|
2251
|
-
var init_httpBase = __esm({
|
|
2252
|
-
"src/script/httpBase.ts"() {
|
|
2253
|
-
"use strict";
|
|
2254
|
-
init_base();
|
|
2255
|
-
HttpServer = class extends BaseScript {
|
|
2256
|
-
app;
|
|
2257
|
-
async init() {
|
|
2258
|
-
const app = express();
|
|
2259
|
-
app.use(compression());
|
|
2260
|
-
app.use(cors());
|
|
2261
|
-
this.app = app;
|
|
2262
|
-
}
|
|
2263
|
-
async server() {
|
|
2264
|
-
if (this.isHttps) {
|
|
2265
|
-
const [key, cert] = await this.getcert();
|
|
2266
|
-
const httpsServer = https.createServer(
|
|
2267
|
-
typeof this.isHttps !== "boolean" ? this.isHttps : {
|
|
2268
|
-
key,
|
|
2269
|
-
cert
|
|
2270
|
-
},
|
|
2271
|
-
this.app
|
|
2272
|
-
);
|
|
2273
|
-
httpsServer.listen(this.sf.port, async () => {
|
|
2274
|
-
this.startOpen();
|
|
2275
|
-
await this.onReady();
|
|
2276
|
-
});
|
|
2277
|
-
} else {
|
|
2278
|
-
this.app.listen(this.sf.port, async () => {
|
|
2279
|
-
this.startOpen();
|
|
2280
|
-
await this.onReady();
|
|
2281
|
-
});
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
async onReady() {
|
|
2285
|
-
}
|
|
2286
|
-
async middleware() {
|
|
2287
|
-
}
|
|
2288
|
-
async start() {
|
|
2289
|
-
await this.init();
|
|
2290
|
-
await this.middleware();
|
|
2291
|
-
await this.server();
|
|
2292
|
-
}
|
|
2293
|
-
};
|
|
2294
|
-
}
|
|
2295
|
-
});
|
|
2296
|
-
|
|
2297
|
-
// src/script/serve.ts
|
|
2298
|
-
var serve_exports = {};
|
|
2299
|
-
__export(serve_exports, {
|
|
2300
|
-
default: () => serve_default
|
|
2301
|
-
});
|
|
2302
|
-
import express2 from "express";
|
|
2303
|
-
import path6 from "path";
|
|
2304
|
-
import fsp from "node:fs/promises";
|
|
2305
|
-
import fs7 from "node:fs";
|
|
2306
|
-
var ServeScript, serve_default;
|
|
2307
|
-
var init_serve = __esm({
|
|
2308
|
-
"src/script/serve.ts"() {
|
|
2309
|
-
"use strict";
|
|
2310
|
-
init_httpBase();
|
|
2311
|
-
init_store();
|
|
2312
|
-
init_logger();
|
|
2313
|
-
init_buildPrint();
|
|
2314
|
-
ServeScript = class extends HttpServer {
|
|
2315
|
-
timing = 0;
|
|
2316
|
-
async run() {
|
|
2317
|
-
this.timing = Date.now();
|
|
2318
|
-
if (!fs7.existsSync(store_default.outDir)) {
|
|
2319
|
-
return logger_default.sysError(`emp serve must be executed after emp build,${store_default.outDir} not exist!`);
|
|
2320
|
-
}
|
|
2321
|
-
if (store_default.empConfig.lifeCycle.beforeServe)
|
|
2322
|
-
await store_default.empConfig.lifeCycle.beforeServe();
|
|
2323
|
-
this.start();
|
|
2324
|
-
}
|
|
2325
|
-
async middleware() {
|
|
2326
|
-
const staticRoot = store_default.resolve(store_default.rsConfig.output?.path);
|
|
2327
|
-
this.app.use(express2.static(staticRoot));
|
|
2328
|
-
const html = await fsp.readFile(path6.join(staticRoot, "index.html"), "utf8");
|
|
2329
|
-
this.app.get("*", (req, res) => res.send(html));
|
|
2330
|
-
}
|
|
2331
|
-
async onReady() {
|
|
2332
|
-
timeDone(Date.now() - this.timing);
|
|
2333
|
-
if (store_default.empConfig.lifeCycle.afterServe)
|
|
2334
|
-
await store_default.empConfig.lifeCycle.afterServe();
|
|
2335
|
-
}
|
|
2336
|
-
};
|
|
2337
|
-
serve_default = new ServeScript();
|
|
2338
|
-
}
|
|
2339
|
-
});
|
|
2340
|
-
|
|
2341
|
-
// src/index.ts
|
|
2342
|
-
init_store();
|
|
2343
|
-
|
|
2344
|
-
// src/script/index.ts
|
|
2345
|
-
init_store();
|
|
2346
|
-
init_utils();
|
|
2347
|
-
init_logger();
|
|
2348
|
-
import { program } from "commander";
|
|
2349
|
-
import process2, { exit } from "node:process";
|
|
2350
|
-
function runScript() {
|
|
2351
|
-
const needVersion = "20.0.0";
|
|
2352
|
-
if (vCompare(needVersion, process2.versions.node) === 1) {
|
|
2353
|
-
logger_default.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${process2.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${needVersion}`);
|
|
2354
|
-
exit(0);
|
|
2355
|
-
}
|
|
2356
|
-
program.version(store_default.empPkg.version, "-v, --version").usage("<command> [options]");
|
|
2357
|
-
program.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>", "\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot", "\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open", "\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts", "\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile", "\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>", "\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option(
|
|
2358
|
-
"-ev, --env-vars <key=value>",
|
|
2359
|
-
"\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",
|
|
2360
|
-
(ovalue, memo) => {
|
|
2361
|
-
const [key, value] = ovalue.split("=");
|
|
2362
|
-
memo[key] = value;
|
|
2363
|
-
return memo;
|
|
2364
|
-
},
|
|
2365
|
-
{}
|
|
2366
|
-
).action(async (o) => {
|
|
2367
|
-
const { default: devScript } = await Promise.resolve().then(() => (init_dev(), dev_exports));
|
|
2368
|
-
await devScript.setup("dev", o);
|
|
2369
|
-
});
|
|
2370
|
-
program.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>", "\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze", "\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts", "\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile", "\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>", "\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option(
|
|
2371
|
-
"-ev, --env-vars <key=value>",
|
|
2372
|
-
"\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",
|
|
2373
|
-
(ovalue, memo) => {
|
|
2374
|
-
const [key, value] = ovalue.split("=");
|
|
2375
|
-
memo[key] = value;
|
|
2376
|
-
return memo;
|
|
2377
|
-
},
|
|
2378
|
-
{}
|
|
2379
|
-
).action(async (o) => {
|
|
2380
|
-
const { default: buildScript } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2381
|
-
await buildScript.setup("build", o);
|
|
2382
|
-
});
|
|
2383
|
-
program.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>", "\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async (o) => {
|
|
2384
|
-
const { default: serveScript } = await Promise.resolve().then(() => (init_serve(), serve_exports));
|
|
2385
|
-
await serveScript.setup("serve", o);
|
|
2386
|
-
});
|
|
2387
|
-
program.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>", "\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>", "\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action((o) => {
|
|
2388
|
-
});
|
|
2389
|
-
program.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]", "JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action((o) => {
|
|
2390
|
-
});
|
|
2391
|
-
program.parse(process2.argv);
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
|
-
// src/script/dts.ts
|
|
2395
|
-
init_store();
|
|
2396
|
-
import glob2 from "fast-glob";
|
|
2397
|
-
import fs8 from "node:fs/promises";
|
|
2398
|
-
import path7 from "node:path";
|
|
2399
|
-
var globalImportRE = /(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g;
|
|
2400
|
-
var staticImportRE = /(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/;
|
|
2401
|
-
var dynamicImportRE = /import\(['"]([^;\n]+?)['"]\)/;
|
|
2402
|
-
var DTSBundle = class {
|
|
2403
|
-
list = [];
|
|
2404
|
-
outDir = store_default.resolve("dist");
|
|
2405
|
-
aliasName = "@empjs/cli";
|
|
2406
|
-
async setup(outDir, aliasName) {
|
|
2407
|
-
if (outDir)
|
|
2408
|
-
this.outDir = outDir;
|
|
2409
|
-
if (aliasName)
|
|
2410
|
-
this.aliasName = aliasName;
|
|
2411
|
-
const bs = await this.readDts();
|
|
2412
|
-
await this.writeCode(bs);
|
|
2413
|
-
}
|
|
2414
|
-
async readDts() {
|
|
2415
|
-
this.list = await glob2([`${store_default.empConfig.build.outDir}/**/*.d.ts`]);
|
|
2416
|
-
const p = [];
|
|
2417
|
-
this.list.map((d) => {
|
|
2418
|
-
d = store_default.resolve(d);
|
|
2419
|
-
p.push(this.readFile(d));
|
|
2420
|
-
});
|
|
2421
|
-
let bs = await Promise.all(p);
|
|
2422
|
-
bs = bs.map((d) => this.replaceAliasPath(d));
|
|
2423
|
-
return bs;
|
|
2424
|
-
}
|
|
2425
|
-
async readFile(src) {
|
|
2426
|
-
const code = await fs8.readFile(src, { encoding: "utf-8" });
|
|
2427
|
-
return { src, code };
|
|
2428
|
-
}
|
|
2429
|
-
replaceAliasPath({ src, code }) {
|
|
2430
|
-
code = code.replace(globalImportRE, (str) => {
|
|
2431
|
-
let matchResult = str.match(staticImportRE);
|
|
2432
|
-
if (!matchResult) {
|
|
2433
|
-
matchResult = str.match(dynamicImportRE);
|
|
2434
|
-
}
|
|
2435
|
-
if (matchResult && matchResult[1]) {
|
|
2436
|
-
const rs = matchResult[1];
|
|
2437
|
-
if (!rs.startsWith("."))
|
|
2438
|
-
return str;
|
|
2439
|
-
const filename = path7.resolve(path7.dirname(src), rs).replace(this.outDir, this.aliasName);
|
|
2440
|
-
return str.replace(matchResult[1], filename);
|
|
2441
|
-
}
|
|
2442
|
-
return str;
|
|
2443
|
-
});
|
|
2444
|
-
let mod = src.replace(this.outDir, this.aliasName).replace(".d.ts", "");
|
|
2445
|
-
if (mod.endsWith("/index")) {
|
|
2446
|
-
mod = mod.replace("/index", "");
|
|
2447
|
-
}
|
|
2448
|
-
code = this.warpDeclareModule(mod, code);
|
|
2449
|
-
return { code, src, mod };
|
|
2450
|
-
}
|
|
2451
|
-
warpDeclareModule(mod, code) {
|
|
2452
|
-
return `declare module '${mod}' {\r
|
|
2453
|
-
${code}}\r
|
|
2454
|
-
`;
|
|
2455
|
-
}
|
|
2456
|
-
async writeCode(bs) {
|
|
2457
|
-
let c = "";
|
|
2458
|
-
bs.map((d) => {
|
|
2459
|
-
c += d.code;
|
|
2460
|
-
});
|
|
2461
|
-
await fs8.writeFile(path7.join(this.outDir.replace("dist", "types"), "type.d.ts"), c);
|
|
2462
|
-
}
|
|
2463
|
-
};
|
|
2464
|
-
var dts_default = new DTSBundle();
|
|
2465
|
-
|
|
2466
|
-
// src/index.ts
|
|
2467
|
-
function defineConfig(config) {
|
|
2468
|
-
return config;
|
|
2469
|
-
}
|
|
2470
|
-
export {
|
|
2471
|
-
defineConfig,
|
|
2472
|
-
dts_default as dts,
|
|
2473
|
-
runScript,
|
|
2474
|
-
store_default as store
|
|
2475
|
-
};
|
|
2476
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
var dt=Object.defineProperty;var l=(r,e)=>()=>(r&&(e=r(r=0)),e);var J=(r,e)=>{for(var t in e)dt(r,t,{get:e[t],enumerable:!0})};import{fileURLToPath as yt}from"node:url";import{dirname as bt}from"node:path";import{readFile as vt}from"node:fs/promises";import be from"node:module";import _ from"node:path";var ve,Ct,V,T,Ce,we,W=l(()=>{"use strict";ve=yt(import.meta.url),Ct=bt(ve),V=async r=>{try{let e=await vt(r);return JSON.parse(e)}catch(e){console.error(e)}},T=be.createRequire(import.meta.url),Ce=(r,e)=>{let t=T;return e&&(t=be.createRequire(e)),t.resolve(r)},we=_.resolve(Ct,ve).replace(`${_.sep}dist${_.sep}index.js`,"")});import k from"@rspack/core";import xe from"fs";import{ModuleFederationPlugin as wt}from"@module-federation/enhanced/rspack";var X,Se,Ee=l(()=>{"use strict";X=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minify()];await this.store.empConfig.lifeCycle.beforePlugin(),await Promise.all(t),await this.store.empConfig.lifeCycle.afterPlugin()}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(e,[{analyzerPort:this.store.empConfig.server.port,defaultSizes:"gzip",analyzerHost:this.store.getLanIp()||"127.0.0.1"}])}async define(){this.store.chain.plugin("definePlugin").use(k.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");xe.existsSync(e)&&xe.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(k.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(k.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){let{isEmpshare:e}=this.store.empConfig.empShareLib;if(!e)return;let t=wt;this.store.chain.plugin("empShare").use(t,[this.store.empConfig.empShareLib.pluginConfig])}minify(){this.store.chain.optimization.minimize(this.store.mode==="production"),this.store.chain.optimization.minimizer("minJs").use(k.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]),this.store.chain.optimization.minimizer("minCss").use(k.SwcCssMinimizerRspackPlugin,[{}])}},Se=new X});import xt from"chalk";import St from"fs-extra";import{ip as Et}from"address";import{gateway4sync as Ot}from"default-gateway";function Pe(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function f(r,...e){for(let t of e)for(let s in t){let i=t[s],o=r[s];if(Object(i)==i&&Object(o)===o){r[s]=f(o,i);continue}r[s]=t[s]}return r}var j,Oe,L,ke,$e,y=l(()=>{"use strict";j=()=>{let{int:r}=Ot();return Et(r||"")||"127.0.0.1"},Oe=r=>{try{let{version:e}=St.readJSONSync(r);return e}catch{return}};L=(r="",e="")=>{let t=r.replace("^","").split("."),s=e.replace("^","").split("."),i=Math.max(t.length,s.length),o=0;for(let p=0;p<i;p++){let m=t.length>p?t[p]:0,g=isNaN(Number(m))?m.charCodeAt():Number(m),O=s.length>p?s[p]:0,c=isNaN(Number(O))?O.charCodeAt():Number(O);if(g<c){o=-1;break}else if(g>c){o=1;break}}return o},ke=r=>{r=r/1e3;let e=s=>xt.bold(s);if(r<1)return`${r*1e3} ms`;if(r<10){let s=r>=.01?2:3;return`${e(r.toFixed(s))} s`}if(r<60)return`${e(r.toFixed(1))} s`;let t=r/60;return`${e(t.toFixed(2))} m`},$e=r=>`data:text/javascript,${r}`});import Te from"node:path";var q,je,Le=l(()=>{"use strict";W();y();q=class{store;swcJsOptions={};swcTsOptions={};coreJs={version:"3",alias:"",path:""};async setup(e){this.store=e;let t=[this.files(),this.scripts(),this.rspackGenerator(),this.rspackParser()];await Promise.all(t)}rspackGenerator(){let e=this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]";this.store.chain.merge({module:{generator:{css:{localIdentName:e},"css/auto":{localIdentName:e},"css/module":{localIdentName:e}}}})}rspackParser(){this.store.chain.merge({module:{parser:{css:{namedExports:!1},"css/auto":{namedExports:!1},"css/module":{namedExports:!1}}}})}get isPolyfill(){return this.store.empConfig.build.polyfill}swcParser(e){switch(e){case"js":return{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1};case"ts":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0}}}swcJsc(e){let{target:t,externalHelpers:s}=this.store.empConfig.build;return{parser:this.swcParser(e),transform:{},target:t,externalHelpers:s,preserveAllComments:!0}}get swcCoreVersion(){let[e,t]=this.coreJs.version.split(".");return`${e}.${t}`}swcOptions(e){let t={jsc:this.swcJsc(e),isModule:"unknown"};return this.isPolyfill&&(delete t.jsc.target,t.env={coreJs:this.swcCoreVersion,targets:this.store.empConfig.build.browserslist},this.store.empConfig.isESM||(t.env.mode=this.store.empConfig.build.polyfill),this.store.empConfig.build.polyfill==="usage"&&(t.env.shippedProposals=!0,t.env.include=["es.object.values","es.array.flat"])),t}swcInitOptions(){let{externalHelpers:e}=this.store.empConfig.build;e&&this.store.chain.resolve.alias.set("@swc/helpers",Te.dirname(T.resolve("@swc/helpers/package.json"))),this.coreJs.path=T.resolve("core-js/package.json");let t=Oe(this.coreJs.path);t&&(this.coreJs.version=t),this.coreJs.alias=Te.dirname(this.coreJs.path),this.store.empConfig.build.polyfill&&(this.store.chain.resolve.alias.set("core-js",this.coreJs.alias),this.store.chain.module.rule("javascript").exclude.add(/core-js/),this.store.chain.module.rule("typescript").exclude.add(/core-js/)),this.swcTsOptions=this.swcOptions("ts"),this.swcJsOptions=this.swcOptions("js")}async scripts(){this.swcInitOptions();let e=!1,t=[];this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,exclude:t,sideEffects:e,use:{swc:{loader:"builtin:swc-loader",options:this.swcTsOptions}}},javascript:{test:/\.(js|jsx)$/,exclude:t,sideEffects:e,use:{swc:{loader:"builtin:swc-loader",options:this.swcJsOptions}}}}}})}async files(){this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},je=new q});var Q,De,Fe=l(()=>{"use strict";Q=class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(t)}async common(){this.store.merge({node:{global:!0},experiments:{rspackFuture:{newTreeshaking:this.store.empConfig.debug.newTreeshaking},outputModule:this.store.empConfig.isESM,topLevelAwait:!0},target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:this.store.empConfig.debug.rspackCache,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){let e={moduleIds:this.store.empConfig.build.moduleIds,chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify,splitChunks:{chunks:"async",cacheGroups:{}}};this.store.empConfig.build.polyfill&&(e.splitChunks.cacheGroups={}),this.store.chain.merge({optimization:e})}},De=new Q});import Ae from"html-webpack-plugin";var Me,D,Re,F,Pt,M,Y=l(()=>{"use strict";y();u();Me="HtmlImportMapPlugin",D=class{importMap;chunk;constructor(e,t){this.importMap=e,this.chunk=t}apply(e){e.hooks.compilation.tap(Me,t=>{Ae.getHooks(t).alterAssetTagGroups.tapAsync(Me,(s,i)=>{if(!s.plugin.userOptions.chunks?.includes(this.chunk))return i(null,s);s.headTags.push({tagName:"script",attributes:{type:"importmap"},innerHTML:`${JSON.stringify(this.importMap,null,2)}`,voidTag:!1,meta:{plugin:void 0}}),i(null,s)})})}},Re="HtmlEmpShareLibPlugin",F=class{chunk;files;constructor(e,t){this.files=f({js:[],css:[]},e),this.chunk=t}apply(e){e.hooks.compilation.tap(Re,t=>{let s=this.files;Ae.getHooks(t).alterAssetTagGroups.tapAsync(Re,(i,o)=>{if(!i.plugin.userOptions.chunks?.includes(this.chunk))return o(null,i);s.js.map(p=>{i.headTags.push({tagName:"script",attributes:{src:p},voidTag:!1,meta:{plugin:void 0}})}),s.css.map(p=>{i.headTags.push({tagName:"link",attributes:{rel:"stylesheet",href:p},voidTag:!1,meta:{plugin:void 0}})}),o(null,i)})})}},Pt=()=>{let r=[`import 'core-js/${n.empConfig.build.coreJsFeatures}'`].join(`
|
|
2
|
+
`);return $e(r)},M=class{constructor(){}apply(e){let{webpack:t}=e;new t.EntryPlugin(e.context,Pt(),{name:void 0}).apply(e)}}});import kt from"html-webpack-plugin";import $t from"fast-glob";import x from"node:path";var Z,Be,ze=l(()=>{"use strict";y();Y();Z=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),e.tags=e.tags||{},e}setChunk(e){return e.replace(x.extname(e),"").replace(`${this.store.empConfig.appSrc}${x.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(x.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(x.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(x.join(this.store.empConfig.appSrc,e));let i=this.setChunk(e),o=[s];this.entriesConfig[i]={entry:{[i]:o},html:this.setHtmlConfig(t,[i])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(kt,[e]),this.store.empConfig.empShareLib&&(e.files=f(e.files,this.store.empConfig.empShareLib.externalAssets)),this.store.chain.plugin(`html-plugin-empShare-${t}`).use(F,[e.files,t]),this.store.empConfig.empShareLib.useImportMap&&this.store.chain.plugin(`html-plugin-import-map-${t}`).use(D,[this.store.empConfig.empShareLib.importMap,t])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=x.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await $t([e]);if(t[0]){let s=x.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(s,this.store.empConfig.html,t[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[s,i]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...i})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},Be=new Z});var K,Ge,Ie=l(()=>{"use strict";K=class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let e={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:{sassLoader:e},type:"css/auto"}}}})}async less(){let e={loader:this.store.importResolve("less-loader"),options:{lessOptions:{javascriptEnabled:!0}}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:{lessLoader:e},type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:{},type:"css/auto"}}}})}},Ge=new K});var ee,He,Ue=l(()=>{"use strict";Ee();Le();Fe();ze();Ie();ee=class{store;async setup(e){this.store=e;let t=[De.setup(this.store),je.setup(this.store),Se.setup(this.store),Be.setup(this.store),Ge.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},He=new ee});import h from"chalk";var te,a,b=l(()=>{"use strict";te=class{pname="";logLevel="debug";setup({pname:e,logLevel:t}){this.pname=e,t&&(this.logLevel=t)}debug=(...e)=>["debug"].includes(this.logLevel)&&console.log(...e);info=(...e)=>["debug","info"].includes(this.logLevel)&&console.log(...e);warn=(...e)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...e);error=(...e)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...e);blue=e=>{console.log(`${h.white.bgBlue(this.pname)}${h.blue.bgWhite(` ${e} `)}
|
|
3
|
+
`)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
|
|
4
|
+
`)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
|
|
5
|
+
`)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
|
|
6
|
+
`)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
|
|
7
|
+
`)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
|
|
8
|
+
`)};sysError=e=>{console.log(`${h.white.bgRed(" System Error Tips ")}${h.red.bgWhite(` ${e} `)}
|
|
9
|
+
`)};link=e=>h.hex("#3498db")(e);title=e=>{console.log(`${h.greenBright.bold(`${this.pname}`)} ${h.bgGreenBright(` ${e} `)}
|
|
10
|
+
`)}},a=new te});var R,Ne=l(()=>{"use strict";u();R=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;config;importMap={imports:{}};version;isEmpshare=!1;async setup(){this.config=n.empConfig.empShare,this.version=n.empConfig.empShare.mfVersion,this.isEmpshare=!!n.empConfig.empShare.name,this.config.shareLib&&this.setShareLib(),this.prepareEsm()}get useImportMap(){return this.config.useImportMap&&n.empConfig.isESM}get pluginConfig(){let e={...this.config};return delete e.mfVersion,delete e.shareLib,delete e.useImportMap,{manifest:!1,dts:!1,dev:!1,...e}}prepareEsm(){if(n.empConfig.isESM){this.config.library={type:"module"};let e=this.config.remotes||{};for(let[t,s]of Object.entries(e))if(typeof s=="string"){let i=s.match(this.exp)||[];i.length>0&&(e[t]=i[2])}this.config.remotes=e}}async setShareLib(){let e=this.config,t=[];if(typeof e.shareLib=="object")for(let[s,i]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof i=="string"){let p=i.match(this.exp)||[];p.length>0?(o.global=p[1],o.entry=p[2],o.type="js",t.push(o),o={}):(o.global="",o.entry=i,o.type="js",t.push(o),o={})}else Array.isArray(i)?i.map(p=>{if(!p)return;if(p.split("?")[0].endsWith(".css"))o.entry=p,o.type="css";else{let g=p.match(this.exp)||[];g.length>0?(o.global=g[1],o.entry=g[2],o.type="js"):(o.global="",o.entry=p,o.type="js")}t.push(o),o={}}):typeof i=="object"&&i.entry&&(o.entry=i.entry,o.global=i.global,o.type=i.type,t.push(o),o={})}await Promise.all([this.setExternalAssets(t)])}async setExternalAssets(e=[]){if(e.length>0){let t=[];t=t.concat(e),t.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global?this.externals[s.module]=s.global:n.empConfig.isESM&&(this.useImportMap?(this.externals[s.module]=s.module,this.importMap.imports[s.module]=s.entry):this.externals[s.module]=s.entry),s.entry&&!n.empConfig.isESM&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Je from"url";import _e from"chalk";var se,E,re=l(()=>{"use strict";y();se=class{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:_e.gray("unavailable"),localUrlForTerminal:"",localUrlForBrowser:""};setup(e){e.host&&(this.host=e.host),e.protocol&&(this.imf.protocol=e.protocol),e.pathname&&(this.imf.pathname=e.pathname),e.port&&(this.imf.port=e.port),this.setupUrls()}setupUrls(){let{host:e}=this,t=e==="0.0.0.0"||e==="::",s;if(t){s="localhost";try{this.urls.lanUrlForConfig=this.getLanIp(),this.urls.lanUrlForConfig&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(this.urls.lanUrlForConfig)?this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig):this.urls.lanUrlForConfig="")}catch{}}else s=e,this.urls.lanUrlForConfig=e,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(s),this.urls.localUrlForBrowser=this.formatUrl(s)}getLanIp=j;formatUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Je.format({protocol:t,hostname:e,port:s,pathname:i})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Je.format({protocol:t,hostname:e,port:_e.bold(s),pathname:i})}},E=new se});var ie,A,oe=l(()=>{"use strict";re();y();u();ie=class{isADB=!1;isHttps=!1;get isHttpBase(){let e=n.empOptions.base||"";return e.indexOf("http://")>-1||e.indexOf("https://")>-1}setup(){if(this.isADB=!!n.empOptions.autoDevBase&&n.mode==="development"&&!this.isHttpBase,!this.isADB)return;let{server:e,https:t}=n.empOptions.server||{};this.isHttps=e==="https"||typeof e=="object"&&e.type==="https"||t===!0;let s=E.getLanIp(),i=this.isHttps?"https":"http",o=n.empOptions.server?.port||8e3;n.empOptions.base=`${i}://${s}:${o}/`,n.empOptions.server=f({port:o,client:{webSocketURL:`${this.isHttps?"wss":"ws"}://${s}:${o}/ws`}},n.empOptions.server)}},A=new ie});var B,Ve=l(()=>{"use strict";oe();u();Y();B=class{op={};constructor(e={}){this.op=e}async afterGetEmpOptions(){A.setup(),this.op.afterGetEmpOptions&&await this.op.afterGetEmpOptions()}async beforePlugin(){n.empConfig.build.polyfill==="entry"&&n.chain.plugin("empPolyfill").use(M),this.op.beforePlugin&&await this.op.beforePlugin()}async afterPlugin(){this.op.afterPlugin&&await this.op.afterPlugin()}async beforeBuild(){this.op.beforeBuild&&await this.op.beforeBuild()}async afterBulid(){this.op.afterBulid&&await this.op.afterBulid()}async beforeDevServe(){console.log(this.op),this.op.beforeDevServe&&await this.op.beforeDevServe()}async afterDevServe(){this.op.afterDevServe&&await this.op.afterDevServe()}async beforeServe(){this.op.beforeServe&&await this.op.beforeServe()}async afterServe(){this.op.afterServe&&await this.op.afterServe()}}});import Tt from"node:fs";var ne,We,Xe=l(()=>{"use strict";y();Ne();Ve();ne=class{store;appSrc="src";appEntry="";base="";target=[];assign(e,t){return t=t||{},f(e,t)}empShareLib=new R;isESM=!1;async autoDevSet(){this.store.mode==="development"&&this.store.empOptions.autoDevBase}checkIsESM(e){return["es3","es5"].indexOf(e)===-1}lifeCycle;async setup(e){this.store=e,await this.syncEmpOptions(),this.lifeCycle=new B(this.store.empOptions.lifeCycle),await this.lifeCycle.afterGetEmpOptions(),this.isESM=this.checkIsESM(this.build.target),this.store.empOptions.target?(this.target=this.store.empOptions.target,Array.isArray(this.target)&&!this.target.includes(this.build.target)&&this.target.push(this.build.target)):this.target=["web",this.build.target];let{appSrc:t,base:s,appEntry:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i),this.store.empConfig.empShare&&await this.empShareLib.setup()}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1,showPerformance:!1,rspackCache:!0,infrastructureLogging:{appendOnly:!0,level:"warn"},newTreeshaking:this.store.empConfig.isESM},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",moduleIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{},target:"es5",polyfill:!1,coreJsFeatures:"stable",externalHelpers:!1,browserslist:this.store.browserslistOptions.default},{...this.store.empOptions.build,staticDir:e})}get html(){let e=this.store.empOptions.html?.template?{}:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"},keywords:{keywords:""},description:{description:""}};return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,scriptLoading:this.isESM?"module":"defer",meta:e,files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get server(){let e={host:"0.0.0.0",port:8e3,open:process.platform==="darwin",hot:!0,watchFiles:["src/**/*.html"],static:[{directory:this.store.publicDir,watch:this.store.isDev}],allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}};return this.assign(e,this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{},mfVersion:1.5},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=this.store.isDev?"":".[contenthash:8]",{assetsDir:s,staticDir:i}=this.store.empConfig.build,o={publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${i}js/[name]${e}.js`,cssFilename:`${i}css/[name]${t}.css`,cssChunkFilename:`${i}css/[name]${t}.css`,assetModuleFilename:`${i}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0};return this.assign(o,this.store.empOptions.output)}get define(){let e={mode:this.store.mode,env:this.store.cliOptions.env};return this.store.empOptions.define&&(e={...e,...this.store.empOptions.define}),this.setDefine(e)}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:this.isESM?"esm":"cjs",s={};return Object.keys(e).map(i=>{(t==="all"||t==="esm")&&(s[`import.meta.env.${i}`]=JSON.stringify(e[i])),(t==="all"||t==="cjs")&&(s[`process.env.${i}`]=JSON.stringify(e[i])),s[`${i}`]=JSON.stringify(e[i])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return f({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Tt.existsSync(e))return;let{default:t}=await import(this.store.importFileUrl(e));typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return t.defaultExclude===!0&&s.and.push(/(node_modules|bower_components)/),t?.exclude&&(s.and=s.and.concat(t.exclude)),e?.include&&(s.not=t.include),s}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}},We=new ne});import v from"node:path";import jt from"node:fs/promises";import Lt from"webpack-chain";import{pathToFileURL as Dt}from"node:url";import Ft from"node:util";var pe,n,u=l(()=>{"use strict";W();Ue();b();Xe();y();pe=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=we;empSource=v.resolve(this.empRoot,"dist");resolve=e=>v.isAbsolute(e)?e:v.resolve(this.root,e);empResolve=e=>v.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;cliOptions;chain;rsConfig;empOptions={};empConfig;vCompare=L;deepAssign=f;getLanIp=j;async setup(e,t){await this.initVars(e,t),this.empConfig=We,await this.empConfig.setup(this),this.initPaths(),this.chain=new Lt,await He.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await V(this.empResolve("package.json")),i=await V(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...i}}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=v.join(this.empRoot,"resource"),this.resource.cert=v.join(this.resource.dir,"emp.cert"),this.resource.key=v.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:`EMP\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return Ce(e,t)}importFileUrl(e){return Dt(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){if(this.empConfig.debug.showRsconfig)if(typeof this.empConfig.debug.showRsconfig=="string"){let e=v.join(this.root,this.empConfig.debug.showRsconfig);jt.writeFile(e,JSON.stringify(this.rsConfig,null,2))}else{let e={colors:!0,depth:null},t=typeof this.empConfig.debug.showRsconfig=="object"?f(e,this.empConfig.debug.showRsconfig):e;console.log(a.link("[Compile Config]")),console.log(Ft.inspect(this.rsConfig,t))}}get browserslistOptions(){return{default:["chrome >= 87","edge >= 88","firefox >= 78","safari >= 14"],h5:["iOS >= 9","Android >= 4.4","last 2 versions","> 0.2%","not dead"],node:["node >= 20"]}}},n=new pe});import{exec as Mt}from"node:child_process";import{promisify as Rt}from"node:util";var Qe,qe,At,Bt,Ye,Ze=l(()=>{"use strict";b();u();Qe=Rt(Mt),qe=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],At=async()=>{let r=process.env.BROWSER;if(!r||!qe.includes(r)){let{stdout:e}=await Qe("ps cax");r=qe.find(t=>e.includes(t))}return r},Bt=async r=>{if(process.platform==="darwin")try{let t=await At();if(t){let s=`osascript openChrome.applescript "${encodeURI(r)}" "${t}"`;return await Qe(s,{cwd:n.resource.dir}),!0}}catch(t){a.debug(t)}try{let{default:t}=await import("open");return await t(r),!0}catch(t){return a.error("Failed to open start URL."),a.error(t),!1}},Ye=Bt});import zt from"net";import Gt from"os";async function et(r,e="localhost"){if(r!==It&&(r<Ke||r>ae))throw new Error(`Port number must lie between ${Ke} and ${ae}`);let t=r,s=Ht(),i;e&&!s.has(e)?i=new Set([e]):i=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=ae;)try{return await Nt(t,i)}catch(p){if(!o.has(p.code))throw p;t+=1}throw new Error("No available ports found")}var Ke,ae,It,Ht,Ut,Nt,tt=l(()=>{"use strict";Ke=1024,ae=65535,It=443,Ht=()=>{let r=Gt.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(r))if(t)for(let s of t)e.add(s.address);return e},Ut=(r,e)=>new Promise((t,s)=>{let i=zt.createServer();i.unref(),i.on("error",s),i.listen(r,e,()=>{let{port:o}=i.address();i.close(()=>{t(o)})})}),Nt=async(r,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ut(r,s)}catch(i){if(!t.has(i.code))throw i}return r}});import st from"node:fs/promises";import z from"chalk";var C,G=l(()=>{"use strict";b();u();y();re();Ze();tt();oe();C=class{sf={protocol:"http",host:"0.0.0.0",port:8e3,publicPath:"",publicHasHttp:!1,isOpenBrower:!1,url:"",urls:{localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""}};async adaptServer(){this.sf.publicPath=n.rsConfig.output?.publicPath==="auto"?"/":n.rsConfig.output?.publicPath||"/",this.sf.isOpenBrower=!!n.empConfig.server.open,this.sf.protocol=this.isHttps?"https":"http",this.sf.host=n.empConfig.server.host?n.empConfig.server.host:this.sf.host,this.sf.port=n.empConfig.server.port,await this.serverPort(),E.setup(this.sf),this.sf.publicPath&&(this.sf.publicPath.indexOf("http://")>-1||this.sf.publicPath.indexOf("https://")>-1)?(this.sf.url=this.sf.publicPath,this.sf.publicHasHttp=!0,this.sf.urls.localUrlForTerminal=E.prettyPrintUrl("localhost")):(this.sf.urls=E.urls,this.sf.url=this.sf.urls.localUrlForBrowser)}startOpen(){let{urls:e}=this.sf;this.sf.publicHasHttp?(a.info(`${z.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${z.greenBright("\u279C")} Network: ${a.link(this.sf.publicPath)}`)):(a.info(`${z.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${z.greenBright("\u279C")} Network: ${a.link(e.lanUrlForTerminal)}
|
|
11
|
+
`)),this.sf.isOpenBrower&&Ye(this.sf.url)}async setup(e,t){await n.setup(e,t),n.empConfig.debug.clearLog&&Pe(),a.title(`${e}`),await this.adaptServer(),await this.run(),this.afterRun()}async run(){}afterRun(){process.on("SIGINT",function(){process.exit()})}get isHttps(){let{server:e,https:t}=n.empConfig.server||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([st.readFile(n.resource.key),st.readFile(n.resource.cert)])}async serverPort(){if(A.isADB)return;let{port:e,host:t}=this.sf,s=await et(e,t);s!==e&&(this.sf.port=s,n.rsConfig.devServer?.port&&(n.rsConfig.devServer.port=s))}}});import d from"chalk";import w from"node:path";import{gzipSizeSync as Jt}from"gzip-size";import _t from"node:fs";function Zt(r,e){let t=[r,e],s=["File","Size","Gzipped"].reduce((i,o,p)=>{let m=t[p],g=o;return m&&(g=o.length<m?o+" ".repeat(m-o.length):o),`${i+g} `}," ");console.log(d.bold.blue(s))}async function rt(r){let e=r.toJson({all:!1,assets:!0,timings:!0});$(e.time);let s=e.assets.filter(c=>qt(c.name)).map(Yt);s.sort((c,P)=>c.size-P.size);let i=Math.max(...s.map(c=>c.sizeLabel.length)),o=Math.max(...s.map(c=>(c.folder+w.sep+c.name).length));Zt(o,i);let p=0,m=0;s.forEach(c=>{let{sizeLabel:P}=c,{name:ft,folder:ut,gzipSizeLabel:gt}=c,ge=(ut+w.sep+ft).length,de=P.length;if(p+=c.size,m+=c.gzippedSize,de<i){let N=" ".repeat(i-de);P+=N}let ye=d.gray(c.folder+w.sep)+Kt(c.name);if(ge<o){let N=" ".repeat(o-ge);ye+=N}a.info(` ${ye} ${d.gray(P)} ${gt}`)});let g=`${d.bold.blue("Total size:")} ${I(p)}`,O=`${d.bold.blue("Gzipped size:")} ${I(m)}`;a.info(`
|
|
12
|
+
${g}
|
|
13
|
+
${O}
|
|
14
|
+
`)}function $(r=0){a.info(`${d.greenBright("\u2713")} Ready in ${ke(Number(r))}`)}var Vt,Wt,Xt,qt,Qt,Yt,I,Kt,H=l(()=>{"use strict";u();b();y();Vt=/\.html$/,Wt=/\.(?:js|mjs|cjs|jsx)$/,Xt=/\.css$/,qt=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),Qt=r=>r>300*1e3?d.red:r>100*1e3?d.yellow:d.white,Yt=r=>{let e=r.name.split("?")[0],t=I(r.size),s=w.basename(e),i=w.join(w.basename(n.empConfig.build.outDir),w.dirname(e)),o=_t.readFileSync(w.join(n.empConfig.build.outDir,e)),p=o.length,m=Jt(o),g=Qt(m)(I(m));return{size:p,folder:i,name:s,gzippedSize:m,sizeLabel:t,gzipSizeLabel:g}};I=r=>{let e=r/1e3;return`${e.toFixed(e<1?2:1)} kB`},Kt=r=>Wt.test(r)?d.yellowBright(r):Xt.test(r)?d.greenBright(r):Vt.test(r)?d.blueBright(r):d.magenta(r)});var it={};J(it,{default:()=>ss});import{rspack as es}from"@rspack/core";import{RspackDevServer as ts}from"@rspack/dev-server";var le,ss,ot=l(()=>{"use strict";u();G();b();y();H();le=class extends C{get rspackDevConfig(){return f(n.rsConfig,{stats:{all:!1,colors:!0,assets:!1,chunks:!1,entrypoints:!1,timings:!1,version:!1,errors:!0,warnings:!0},devServer:{open:!1,setupExitSignals:!0}})}async devServerConfig(){let e=Object.assign({},n.rsConfig.devServer);if(this.isHttps&&(e.https===!0&&delete e.https,!e.server)){let[t,s]=await this.getcert();e.server={type:"https",options:{key:t,cert:s}}}return e}async run(){let e=es(this.rspackDevConfig);if(!n.rsConfig.devServer){a.error("devServer is not defined in config");return}let t=await this.devServerConfig(),s=new ts(t,e);this.startOpen(),n.empConfig.lifeCycle.beforeDevServe&&await n.empConfig.lifeCycle.beforeDevServe(),await s.start();let i=o=>{let p=o?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});$(p.time)};n.empConfig.debug.showPerformance&&e.hooks.afterDone.tap("done",i),s.middleware?.waitUntilValid(o=>{n.empConfig.debug.showPerformance||i(o),n.empConfig.lifeCycle.afterDevServe&&n.empConfig.lifeCycle.afterDevServe()})}},ss=new le});var nt={};J(nt,{default:()=>is});import{rspack as rs}from"@rspack/core";var ce,is,pt=l(()=>{"use strict";b();u();G();H();ce=class extends C{async run(){n.empConfig.lifeCycle.beforeBuild&&await n.empConfig.lifeCycle.beforeBuild(),rs(n.rsConfig,async(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}t.hasErrors()&&(a.error(t.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(t.toString({colors:!0,children:!0}))),await rt(t),n.empConfig.lifeCycle.afterBulid&&await n.empConfig.lifeCycle.afterBulid()})}},is=new ce});import os from"express";import ns from"cors";import ps from"compression";import as from"https";var U,at=l(()=>{"use strict";G();U=class extends C{app;async init(){let e=os();e.use(ps()),e.use(ns()),this.app=e}async server(){if(this.isHttps){let[e,t]=await this.getcert();as.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:e,cert:t},this.app).listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}else this.app.listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}async onReady(){}async middleware(){}async start(){await this.init(),await this.middleware(),await this.server()}}});var lt={};J(lt,{default:()=>fs});import ls from"express";import cs from"path";import ms from"node:fs/promises";import hs from"node:fs";var me,fs,ct=l(()=>{"use strict";at();u();b();H();me=class extends U{timing=0;async run(){if(this.timing=Date.now(),!hs.existsSync(n.outDir))return a.sysError(`emp serve must be executed after emp build,${n.outDir} not exist!`);n.empConfig.lifeCycle.beforeServe&&await n.empConfig.lifeCycle.beforeServe(),this.start()}async middleware(){let e=n.resolve(n.rsConfig.output?.path);this.app.use(ls.static(e));let t=await ms.readFile(cs.join(e,"index.html"),"utf8");this.app.get("*",(s,i)=>i.send(t))}async onReady(){$(Date.now()-this.timing),n.empConfig.lifeCycle.afterServe&&await n.empConfig.lifeCycle.afterServe()}},fs=new me});u();u();y();b();import{program as S}from"commander";import he,{exit as us}from"node:process";function mt(){let r="20.0.0";L(r,he.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${he.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${r}`),us(0)),S.version(n.empPkg.version,"-v, --version").usage("<command> [options]"),S.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(ot(),it));await t.setup("dev",e)}),S.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(pt(),nt));await t.setup("build",e)}),S.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(ct(),lt));await t.setup("serve",e)}),S.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),S.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),S.parse(he.argv)}u();import gs from"fast-glob";import ht from"node:fs/promises";import fe from"node:path";var ds=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ys=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,bs=/import\(['"]([^;\n]+?)['"]\)/,ue=class{list=[];outDir=n.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await gs([`${n.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=n.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await ht.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ds,i=>{let o=i.match(ys);if(o||(o=i.match(bs)),o&&o[1]){let p=o[1];if(!p.startsWith("."))return i;let m=fe.resolve(fe.dirname(e),p).replace(this.outDir,this.aliasName);return i.replace(o[1],m)}return i});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
|
|
15
|
+
${t}}\r
|
|
16
|
+
`}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await ht.writeFile(fe.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},vs=new ue;function Zi(r){return r}export{Zi as defineConfig,vs as dts,mt as runScript,n as store};
|