@yannick-z/modulo 0.3.2 → 0.3.3
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/131.js +108 -0
- package/dist/54.js +340 -0
- package/dist/839.js +437 -0
- package/dist/938.js +289 -0
- package/dist/bin/modulo.js +3 -81
- package/dist/index.js +1 -200
- package/package.json +1 -1
- package/src/packer/lib.ts +4 -3
- package/dist/183.js +0 -130
- package/dist/740.js +0 -793
- package/dist/882.js +0 -697
package/dist/740.js
DELETED
|
@@ -1,793 +0,0 @@
|
|
|
1
|
-
import { pluginLess } from "@rsbuild/plugin-less";
|
|
2
|
-
import { build, defineConfig } from "@rslib/core";
|
|
3
|
-
import { pluginReact } from "@rsbuild/plugin-react";
|
|
4
|
-
import { pluginVue2 } from "@rsbuild/plugin-vue2";
|
|
5
|
-
import semver from "semver";
|
|
6
|
-
import { createRsbuild, defineConfig as core_defineConfig } from "@rsbuild/core";
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
9
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
10
|
-
export const __webpack_id__ = "740";
|
|
11
|
-
export const __webpack_ids__ = [
|
|
12
|
-
"740"
|
|
13
|
-
];
|
|
14
|
-
export const __webpack_modules__ = {
|
|
15
|
-
"./src/cli/pack-code.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
16
|
-
__webpack_require__.r(__webpack_exports__);
|
|
17
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
18
|
-
pack_code: ()=>pack_code
|
|
19
|
-
});
|
|
20
|
-
var external_picocolors_ = __webpack_require__("picocolors");
|
|
21
|
-
var src_config = __webpack_require__("./src/config/index.ts");
|
|
22
|
-
var panic = __webpack_require__("./src/tools/panic.ts");
|
|
23
|
-
function get_framework_name() {
|
|
24
|
-
const { dependencies } = (0, src_config.mJ)();
|
|
25
|
-
(0, panic.a)(!("vue" in dependencies || "react" in dependencies), "package.json中未识别到支持的ui库信息, 当前只支持vue和react");
|
|
26
|
-
return "vue" in dependencies ? "vue" : "react";
|
|
27
|
-
}
|
|
28
|
-
function framework_plugin(global_config, options) {
|
|
29
|
-
const { dependencies } = (0, src_config.mJ)();
|
|
30
|
-
const framework_name = get_framework_name();
|
|
31
|
-
const version = dependencies[framework_name];
|
|
32
|
-
const allowed_versions = [
|
|
33
|
-
global_config.ui_lib.vue2,
|
|
34
|
-
global_config.ui_lib.react19
|
|
35
|
-
];
|
|
36
|
-
const is_valid = allowed_versions.some((allowed)=>{
|
|
37
|
-
const min_version = semver.minVersion(version);
|
|
38
|
-
return min_version && semver.satisfies(min_version, `^${allowed}`);
|
|
39
|
-
});
|
|
40
|
-
(0, panic.a)(!is_valid, `package.json中只允许使用固定版本号, 并且只支持vue-2.7.16, react-19.2.4 (当前版本: ${version})`);
|
|
41
|
-
return "vue" === framework_name ? pluginVue2(options) : pluginReact(options);
|
|
42
|
-
}
|
|
43
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
44
|
-
var log = __webpack_require__("./src/tools/log.ts");
|
|
45
|
-
var file = __webpack_require__("./src/tools/file.ts");
|
|
46
|
-
function collect_modules(args, kind, global_config) {
|
|
47
|
-
const framework_name = get_framework_name();
|
|
48
|
-
const module_path = global_config.input[`${kind}s`];
|
|
49
|
-
const isExist = (0, file.t2)(module_path);
|
|
50
|
-
(0, log.n)(external_picocolors_["default"].blue("check module_path"), module_path, isExist ? "exists" : "NOT exists");
|
|
51
|
-
if (!isExist) return;
|
|
52
|
-
const baseCandidates = [
|
|
53
|
-
"index",
|
|
54
|
-
"main"
|
|
55
|
-
];
|
|
56
|
-
const extensions = [
|
|
57
|
-
".ts",
|
|
58
|
-
".tsx",
|
|
59
|
-
".js",
|
|
60
|
-
".jsx"
|
|
61
|
-
];
|
|
62
|
-
if ("vue" === framework_name) extensions.unshift(".vue");
|
|
63
|
-
const module_entries = (0, file.xh)(module_path).map((dirName)=>{
|
|
64
|
-
const dir_path = (0, external_node_path_.resolve)(module_path, dirName);
|
|
65
|
-
const candidates = [
|
|
66
|
-
...baseCandidates,
|
|
67
|
-
dirName
|
|
68
|
-
];
|
|
69
|
-
const entry_file_path = (0, file.Ke)(dir_path, candidates, extensions);
|
|
70
|
-
(0, log.n)("found entry", dirName, entry_file_path || "NOT FOUND");
|
|
71
|
-
return [
|
|
72
|
-
dirName,
|
|
73
|
-
entry_file_path
|
|
74
|
-
];
|
|
75
|
-
}).filter((entry)=>!!entry[1]);
|
|
76
|
-
return module_entries.length > 0 ? Object.fromEntries(module_entries) : void 0;
|
|
77
|
-
}
|
|
78
|
-
function omit_root_path(path) {
|
|
79
|
-
const rel = (0, external_node_path_.relative)(process.cwd(), path);
|
|
80
|
-
return rel.startsWith("/") ? rel : `/${rel}`;
|
|
81
|
-
}
|
|
82
|
-
function omit_root_path_for_entries(entries) {
|
|
83
|
-
return Object.fromEntries(Object.entries(entries).map(([key, value])=>[
|
|
84
|
-
key,
|
|
85
|
-
omit_root_path(value)
|
|
86
|
-
]));
|
|
87
|
-
}
|
|
88
|
-
function is_string(data) {
|
|
89
|
-
return "string" == typeof data;
|
|
90
|
-
}
|
|
91
|
-
function is_record(data) {
|
|
92
|
-
return !!data && "object" == typeof data;
|
|
93
|
-
}
|
|
94
|
-
function is_env_external(data) {
|
|
95
|
-
return is_record(data) && is_string(data.dev) && is_string(data.prd);
|
|
96
|
-
}
|
|
97
|
-
function getExternalUrl(args, url) {
|
|
98
|
-
let resolvedUrl = url;
|
|
99
|
-
while(!is_string(resolvedUrl))if (!is_env_external(resolvedUrl)) return;
|
|
100
|
-
else resolvedUrl = resolvedUrl[args.pack.env];
|
|
101
|
-
return resolvedUrl;
|
|
102
|
-
}
|
|
103
|
-
function getExternalsAndImportMap(args, externalLibs, externalsType = "importmap") {
|
|
104
|
-
return Object.entries(externalLibs).reduce(({ externals, importMap }, [libName, data])=>{
|
|
105
|
-
let externalLib;
|
|
106
|
-
externalLib = is_string(data) ? {
|
|
107
|
-
url: data
|
|
108
|
-
} : is_env_external(data) ? {
|
|
109
|
-
url: data
|
|
110
|
-
} : data;
|
|
111
|
-
const url = getExternalUrl(args, externalLib.url);
|
|
112
|
-
if ("script" === externalsType) {
|
|
113
|
-
const globalVar = externalLib.global || libName;
|
|
114
|
-
const importName = externalLib.importName || libName;
|
|
115
|
-
(Array.isArray(importName) ? importName : [
|
|
116
|
-
importName
|
|
117
|
-
]).forEach((name)=>{
|
|
118
|
-
externals[name] = globalVar;
|
|
119
|
-
});
|
|
120
|
-
if (url) importMap[libName] = url;
|
|
121
|
-
} else {
|
|
122
|
-
const importName = externalLib.importName || libName;
|
|
123
|
-
(Array.isArray(importName) ? importName : [
|
|
124
|
-
importName
|
|
125
|
-
]).forEach((name)=>{
|
|
126
|
-
externals[name] = libName;
|
|
127
|
-
});
|
|
128
|
-
if (url) importMap[libName] = url;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
externals,
|
|
132
|
-
importMap
|
|
133
|
-
};
|
|
134
|
-
}, {
|
|
135
|
-
externals: {},
|
|
136
|
-
importMap: {}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
let printed = false;
|
|
140
|
-
function prepare_config(args, kind, config) {
|
|
141
|
-
console.log(external_picocolors_["default"].blueBright(`\n**** 开始构建 【${kind}】 ****`));
|
|
142
|
-
const entries = collect_modules(args, kind, config);
|
|
143
|
-
if (entries) console.log(`${external_picocolors_["default"].blue(`\n${kind} entries:`)}\n${JSON.stringify(omit_root_path_for_entries(entries), null, 2)}\n`);
|
|
144
|
-
else console.log(external_picocolors_["default"].red(`\n没有要构建的${kind},跳过\n`));
|
|
145
|
-
const { externals, importMap } = getExternalsAndImportMap(args, config.externals, config.externalsType);
|
|
146
|
-
printed || console.log(`${external_picocolors_["default"].blue("\nexternals:")}\n${JSON.stringify(externals, null, 2)}\n`);
|
|
147
|
-
let importMapsTag;
|
|
148
|
-
importMapsTag = "script" === config.externalsType ? Object.values(importMap).map((url)=>({
|
|
149
|
-
tag: "script",
|
|
150
|
-
attrs: {
|
|
151
|
-
src: url
|
|
152
|
-
},
|
|
153
|
-
append: false,
|
|
154
|
-
head: true
|
|
155
|
-
})) : [
|
|
156
|
-
{
|
|
157
|
-
append: false,
|
|
158
|
-
head: true,
|
|
159
|
-
tag: "script",
|
|
160
|
-
attrs: {
|
|
161
|
-
type: "importmap"
|
|
162
|
-
},
|
|
163
|
-
children: `{
|
|
164
|
-
"imports": ${JSON.stringify(importMap, null, 2)}
|
|
165
|
-
}`
|
|
166
|
-
}
|
|
167
|
-
];
|
|
168
|
-
printed || console.log(`${external_picocolors_["default"].blue("\nimportmaps/scripts:")}\n${JSON.stringify(importMap, null, 2)}\n`);
|
|
169
|
-
printed = true;
|
|
170
|
-
return {
|
|
171
|
-
entries,
|
|
172
|
-
externals,
|
|
173
|
-
importMapsTag
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
async function lib_pack(args) {
|
|
177
|
-
const config = await (0, src_config.eP)(args);
|
|
178
|
-
const packagejson = (0, src_config.mJ)();
|
|
179
|
-
const { entries, externals } = prepare_config(args, "module", config);
|
|
180
|
-
if (!entries) return;
|
|
181
|
-
const rslibConfig = defineConfig({
|
|
182
|
-
source: {
|
|
183
|
-
define: config.define,
|
|
184
|
-
entry: entries
|
|
185
|
-
},
|
|
186
|
-
plugins: [
|
|
187
|
-
framework_plugin(config),
|
|
188
|
-
pluginLess()
|
|
189
|
-
],
|
|
190
|
-
resolve: {
|
|
191
|
-
alias: config.alias
|
|
192
|
-
},
|
|
193
|
-
lib: [
|
|
194
|
-
{
|
|
195
|
-
format: "esm",
|
|
196
|
-
syntax: "esnext",
|
|
197
|
-
dts: false,
|
|
198
|
-
output: {
|
|
199
|
-
assetPrefix: `${config.url.base}/modules`,
|
|
200
|
-
externals,
|
|
201
|
-
distPath: {
|
|
202
|
-
root: config.output.modules,
|
|
203
|
-
js: "esm",
|
|
204
|
-
jsAsync: "esm",
|
|
205
|
-
css: "esm"
|
|
206
|
-
},
|
|
207
|
-
minify: config.minify
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
format: "umd",
|
|
212
|
-
output: {
|
|
213
|
-
assetPrefix: `${config.url.base}/modules`,
|
|
214
|
-
externals,
|
|
215
|
-
distPath: {
|
|
216
|
-
root: config.output.modules,
|
|
217
|
-
js: "umd",
|
|
218
|
-
jsAsync: "umd",
|
|
219
|
-
css: "umd"
|
|
220
|
-
},
|
|
221
|
-
minify: config.minify
|
|
222
|
-
},
|
|
223
|
-
syntax: "es6",
|
|
224
|
-
umdName: `${packagejson.name}-modules-[name]`
|
|
225
|
-
}
|
|
226
|
-
],
|
|
227
|
-
output: {
|
|
228
|
-
legalComments: "none",
|
|
229
|
-
target: "web"
|
|
230
|
-
},
|
|
231
|
-
performance: {
|
|
232
|
-
bundleAnalyze: config.analyze ? {
|
|
233
|
-
analyzerMode: "disabled",
|
|
234
|
-
generateStatsFile: true
|
|
235
|
-
} : void 0,
|
|
236
|
-
chunkSplit: {
|
|
237
|
-
strategy: "all-in-one"
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
await build(rslibConfig, {
|
|
242
|
-
watch: "build" === args.cmd && !!args.pack.watch,
|
|
243
|
-
root: process.cwd()
|
|
244
|
-
});
|
|
245
|
-
if ("build" === args.cmd) console.log(external_picocolors_["default"].green("\n**** 构建【module】完成 ****\n"));
|
|
246
|
-
}
|
|
247
|
-
var external_node_fs_ = __webpack_require__("node:fs");
|
|
248
|
-
var external_node_url_ = __webpack_require__("node:url");
|
|
249
|
-
let packageRoot = "";
|
|
250
|
-
function get_package_root() {
|
|
251
|
-
if (!packageRoot) {
|
|
252
|
-
const __filename = (0, external_node_url_.fileURLToPath)(import.meta.url);
|
|
253
|
-
const __dirname = (0, external_node_path_.dirname)(__filename);
|
|
254
|
-
let currentDir = external_node_path_["default"].resolve(__dirname);
|
|
255
|
-
const root = external_node_path_["default"].parse(currentDir).root;
|
|
256
|
-
while(currentDir !== root){
|
|
257
|
-
const potentialPkgJson = external_node_path_["default"].join(currentDir, "package.json");
|
|
258
|
-
if (external_node_fs_["default"].existsSync(potentialPkgJson)) break;
|
|
259
|
-
currentDir = external_node_path_["default"].dirname(currentDir);
|
|
260
|
-
}
|
|
261
|
-
(0, log.n)("packageRoot", currentDir);
|
|
262
|
-
packageRoot = currentDir;
|
|
263
|
-
}
|
|
264
|
-
return packageRoot;
|
|
265
|
-
}
|
|
266
|
-
function find_workspace_root(cwd) {
|
|
267
|
-
let currentDir = external_node_path_["default"].resolve(cwd);
|
|
268
|
-
const root = external_node_path_["default"].parse(currentDir).root;
|
|
269
|
-
while(currentDir !== root){
|
|
270
|
-
const pnpmWorkspace = external_node_path_["default"].join(currentDir, "pnpm-workspace.yaml");
|
|
271
|
-
const packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
272
|
-
if (external_node_fs_["default"].existsSync(pnpmWorkspace)) return currentDir;
|
|
273
|
-
if (external_node_fs_["default"].existsSync(packageJsonPath)) try {
|
|
274
|
-
const pkg = JSON.parse(external_node_fs_["default"].readFileSync(packageJsonPath, "utf-8"));
|
|
275
|
-
if (pkg.workspaces) return currentDir;
|
|
276
|
-
} catch {}
|
|
277
|
-
currentDir = external_node_path_["default"].dirname(currentDir);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const auto_external_plugin_require = createRequire(import.meta.url);
|
|
281
|
-
class AutoExternalPlugin {
|
|
282
|
-
externalLibNames;
|
|
283
|
-
usedExternals;
|
|
284
|
-
args;
|
|
285
|
-
config;
|
|
286
|
-
constructor(args, config){
|
|
287
|
-
this.args = args;
|
|
288
|
-
this.config = config;
|
|
289
|
-
this.externalLibNames = Object.keys(config.externals);
|
|
290
|
-
this.usedExternals = new Set();
|
|
291
|
-
}
|
|
292
|
-
apply(compiler) {
|
|
293
|
-
compiler.hooks.compilation.tap("AutoExternalPlugin", (compilation)=>{
|
|
294
|
-
compilation.hooks.finishModules.tap("AutoExternalPlugin", (modules)=>{
|
|
295
|
-
for (const module of modules){
|
|
296
|
-
const constructorName = module.constructor.name;
|
|
297
|
-
const request = module.request;
|
|
298
|
-
const userRequest = module.userRequest;
|
|
299
|
-
const resource = module.resource;
|
|
300
|
-
const externalType = module.externalType;
|
|
301
|
-
if ('ExternalModule' === constructorName || externalType) {
|
|
302
|
-
const libName = request || userRequest;
|
|
303
|
-
if (libName && this.externalLibNames.includes(libName)) {
|
|
304
|
-
this.usedExternals.add(libName);
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (resource && resource.includes("node_modules")) {
|
|
309
|
-
for (const libName of this.externalLibNames)if (resource.includes(`/node_modules/${libName}/`) || resource.includes(`\\node_modules\\${libName}\\`)) this.usedExternals.add(libName);
|
|
310
|
-
} else if (resource && resource.includes("/node_modules/.pnpm/")) {
|
|
311
|
-
for (const libName of this.externalLibNames)if (resource.includes(`/node_modules/.pnpm/${libName}@`) || resource.includes(`/node_modules/.pnpm/${libName}+`) || resource.includes(`/node_modules/${libName}/`)) this.usedExternals.add(libName);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
compiler.hooks.emit.tapAsync("AutoExternalPlugin", (compilation, cb)=>{
|
|
316
|
-
if (process.env.DEBUG) console.log('[AutoExternalPlugin] emit hook triggered');
|
|
317
|
-
const assetNames = Object.keys(compilation.assets);
|
|
318
|
-
if (process.env.DEBUG) console.log('[AutoExternalPlugin] Assets:', assetNames);
|
|
319
|
-
cb();
|
|
320
|
-
});
|
|
321
|
-
let HtmlWebpackPlugin;
|
|
322
|
-
const htmlPluginInstance = compiler.options.plugins.find((p)=>p && ("HtmlWebpackPlugin" === p.constructor.name || "HtmlRspackPlugin" === p.constructor.name));
|
|
323
|
-
if (htmlPluginInstance) HtmlWebpackPlugin = htmlPluginInstance.constructor;
|
|
324
|
-
if (!HtmlWebpackPlugin) HtmlWebpackPlugin = compiler.webpack.HtmlRspackPlugin || compiler.webpack.HtmlWebpackPlugin;
|
|
325
|
-
if (!HtmlWebpackPlugin) try {
|
|
326
|
-
HtmlWebpackPlugin = auto_external_plugin_require('@rspack/plugin-html').HtmlRspackPlugin;
|
|
327
|
-
} catch (e) {}
|
|
328
|
-
if (!HtmlWebpackPlugin) return;
|
|
329
|
-
if ('function' != typeof HtmlWebpackPlugin.getHooks) return;
|
|
330
|
-
const hooks = HtmlWebpackPlugin.getHooks(compilation);
|
|
331
|
-
hooks.alterAssetTags.tapAsync("AutoExternalPlugin", (data, cb)=>{
|
|
332
|
-
if (data.assetTags && data.assetTags.scripts) this.processTags(data, "assetTags.scripts");
|
|
333
|
-
cb(null, data);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
processTags(data, targetProp) {
|
|
338
|
-
if (!this.config.autoExternal) return data;
|
|
339
|
-
const { importMap } = getExternalsAndImportMap(this.args, this.config.externals, this.config.externalsType);
|
|
340
|
-
const filteredImportMap = Object.fromEntries(Object.entries(importMap).filter(([key])=>this.usedExternals.has(key)));
|
|
341
|
-
if (0 === Object.keys(filteredImportMap).length) return data;
|
|
342
|
-
let tags = [];
|
|
343
|
-
tags = "script" === this.config.externalsType ? Object.values(filteredImportMap).map((url)=>({
|
|
344
|
-
tagName: "script",
|
|
345
|
-
voidTag: false,
|
|
346
|
-
attributes: {
|
|
347
|
-
src: url
|
|
348
|
-
}
|
|
349
|
-
})) : [
|
|
350
|
-
{
|
|
351
|
-
tagName: "script",
|
|
352
|
-
voidTag: false,
|
|
353
|
-
attributes: {
|
|
354
|
-
type: "importmap"
|
|
355
|
-
},
|
|
356
|
-
innerHTML: JSON.stringify({
|
|
357
|
-
imports: filteredImportMap
|
|
358
|
-
}, null, 2)
|
|
359
|
-
}
|
|
360
|
-
];
|
|
361
|
-
if ('headTags' === targetProp) data.headTags.unshift(...tags);
|
|
362
|
-
else if ("assetTags.scripts" === targetProp) data.assetTags.scripts.unshift(...tags);
|
|
363
|
-
else if ('head' === targetProp) data.head.unshift(...tags);
|
|
364
|
-
return data;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
async function page_pack(args) {
|
|
368
|
-
const config = await (0, src_config.eP)(args);
|
|
369
|
-
const { entries, externals } = prepare_config(args, "page", config);
|
|
370
|
-
if (!entries) return;
|
|
371
|
-
const workspaceRoot = find_workspace_root(process.cwd());
|
|
372
|
-
const rsbuildConfig = core_defineConfig({
|
|
373
|
-
source: {
|
|
374
|
-
define: config.define,
|
|
375
|
-
entry: entries
|
|
376
|
-
},
|
|
377
|
-
plugins: [
|
|
378
|
-
framework_plugin(config),
|
|
379
|
-
pluginLess()
|
|
380
|
-
],
|
|
381
|
-
tools: {
|
|
382
|
-
rspack: {
|
|
383
|
-
experiments: {
|
|
384
|
-
outputModule: "importmap" === config.externalsType ? true : void 0
|
|
385
|
-
},
|
|
386
|
-
plugins: [
|
|
387
|
-
new AutoExternalPlugin(args, config)
|
|
388
|
-
]
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
output: {
|
|
392
|
-
assetPrefix: config.url.cdn || config.url.base,
|
|
393
|
-
distPath: {
|
|
394
|
-
root: config.output.dist
|
|
395
|
-
},
|
|
396
|
-
externals,
|
|
397
|
-
filenameHash: config.output.filenameHash,
|
|
398
|
-
legalComments: "none",
|
|
399
|
-
minify: config.minify
|
|
400
|
-
},
|
|
401
|
-
html: {
|
|
402
|
-
meta: config.html.meta,
|
|
403
|
-
mountId: config.html.root,
|
|
404
|
-
scriptLoading: "importmap" === config.externalsType ? void 0 : "module",
|
|
405
|
-
tags: config.html.tags,
|
|
406
|
-
template: config.html.template || (0, external_node_path_.resolve)(get_package_root(), "template/index.html"),
|
|
407
|
-
templateParameters: {
|
|
408
|
-
base_prefix: config.url.base
|
|
409
|
-
},
|
|
410
|
-
title: config.html.title
|
|
411
|
-
},
|
|
412
|
-
resolve: {
|
|
413
|
-
alias: config.alias
|
|
414
|
-
},
|
|
415
|
-
server: {
|
|
416
|
-
publicDir: workspaceRoot ? {
|
|
417
|
-
name: workspaceRoot,
|
|
418
|
-
copyOnBuild: false,
|
|
419
|
-
watch: false
|
|
420
|
-
} : void 0,
|
|
421
|
-
open: config.dev_server.open ? config.dev_server.open.map((name)=>config.url.base + (name.endsWith("html") ? `/${name}` : `/${name}.html`)) : false,
|
|
422
|
-
port: config.dev_server.port,
|
|
423
|
-
proxy: config.dev_server.proxy
|
|
424
|
-
},
|
|
425
|
-
performance: {
|
|
426
|
-
chunkSplit: {
|
|
427
|
-
strategy: "split-by-experience"
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
console.log("Dev Server Config:", JSON.stringify(rsbuildConfig.server, null, 2));
|
|
432
|
-
const rsbuild = await createRsbuild({
|
|
433
|
-
rsbuildConfig
|
|
434
|
-
});
|
|
435
|
-
if ("dev" === args.cmd) await rsbuild.startDevServer();
|
|
436
|
-
else if ("preview" === args.cmd) await rsbuild.preview();
|
|
437
|
-
else await rsbuild.build({
|
|
438
|
-
watch: args.pack.watch
|
|
439
|
-
});
|
|
440
|
-
if ("build" === args.cmd) console.log(external_picocolors_["default"].green("\n**** 构建【page】完成 ****"));
|
|
441
|
-
}
|
|
442
|
-
async function pack_code(args) {
|
|
443
|
-
const { target } = args;
|
|
444
|
-
if ("preview" === args.cmd) return void await page_pack(args);
|
|
445
|
-
if ("all" === target && "dev" === args.cmd) return void await Promise.all([
|
|
446
|
-
page_pack(args),
|
|
447
|
-
lib_pack(args)
|
|
448
|
-
]);
|
|
449
|
-
if ("page" === target || "all" === target) await page_pack(args);
|
|
450
|
-
if ("module" === target || "all" === target) await lib_pack(args);
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
"./src/config/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
454
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
455
|
-
eP: ()=>get_global_config,
|
|
456
|
-
mJ: ()=>get_packagejson
|
|
457
|
-
});
|
|
458
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
459
|
-
var external_node_process_ = __webpack_require__("node:process");
|
|
460
|
-
var external_node_fs_ = __webpack_require__("node:fs");
|
|
461
|
-
var external_node_url_ = __webpack_require__("node:url");
|
|
462
|
-
var log = __webpack_require__("./src/tools/log.ts");
|
|
463
|
-
var file = __webpack_require__("./src/tools/file.ts");
|
|
464
|
-
var json = __webpack_require__("./src/tools/json.ts");
|
|
465
|
-
var panic = __webpack_require__("./src/tools/panic.ts");
|
|
466
|
-
function merge_user_config(target, input) {
|
|
467
|
-
for(const key in input){
|
|
468
|
-
const from = input[key];
|
|
469
|
-
const to = target[key];
|
|
470
|
-
if (typeof from === typeof to && key in target) if (Array.isArray(to)) {
|
|
471
|
-
(0, panic.a)(!Array.isArray(from));
|
|
472
|
-
target[key] = [
|
|
473
|
-
...to,
|
|
474
|
-
...from
|
|
475
|
-
];
|
|
476
|
-
} else if ("object" == typeof to) merge_user_config(to, from);
|
|
477
|
-
else target[key] = from;
|
|
478
|
-
else {
|
|
479
|
-
target[key] = from;
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
var presets = __webpack_require__("./src/config/presets.ts");
|
|
485
|
-
const root = (0, external_node_process_.cwd)();
|
|
486
|
-
let packagejson = null;
|
|
487
|
-
function get_packagejson(customRoot = root) {
|
|
488
|
-
if (packagejson) {
|
|
489
|
-
if (customRoot !== root) {
|
|
490
|
-
const newPackageJson = (0, json.a)((0, file.Cr)(customRoot, "package.json"));
|
|
491
|
-
(0, panic.a)(!newPackageJson, "根目录下没有package.json");
|
|
492
|
-
(0, panic.a)(!newPackageJson.name, "package.json缺少name字段");
|
|
493
|
-
return newPackageJson;
|
|
494
|
-
}
|
|
495
|
-
} else {
|
|
496
|
-
packagejson = (0, json.a)((0, file.Cr)(customRoot, "package.json"));
|
|
497
|
-
(0, panic.a)(!packagejson, "根目录下没有package.json");
|
|
498
|
-
(0, panic.a)(!packagejson.name, "package.json缺少name字段");
|
|
499
|
-
}
|
|
500
|
-
return packagejson;
|
|
501
|
-
}
|
|
502
|
-
let global_config;
|
|
503
|
-
async function get_global_config(args) {
|
|
504
|
-
if (!global_config) {
|
|
505
|
-
let configPath = args.pack.config;
|
|
506
|
-
if (!configPath) {
|
|
507
|
-
const candidates = [
|
|
508
|
-
"modulo.config.ts",
|
|
509
|
-
"modulo.config.js",
|
|
510
|
-
"modulo.config.json"
|
|
511
|
-
];
|
|
512
|
-
for (const f of candidates){
|
|
513
|
-
const p = (0, external_node_path_.resolve)(root, f);
|
|
514
|
-
if ((0, external_node_fs_.existsSync)(p)) {
|
|
515
|
-
configPath = p;
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
if (!configPath) throw new Error("根目录下没有配置文件 (modulo.config.ts/js/json)");
|
|
521
|
-
const resolvedConfigPath = (0, external_node_path_.resolve)(root, configPath);
|
|
522
|
-
let user_config;
|
|
523
|
-
try {
|
|
524
|
-
const fileUrl = (0, external_node_url_.pathToFileURL)(resolvedConfigPath).href;
|
|
525
|
-
const mod = await import(fileUrl);
|
|
526
|
-
user_config = mod.default || mod;
|
|
527
|
-
} catch (e) {
|
|
528
|
-
console.error(`无法加载配置文件: ${resolvedConfigPath}`);
|
|
529
|
-
throw e;
|
|
530
|
-
}
|
|
531
|
-
(0, panic.a)(!user_config, "根目录下没有配置文件");
|
|
532
|
-
(0, log.n)("input user config", user_config);
|
|
533
|
-
if (user_config.extends) {
|
|
534
|
-
const extend_config_path = (0, external_node_path_.resolve)(root, user_config.extends);
|
|
535
|
-
try {
|
|
536
|
-
const extend_fileUrl = (0, external_node_url_.pathToFileURL)(extend_config_path).href;
|
|
537
|
-
const extend_mod = await import(extend_fileUrl);
|
|
538
|
-
const extend_config = extend_mod.default || extend_mod;
|
|
539
|
-
(0, log.n)("extend config", extend_config);
|
|
540
|
-
merge_user_config(presets.pw, extend_config);
|
|
541
|
-
} catch (e) {
|
|
542
|
-
console.error(`无法加载继承的配置文件: ${extend_config_path}`);
|
|
543
|
-
throw e;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
merge_user_config(presets.pw, user_config);
|
|
547
|
-
const _config = presets.pw;
|
|
548
|
-
const src = (0, external_node_path_.resolve)(root, _config.input.src);
|
|
549
|
-
const input = {
|
|
550
|
-
modules: (0, external_node_path_.resolve)(src, _config.input.modules),
|
|
551
|
-
pages: (0, external_node_path_.resolve)(src, _config.input.pages),
|
|
552
|
-
src: src
|
|
553
|
-
};
|
|
554
|
-
const dist = (0, external_node_path_.resolve)(root, _config.output.dist);
|
|
555
|
-
const output = {
|
|
556
|
-
..._config.output,
|
|
557
|
-
dist: dist,
|
|
558
|
-
modules: (0, external_node_path_.resolve)(dist, _config.output.modules),
|
|
559
|
-
pages: (0, external_node_path_.resolve)(dist, _config.output.pages)
|
|
560
|
-
};
|
|
561
|
-
const html = _config.html?.template ? {
|
|
562
|
-
..._config.html,
|
|
563
|
-
template: (0, external_node_path_.resolve)(root, _config.html.template)
|
|
564
|
-
} : _config.html;
|
|
565
|
-
const define = Object.fromEntries(Object.entries({
|
|
566
|
-
..._config.define,
|
|
567
|
-
"import.meta.env.MOUNT_ID": _config.html.root
|
|
568
|
-
}).map(([k, v])=>[
|
|
569
|
-
k,
|
|
570
|
-
JSON.stringify(v)
|
|
571
|
-
]));
|
|
572
|
-
(0, log.n)("当前模式", process.env.NODE_ENV);
|
|
573
|
-
const minify = true === _config.minify ? presets.Cw : _config.minify;
|
|
574
|
-
const alias = Object.fromEntries(Object.entries(_config.alias).map(([k, v])=>[
|
|
575
|
-
k,
|
|
576
|
-
v.replace("{input.src}", input.src)
|
|
577
|
-
]));
|
|
578
|
-
global_config = {
|
|
579
|
-
..._config,
|
|
580
|
-
define,
|
|
581
|
-
html,
|
|
582
|
-
input,
|
|
583
|
-
minify,
|
|
584
|
-
output,
|
|
585
|
-
alias
|
|
586
|
-
};
|
|
587
|
-
(0, log.n)("global config", global_config);
|
|
588
|
-
}
|
|
589
|
-
return global_config;
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
"./src/config/presets.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
593
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
594
|
-
Cw: ()=>preset_minify_config,
|
|
595
|
-
pw: ()=>preset_config,
|
|
596
|
-
rH: ()=>preset_alias
|
|
597
|
-
});
|
|
598
|
-
const preset_alias = {
|
|
599
|
-
"@": "{input.src}"
|
|
600
|
-
};
|
|
601
|
-
const preset_dev_server_config = {
|
|
602
|
-
open: false,
|
|
603
|
-
port: 8080,
|
|
604
|
-
proxy: {}
|
|
605
|
-
};
|
|
606
|
-
const preset_input_dirs = {
|
|
607
|
-
src: "src",
|
|
608
|
-
pages: "pages",
|
|
609
|
-
modules: "modules"
|
|
610
|
-
};
|
|
611
|
-
const preset_output_dirs = {
|
|
612
|
-
dist: "dist",
|
|
613
|
-
pages: "",
|
|
614
|
-
modules: "modules",
|
|
615
|
-
filenameHash: true
|
|
616
|
-
};
|
|
617
|
-
const default_html_config = {
|
|
618
|
-
meta: {},
|
|
619
|
-
root: "",
|
|
620
|
-
tags: [],
|
|
621
|
-
template: "",
|
|
622
|
-
title: ""
|
|
623
|
-
};
|
|
624
|
-
const preset_ui_libs = {
|
|
625
|
-
react19: "19.2.4",
|
|
626
|
-
vue2: "2.7.16"
|
|
627
|
-
};
|
|
628
|
-
const preset_minify_config = {
|
|
629
|
-
js: true,
|
|
630
|
-
jsOptions: {
|
|
631
|
-
minimizerOptions: {
|
|
632
|
-
compress: {
|
|
633
|
-
dead_code: true,
|
|
634
|
-
defaults: false,
|
|
635
|
-
toplevel: true,
|
|
636
|
-
unused: true
|
|
637
|
-
},
|
|
638
|
-
format: {
|
|
639
|
-
comments: "some",
|
|
640
|
-
ecma: 2015,
|
|
641
|
-
preserve_annotations: true,
|
|
642
|
-
safari10: true,
|
|
643
|
-
semicolons: false
|
|
644
|
-
},
|
|
645
|
-
mangle: true,
|
|
646
|
-
minify: true
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
const preset_url_config = {
|
|
651
|
-
base: "/",
|
|
652
|
-
cdn: ""
|
|
653
|
-
};
|
|
654
|
-
const preset_config = {
|
|
655
|
-
analyze: false,
|
|
656
|
-
define: {},
|
|
657
|
-
dev_server: preset_dev_server_config,
|
|
658
|
-
externals: {},
|
|
659
|
-
html: default_html_config,
|
|
660
|
-
input: preset_input_dirs,
|
|
661
|
-
minify: preset_minify_config,
|
|
662
|
-
output: preset_output_dirs,
|
|
663
|
-
ui_lib: preset_ui_libs,
|
|
664
|
-
url: preset_url_config,
|
|
665
|
-
alias: preset_alias,
|
|
666
|
-
webhost: true,
|
|
667
|
-
autoExternal: true,
|
|
668
|
-
externalsType: "importmap"
|
|
669
|
-
};
|
|
670
|
-
},
|
|
671
|
-
"./src/tools/file.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
672
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
673
|
-
Cr: ()=>resolve_and_read,
|
|
674
|
-
Ke: ()=>find_entry_file,
|
|
675
|
-
t2: ()=>exists,
|
|
676
|
-
xh: ()=>get_directories
|
|
677
|
-
});
|
|
678
|
-
var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
|
|
679
|
-
var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:path");
|
|
680
|
-
var picocolors__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("picocolors");
|
|
681
|
-
var _log_ts__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/tools/log.ts");
|
|
682
|
-
function read_file(path, error_msg, throwError = false) {
|
|
683
|
-
try {
|
|
684
|
-
return (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync)(path, "utf8");
|
|
685
|
-
} catch (error) {
|
|
686
|
-
const msg = error_msg || `文件无法访问或者不存在: ${path}`;
|
|
687
|
-
(0, _log_ts__WEBPACK_IMPORTED_MODULE_3__.n)("read_file error", msg, error);
|
|
688
|
-
if (throwError) throw new Error(msg);
|
|
689
|
-
console.log(picocolors__WEBPACK_IMPORTED_MODULE_2__["default"].red(msg));
|
|
690
|
-
return "";
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
function resolve_and_read(root, name) {
|
|
694
|
-
const fullpath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.resolve)(root, name);
|
|
695
|
-
(0, _log_ts__WEBPACK_IMPORTED_MODULE_3__.n)(`resolve file: ${name}`, "result is:", fullpath);
|
|
696
|
-
return read_file(fullpath);
|
|
697
|
-
}
|
|
698
|
-
function get_directories(path) {
|
|
699
|
-
try {
|
|
700
|
-
if (!(0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(path)) return [];
|
|
701
|
-
return (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.readdirSync)(path).filter((file)=>{
|
|
702
|
-
const fullPath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.join)(path, file);
|
|
703
|
-
return (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.statSync)(fullPath).isDirectory();
|
|
704
|
-
});
|
|
705
|
-
} catch (error) {
|
|
706
|
-
(0, _log_ts__WEBPACK_IMPORTED_MODULE_3__.n)("get_directories error", path, error);
|
|
707
|
-
return [];
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
function find_entry_file(dir, candidates, extensions = [
|
|
711
|
-
".ts",
|
|
712
|
-
".tsx",
|
|
713
|
-
".js",
|
|
714
|
-
".jsx",
|
|
715
|
-
".vue"
|
|
716
|
-
]) {
|
|
717
|
-
for (const name of candidates)for (const ext of extensions){
|
|
718
|
-
const filename = `${name}${ext}`;
|
|
719
|
-
const filepath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.join)(dir, filename);
|
|
720
|
-
if ((0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(filepath) && (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.statSync)(filepath).isFile()) return filepath;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function exists(path) {
|
|
724
|
-
const isExist = (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(path);
|
|
725
|
-
(0, _log_ts__WEBPACK_IMPORTED_MODULE_3__.n)(`check exists: ${path}`, isExist);
|
|
726
|
-
return isExist;
|
|
727
|
-
}
|
|
728
|
-
},
|
|
729
|
-
"./src/tools/json.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
730
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
731
|
-
Q: ()=>update_json_file,
|
|
732
|
-
a: ()=>jsonparse
|
|
733
|
-
});
|
|
734
|
-
var picocolors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("picocolors");
|
|
735
|
-
var node_fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:fs");
|
|
736
|
-
function jsonparse(input, defaultValue) {
|
|
737
|
-
try {
|
|
738
|
-
if (input) return JSON.parse(input);
|
|
739
|
-
return defaultValue;
|
|
740
|
-
} catch (e) {
|
|
741
|
-
console.error(picocolors__WEBPACK_IMPORTED_MODULE_0__["default"].red(`JSON.parse failed\n${e}`));
|
|
742
|
-
return defaultValue;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
function update_json_file(path, updater, createIfNotExist = false) {
|
|
746
|
-
try {
|
|
747
|
-
let data;
|
|
748
|
-
try {
|
|
749
|
-
const content = (0, node_fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync)(path, "utf-8");
|
|
750
|
-
const parsed = jsonparse(content);
|
|
751
|
-
if (parsed) data = parsed;
|
|
752
|
-
else if (createIfNotExist) data = {};
|
|
753
|
-
else {
|
|
754
|
-
console.error(picocolors__WEBPACK_IMPORTED_MODULE_0__["default"].red(`Failed to parse JSON file: ${path}`));
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
} catch (error) {
|
|
758
|
-
if ("ENOENT" === error.code && createIfNotExist) data = {};
|
|
759
|
-
else {
|
|
760
|
-
console.error(picocolors__WEBPACK_IMPORTED_MODULE_0__["default"].red(`Failed to read file: ${path}`));
|
|
761
|
-
return false;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
const newData = updater(data);
|
|
765
|
-
(0, node_fs__WEBPACK_IMPORTED_MODULE_1__.writeFileSync)(path, JSON.stringify(newData, null, 2) + "\n");
|
|
766
|
-
return true;
|
|
767
|
-
} catch (e) {
|
|
768
|
-
console.error(picocolors__WEBPACK_IMPORTED_MODULE_0__["default"].red(`Failed to update JSON file: ${path}\n${e}`));
|
|
769
|
-
return false;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
},
|
|
773
|
-
"./src/tools/panic.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
774
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
775
|
-
a: ()=>PANIC_IF
|
|
776
|
-
});
|
|
777
|
-
var node_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:process");
|
|
778
|
-
var picocolors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("picocolors");
|
|
779
|
-
const alert = "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !";
|
|
780
|
-
function PANIC_IF(status = false, msg = "SOMETHING'S WRONG", halt = true) {
|
|
781
|
-
if (status) {
|
|
782
|
-
console.log(picocolors__WEBPACK_IMPORTED_MODULE_1__["default"].bgRed(picocolors__WEBPACK_IMPORTED_MODULE_1__["default"].white(`\n${alert}\n\n${msg}\n\n${alert}`)), "\n");
|
|
783
|
-
halt && (0, node_process__WEBPACK_IMPORTED_MODULE_0__.exit)(1);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
"node:process": function(module) {
|
|
788
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
|
|
789
|
-
},
|
|
790
|
-
"node:url": function(module) {
|
|
791
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
|
|
792
|
-
}
|
|
793
|
-
};
|