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