@rspack/cli 1.2.7 → 1.3.0-beta.0
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/{197.js → 957.js} +1 -1
- package/dist/{197.mjs → 957.mjs} +3 -3
- package/dist/index.js +89 -49
- package/dist/index.mjs +94 -50
- package/dist/types.d.ts +1 -1
- package/dist/utils/loadConfig.d.ts +10 -1
- package/dist/utils/options.d.ts +7 -6
- package/package.json +6 -6
package/dist/{197.js → 957.js}
RENAMED
package/dist/{197.mjs → 957.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const
|
|
2
|
-
'
|
|
1
|
+
export const __webpack_ids__ = [
|
|
2
|
+
'957'
|
|
3
3
|
];
|
|
4
|
-
export const
|
|
4
|
+
export const __webpack_modules__ = {
|
|
5
5
|
"./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
6
6
|
__webpack_require__.d(__webpack_exports__, {
|
|
7
7
|
applyProfile: ()=>applyProfile
|
package/dist/index.js
CHANGED
|
@@ -46,12 +46,8 @@ function __webpack_require__(moduleId) {
|
|
|
46
46
|
}
|
|
47
47
|
__webpack_require__.m = __webpack_modules__;
|
|
48
48
|
(()=>{
|
|
49
|
-
__webpack_require__.n =
|
|
50
|
-
var getter = module && module.__esModule ?
|
|
51
|
-
return module['default'];
|
|
52
|
-
} : function() {
|
|
53
|
-
return module;
|
|
54
|
-
};
|
|
49
|
+
__webpack_require__.n = (module)=>{
|
|
50
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
55
51
|
__webpack_require__.d(getter, {
|
|
56
52
|
a: getter
|
|
57
53
|
});
|
|
@@ -59,7 +55,7 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
59
55
|
};
|
|
60
56
|
})();
|
|
61
57
|
(()=>{
|
|
62
|
-
__webpack_require__.d =
|
|
58
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
63
59
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
64
60
|
enumerable: true,
|
|
65
61
|
get: definition[key]
|
|
@@ -68,22 +64,16 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
68
64
|
})();
|
|
69
65
|
(()=>{
|
|
70
66
|
__webpack_require__.f = {};
|
|
71
|
-
__webpack_require__.e =
|
|
72
|
-
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
67
|
+
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
73
68
|
__webpack_require__.f[key](chunkId, promises);
|
|
74
69
|
return promises;
|
|
75
70
|
}, []));
|
|
76
|
-
};
|
|
77
71
|
})();
|
|
78
72
|
(()=>{
|
|
79
|
-
__webpack_require__.u =
|
|
80
|
-
return "" + chunkId + ".js";
|
|
81
|
-
};
|
|
73
|
+
__webpack_require__.u = (chunkId)=>"" + chunkId + ".js";
|
|
82
74
|
})();
|
|
83
75
|
(()=>{
|
|
84
|
-
__webpack_require__.o =
|
|
85
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
86
|
-
};
|
|
76
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
87
77
|
})();
|
|
88
78
|
(()=>{
|
|
89
79
|
__webpack_require__.r = function(exports1) {
|
|
@@ -99,13 +89,13 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
99
89
|
var installedChunks = {
|
|
100
90
|
980: 1
|
|
101
91
|
};
|
|
102
|
-
var installChunk =
|
|
92
|
+
var installChunk = (chunk)=>{
|
|
103
93
|
var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
|
|
104
94
|
for(var moduleId in moreModules)if (__webpack_require__.o(moreModules, moduleId)) __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
105
95
|
if (runtime) runtime(__webpack_require__);
|
|
106
96
|
for(var i = 0; i < chunkIds.length; i++)installedChunks[chunkIds[i]] = 1;
|
|
107
97
|
};
|
|
108
|
-
__webpack_require__.f.require =
|
|
98
|
+
__webpack_require__.f.require = (chunkId, promises)=>{
|
|
109
99
|
if (!installedChunks[chunkId]) installChunk(require("./" + __webpack_require__.u(chunkId)));
|
|
110
100
|
};
|
|
111
101
|
})();
|
|
@@ -113,9 +103,9 @@ var __webpack_exports__ = {};
|
|
|
113
103
|
(()=>{
|
|
114
104
|
__webpack_require__.r(__webpack_exports__);
|
|
115
105
|
__webpack_require__.d(__webpack_exports__, {
|
|
106
|
+
definePlugin: ()=>definePlugin,
|
|
116
107
|
RspackCLI: ()=>RspackCLI,
|
|
117
|
-
defineConfig: ()=>defineConfig
|
|
118
|
-
definePlugin: ()=>definePlugin
|
|
108
|
+
defineConfig: ()=>defineConfig
|
|
119
109
|
});
|
|
120
110
|
var external_node_path_ = __webpack_require__("node:path");
|
|
121
111
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
|
|
@@ -144,6 +134,10 @@ var __webpack_exports__ = {};
|
|
|
144
134
|
type: "string",
|
|
145
135
|
default: "register",
|
|
146
136
|
describe: "Specify the loader to load the config file, can be `native` or `register`."
|
|
137
|
+
},
|
|
138
|
+
nodeEnv: {
|
|
139
|
+
string: true,
|
|
140
|
+
describe: "sets `process.env.NODE_ENV` to be specified value"
|
|
147
141
|
}
|
|
148
142
|
});
|
|
149
143
|
const commonOptionsForBuildAndServe = (yargs)=>yargs.options({
|
|
@@ -173,10 +167,6 @@ var __webpack_exports__ = {};
|
|
|
173
167
|
string: true,
|
|
174
168
|
describe: "env passed to config function"
|
|
175
169
|
},
|
|
176
|
-
nodeEnv: {
|
|
177
|
-
string: true,
|
|
178
|
-
describe: "sets process.env.NODE_ENV to be specified value"
|
|
179
|
-
},
|
|
180
170
|
devtool: {
|
|
181
171
|
type: "boolean",
|
|
182
172
|
default: false,
|
|
@@ -222,6 +212,10 @@ var __webpack_exports__ = {};
|
|
|
222
212
|
options.env = options.env || {};
|
|
223
213
|
return options.env;
|
|
224
214
|
}
|
|
215
|
+
function setDefaultNodeEnv(options, defaultEnv) {
|
|
216
|
+
if (void 0 !== process.env.NODE_ENV) return;
|
|
217
|
+
process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
218
|
+
}
|
|
225
219
|
class BuildCommand {
|
|
226
220
|
async apply(cli) {
|
|
227
221
|
cli.program.command([
|
|
@@ -246,6 +240,7 @@ var __webpack_exports__ = {};
|
|
|
246
240
|
}
|
|
247
241
|
});
|
|
248
242
|
}, async (options)=>{
|
|
243
|
+
setDefaultNodeEnv(options, "production");
|
|
249
244
|
const env = ensureEnvObject(options);
|
|
250
245
|
if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
251
246
|
else {
|
|
@@ -336,6 +331,7 @@ var __webpack_exports__ = {};
|
|
|
336
331
|
"preview",
|
|
337
332
|
"p"
|
|
338
333
|
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
334
|
+
setDefaultNodeEnv(options, "production");
|
|
339
335
|
const rspackOptions = {
|
|
340
336
|
...options,
|
|
341
337
|
argv: {
|
|
@@ -411,6 +407,7 @@ var __webpack_exports__ = {};
|
|
|
411
407
|
describe: "allows to specify a hostname to use"
|
|
412
408
|
}
|
|
413
409
|
}), async (options)=>{
|
|
410
|
+
setDefaultNodeEnv(options, "development");
|
|
414
411
|
setBuiltinEnvArg(ensureEnvObject(options), "SERVE", true);
|
|
415
412
|
const rspackOptions = {
|
|
416
413
|
...options,
|
|
@@ -477,7 +474,7 @@ var __webpack_exports__ = {};
|
|
|
477
474
|
}
|
|
478
475
|
}
|
|
479
476
|
var external_node_url_ = __webpack_require__("node:url");
|
|
480
|
-
const
|
|
477
|
+
const readPackageUp_readPackageUp = (cwd = process.cwd())=>{
|
|
481
478
|
let currentDir = external_node_path_default().resolve(cwd);
|
|
482
479
|
let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
|
|
483
480
|
while(!external_node_fs_default().existsSync(packageJsonPath)){
|
|
@@ -492,12 +489,12 @@ var __webpack_exports__ = {};
|
|
|
492
489
|
return null;
|
|
493
490
|
}
|
|
494
491
|
};
|
|
495
|
-
const
|
|
492
|
+
const readPackageUp = readPackageUp_readPackageUp;
|
|
496
493
|
const isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
497
494
|
const ext = external_node_path_default().extname(filePath);
|
|
498
495
|
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
499
496
|
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
500
|
-
const packageJson =
|
|
497
|
+
const packageJson = readPackageUp(external_node_path_default().dirname(filePath));
|
|
501
498
|
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
502
499
|
};
|
|
503
500
|
const utils_isEsmFile = isEsmFile;
|
|
@@ -521,15 +518,15 @@ var __webpack_exports__ = {};
|
|
|
521
518
|
];
|
|
522
519
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
|
523
520
|
const utils_findConfig = findConfig;
|
|
524
|
-
const
|
|
521
|
+
const isTsFile = (configPath)=>{
|
|
525
522
|
const ext = external_node_path_default().extname(configPath);
|
|
526
523
|
return /\.(c|m)?ts$/.test(ext);
|
|
527
524
|
};
|
|
528
|
-
const
|
|
525
|
+
const utils_isTsFile = isTsFile;
|
|
529
526
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
530
527
|
const registerLoader = async (configPath)=>{
|
|
531
528
|
const ext = external_node_path_default().extname(configPath);
|
|
532
|
-
if (utils_isEsmFile(configPath) &&
|
|
529
|
+
if (utils_isEsmFile(configPath) && utils_isTsFile(configPath)) return;
|
|
533
530
|
const { default: interpret } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "interpret"));
|
|
534
531
|
const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
|
|
535
532
|
if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
|
|
@@ -545,19 +542,63 @@ var __webpack_exports__ = {};
|
|
|
545
542
|
throw error;
|
|
546
543
|
}
|
|
547
544
|
};
|
|
545
|
+
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
546
|
+
if (!("extends" in config) || !config.extends) return config;
|
|
547
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
548
|
+
config.extends
|
|
549
|
+
];
|
|
550
|
+
const { extends: _, ...configWithoutExtends } = config;
|
|
551
|
+
const baseDir = external_node_path_default().dirname(configPath);
|
|
552
|
+
let resultConfig = configWithoutExtends;
|
|
553
|
+
for (const extendPath of extendsList){
|
|
554
|
+
let resolvedPath;
|
|
555
|
+
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
556
|
+
resolvedPath = external_node_path_default().resolve(baseDir, extendPath);
|
|
557
|
+
if (!external_node_path_default().extname(resolvedPath)) {
|
|
558
|
+
const foundConfig = utils_findConfig(resolvedPath);
|
|
559
|
+
if (foundConfig) resolvedPath = foundConfig;
|
|
560
|
+
else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
561
|
+
}
|
|
562
|
+
} else try {
|
|
563
|
+
resolvedPath = require.resolve(extendPath, {
|
|
564
|
+
paths: [
|
|
565
|
+
baseDir,
|
|
566
|
+
cwd
|
|
567
|
+
]
|
|
568
|
+
});
|
|
569
|
+
} catch (error) {
|
|
570
|
+
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
571
|
+
}
|
|
572
|
+
if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
573
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
|
|
574
|
+
let extendedConfig = await crossImport(resolvedPath, cwd);
|
|
575
|
+
if ("function" == typeof extendedConfig) {
|
|
576
|
+
var _options_argv;
|
|
577
|
+
extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
578
|
+
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
579
|
+
}
|
|
580
|
+
extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
|
|
581
|
+
resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
|
|
582
|
+
}
|
|
583
|
+
return resultConfig;
|
|
584
|
+
}
|
|
548
585
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
586
|
+
let configPath;
|
|
587
|
+
let loadedConfig;
|
|
549
588
|
if (options.config) {
|
|
550
|
-
|
|
589
|
+
configPath = external_node_path_default().resolve(cwd, options.config);
|
|
551
590
|
if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
552
|
-
if (
|
|
553
|
-
|
|
591
|
+
if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
592
|
+
loadedConfig = await crossImport(configPath, cwd);
|
|
593
|
+
} else {
|
|
594
|
+
const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
595
|
+
if (!defaultConfig) return {};
|
|
596
|
+
configPath = defaultConfig;
|
|
597
|
+
if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
598
|
+
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
554
599
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
558
|
-
return crossImport(defaultConfig, cwd);
|
|
559
|
-
}
|
|
560
|
-
return {};
|
|
600
|
+
if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
|
|
601
|
+
return loadedConfig;
|
|
561
602
|
}
|
|
562
603
|
function _define_property(obj, key, value) {
|
|
563
604
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -571,13 +612,8 @@ var __webpack_exports__ = {};
|
|
|
571
612
|
}
|
|
572
613
|
class RspackCLI {
|
|
573
614
|
async createCompiler(options, rspackCommand, callback) {
|
|
574
|
-
var _process_env, _process;
|
|
575
615
|
process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
|
|
576
616
|
process.env.WATCHPACK_WATCHER_LIMIT = process.env.WATCHPACK_WATCHER_LIMIT || "20";
|
|
577
|
-
const nodeEnv = null === (_process = process) || void 0 === _process ? void 0 : null === (_process_env = _process.env) || void 0 === _process_env ? void 0 : _process_env.NODE_ENV;
|
|
578
|
-
const rspackCommandDefaultEnv = "build" === rspackCommand ? "production" : "development";
|
|
579
|
-
if ("string" == typeof options.nodeEnv) process.env.NODE_ENV = nodeEnv || options.nodeEnv;
|
|
580
|
-
else process.env.NODE_ENV = nodeEnv || rspackCommandDefaultEnv;
|
|
581
617
|
let config = await this.loadConfig(options);
|
|
582
618
|
config = await this.buildConfig(config, options, rspackCommand);
|
|
583
619
|
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
@@ -636,7 +672,6 @@ var __webpack_exports__ = {};
|
|
|
636
672
|
async buildConfig(item, options, command) {
|
|
637
673
|
const isBuild = "build" === command;
|
|
638
674
|
const isServe = "serve" === command;
|
|
639
|
-
const commandDefaultEnv = isBuild ? "production" : "development";
|
|
640
675
|
const internalBuildConfig = async (item)=>{
|
|
641
676
|
if (options.entry) item.entry = {
|
|
642
677
|
main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
|
|
@@ -656,11 +691,11 @@ var __webpack_exports__ = {};
|
|
|
656
691
|
}
|
|
657
692
|
if (options.profile) item.profile = true;
|
|
658
693
|
if (process.env.RSPACK_PROFILE) {
|
|
659
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
694
|
+
const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
660
695
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
661
696
|
}
|
|
662
697
|
if (options.watch) item.watch = options.watch;
|
|
663
|
-
if (!item.mode) item.mode =
|
|
698
|
+
if (!item.mode) item.mode = isBuild ? "production" : "development";
|
|
664
699
|
if (options.mode) item.mode = options.mode;
|
|
665
700
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
666
701
|
if (isServe) {
|
|
@@ -689,8 +724,13 @@ var __webpack_exports__ = {};
|
|
|
689
724
|
let loadedConfig = await loadRspackConfig(options);
|
|
690
725
|
if ("function" == typeof loadedConfig) {
|
|
691
726
|
var _options_argv;
|
|
692
|
-
|
|
693
|
-
if ("function" == typeof
|
|
727
|
+
let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
728
|
+
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
729
|
+
loadedConfig = functionResult;
|
|
730
|
+
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
731
|
+
const tempConfigPath = external_node_path_default().resolve(process.cwd(), "rspack.config.js");
|
|
732
|
+
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
733
|
+
}
|
|
694
734
|
}
|
|
695
735
|
if (options.configName) {
|
|
696
736
|
const notFoundConfigNames = [];
|
package/dist/index.mjs
CHANGED
|
@@ -36,7 +36,7 @@ function __webpack_require__(moduleId) {
|
|
|
36
36
|
}
|
|
37
37
|
__webpack_require__.m = __webpack_modules__;
|
|
38
38
|
(()=>{
|
|
39
|
-
__webpack_require__.d =
|
|
39
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
40
40
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
41
41
|
enumerable: true,
|
|
42
42
|
get: definition[key]
|
|
@@ -45,38 +45,32 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
45
45
|
})();
|
|
46
46
|
(()=>{
|
|
47
47
|
__webpack_require__.f = {};
|
|
48
|
-
__webpack_require__.e =
|
|
49
|
-
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
48
|
+
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
50
49
|
__webpack_require__.f[key](chunkId, promises);
|
|
51
50
|
return promises;
|
|
52
51
|
}, []));
|
|
53
|
-
};
|
|
54
52
|
})();
|
|
55
53
|
(()=>{
|
|
56
|
-
__webpack_require__.u =
|
|
57
|
-
return "" + chunkId + ".mjs";
|
|
58
|
-
};
|
|
54
|
+
__webpack_require__.u = (chunkId)=>"" + chunkId + ".mjs";
|
|
59
55
|
})();
|
|
60
56
|
(()=>{
|
|
61
|
-
__webpack_require__.o =
|
|
62
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
63
|
-
};
|
|
57
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
64
58
|
})();
|
|
65
59
|
(()=>{
|
|
66
60
|
var installedChunks = {
|
|
67
61
|
980: 0
|
|
68
62
|
};
|
|
69
|
-
var installChunk =
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
63
|
+
var installChunk = (data)=>{
|
|
64
|
+
var __webpack_ids__ = data.__webpack_ids__;
|
|
65
|
+
var __webpack_modules__ = data.__webpack_modules__;
|
|
66
|
+
var __webpack_runtime__ = data.__webpack_runtime__;
|
|
73
67
|
var moduleId, chunkId, i = 0;
|
|
74
|
-
for(moduleId in
|
|
75
|
-
if (
|
|
76
|
-
for(; i <
|
|
77
|
-
chunkId =
|
|
68
|
+
for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
|
|
69
|
+
if (__webpack_runtime__) __webpack_runtime__(__webpack_require__);
|
|
70
|
+
for(; i < __webpack_ids__.length; i++){
|
|
71
|
+
chunkId = __webpack_ids__[i];
|
|
78
72
|
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
79
|
-
installedChunks[
|
|
73
|
+
installedChunks[__webpack_ids__[i]] = 0;
|
|
80
74
|
}
|
|
81
75
|
};
|
|
82
76
|
__webpack_require__.f.j = function(chunkId, promises) {
|
|
@@ -84,13 +78,13 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
84
78
|
if (0 !== installedChunkData) {
|
|
85
79
|
if (installedChunkData) promises.push(installedChunkData[1]);
|
|
86
80
|
else {
|
|
87
|
-
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk,
|
|
81
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
|
|
88
82
|
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
89
83
|
throw e;
|
|
90
84
|
});
|
|
91
85
|
var promise = Promise.race([
|
|
92
86
|
promise,
|
|
93
|
-
new Promise(
|
|
87
|
+
new Promise((resolve)=>{
|
|
94
88
|
installedChunkData = installedChunks[chunkId] = [
|
|
95
89
|
resolve
|
|
96
90
|
];
|
|
@@ -120,6 +114,10 @@ const commonOptions = (yargs)=>yargs.options({
|
|
|
120
114
|
type: "string",
|
|
121
115
|
default: "register",
|
|
122
116
|
describe: "Specify the loader to load the config file, can be `native` or `register`."
|
|
117
|
+
},
|
|
118
|
+
nodeEnv: {
|
|
119
|
+
string: true,
|
|
120
|
+
describe: "sets `process.env.NODE_ENV` to be specified value"
|
|
123
121
|
}
|
|
124
122
|
});
|
|
125
123
|
const commonOptionsForBuildAndServe = (yargs)=>yargs.options({
|
|
@@ -149,10 +147,6 @@ const commonOptionsForBuildAndServe = (yargs)=>yargs.options({
|
|
|
149
147
|
string: true,
|
|
150
148
|
describe: "env passed to config function"
|
|
151
149
|
},
|
|
152
|
-
nodeEnv: {
|
|
153
|
-
string: true,
|
|
154
|
-
describe: "sets process.env.NODE_ENV to be specified value"
|
|
155
|
-
},
|
|
156
150
|
devtool: {
|
|
157
151
|
type: "boolean",
|
|
158
152
|
default: false,
|
|
@@ -198,6 +192,10 @@ function ensureEnvObject(options) {
|
|
|
198
192
|
options.env = options.env || {};
|
|
199
193
|
return options.env;
|
|
200
194
|
}
|
|
195
|
+
function setDefaultNodeEnv(options, defaultEnv) {
|
|
196
|
+
if (void 0 !== process.env.NODE_ENV) return;
|
|
197
|
+
process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
198
|
+
}
|
|
201
199
|
class BuildCommand {
|
|
202
200
|
async apply(cli) {
|
|
203
201
|
cli.program.command([
|
|
@@ -222,6 +220,7 @@ class BuildCommand {
|
|
|
222
220
|
}
|
|
223
221
|
});
|
|
224
222
|
}, async (options)=>{
|
|
223
|
+
setDefaultNodeEnv(options, "production");
|
|
225
224
|
const env = ensureEnvObject(options);
|
|
226
225
|
if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
227
226
|
else {
|
|
@@ -312,6 +311,7 @@ class PreviewCommand {
|
|
|
312
311
|
"preview",
|
|
313
312
|
"p"
|
|
314
313
|
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
314
|
+
setDefaultNodeEnv(options, "production");
|
|
315
315
|
const rspackOptions = {
|
|
316
316
|
...options,
|
|
317
317
|
argv: {
|
|
@@ -387,6 +387,7 @@ class ServeCommand {
|
|
|
387
387
|
describe: "allows to specify a hostname to use"
|
|
388
388
|
}
|
|
389
389
|
}), async (options)=>{
|
|
390
|
+
setDefaultNodeEnv(options, "development");
|
|
390
391
|
setBuiltinEnvArg(ensureEnvObject(options), "SERVE", true);
|
|
391
392
|
const rspackOptions = {
|
|
392
393
|
...options,
|
|
@@ -453,7 +454,7 @@ class ServeCommand {
|
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
var external_node_url_ = __webpack_require__("node:url");
|
|
456
|
-
const
|
|
457
|
+
const readPackageUp_readPackageUp = (cwd = process.cwd())=>{
|
|
457
458
|
let currentDir = external_node_path_["default"].resolve(cwd);
|
|
458
459
|
let packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
459
460
|
while(!external_node_fs_["default"].existsSync(packageJsonPath)){
|
|
@@ -468,12 +469,12 @@ const readPackageUp = (cwd = process.cwd())=>{
|
|
|
468
469
|
return null;
|
|
469
470
|
}
|
|
470
471
|
};
|
|
471
|
-
const
|
|
472
|
+
const readPackageUp = readPackageUp_readPackageUp;
|
|
472
473
|
const isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
473
474
|
const ext = external_node_path_["default"].extname(filePath);
|
|
474
475
|
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
475
476
|
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
476
|
-
const packageJson =
|
|
477
|
+
const packageJson = readPackageUp(external_node_path_["default"].dirname(filePath));
|
|
477
478
|
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
478
479
|
};
|
|
479
480
|
const utils_isEsmFile = isEsmFile;
|
|
@@ -497,15 +498,15 @@ const DEFAULT_EXTENSIONS = [
|
|
|
497
498
|
];
|
|
498
499
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
|
499
500
|
const utils_findConfig = findConfig;
|
|
500
|
-
const
|
|
501
|
+
const isTsFile = (configPath)=>{
|
|
501
502
|
const ext = external_node_path_["default"].extname(configPath);
|
|
502
503
|
return /\.(c|m)?ts$/.test(ext);
|
|
503
504
|
};
|
|
504
|
-
const
|
|
505
|
+
const utils_isTsFile = isTsFile;
|
|
505
506
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
506
507
|
const registerLoader = async (configPath)=>{
|
|
507
508
|
const ext = external_node_path_["default"].extname(configPath);
|
|
508
|
-
if (utils_isEsmFile(configPath) &&
|
|
509
|
+
if (utils_isEsmFile(configPath) && utils_isTsFile(configPath)) return;
|
|
509
510
|
const { default: interpret } = await import("interpret");
|
|
510
511
|
const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
|
|
511
512
|
if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
|
|
@@ -521,19 +522,63 @@ const registerLoader = async (configPath)=>{
|
|
|
521
522
|
throw error;
|
|
522
523
|
}
|
|
523
524
|
};
|
|
525
|
+
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
526
|
+
if (!("extends" in config) || !config.extends) return config;
|
|
527
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
528
|
+
config.extends
|
|
529
|
+
];
|
|
530
|
+
const { extends: _, ...configWithoutExtends } = config;
|
|
531
|
+
const baseDir = external_node_path_["default"].dirname(configPath);
|
|
532
|
+
let resultConfig = configWithoutExtends;
|
|
533
|
+
for (const extendPath of extendsList){
|
|
534
|
+
let resolvedPath;
|
|
535
|
+
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
536
|
+
resolvedPath = external_node_path_["default"].resolve(baseDir, extendPath);
|
|
537
|
+
if (!external_node_path_["default"].extname(resolvedPath)) {
|
|
538
|
+
const foundConfig = utils_findConfig(resolvedPath);
|
|
539
|
+
if (foundConfig) resolvedPath = foundConfig;
|
|
540
|
+
else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
541
|
+
}
|
|
542
|
+
} else try {
|
|
543
|
+
resolvedPath = require.resolve(extendPath, {
|
|
544
|
+
paths: [
|
|
545
|
+
baseDir,
|
|
546
|
+
cwd
|
|
547
|
+
]
|
|
548
|
+
});
|
|
549
|
+
} catch (error) {
|
|
550
|
+
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
551
|
+
}
|
|
552
|
+
if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
553
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
|
|
554
|
+
let extendedConfig = await crossImport(resolvedPath, cwd);
|
|
555
|
+
if ("function" == typeof extendedConfig) {
|
|
556
|
+
var _options_argv;
|
|
557
|
+
extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
558
|
+
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
559
|
+
}
|
|
560
|
+
extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
|
|
561
|
+
resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
|
|
562
|
+
}
|
|
563
|
+
return resultConfig;
|
|
564
|
+
}
|
|
524
565
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
566
|
+
let configPath;
|
|
567
|
+
let loadedConfig;
|
|
525
568
|
if (options.config) {
|
|
526
|
-
|
|
569
|
+
configPath = external_node_path_["default"].resolve(cwd, options.config);
|
|
527
570
|
if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
528
|
-
if (
|
|
529
|
-
|
|
571
|
+
if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
572
|
+
loadedConfig = await crossImport(configPath, cwd);
|
|
573
|
+
} else {
|
|
574
|
+
const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
575
|
+
if (!defaultConfig) return {};
|
|
576
|
+
configPath = defaultConfig;
|
|
577
|
+
if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
578
|
+
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
530
579
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
534
|
-
return crossImport(defaultConfig, cwd);
|
|
535
|
-
}
|
|
536
|
-
return {};
|
|
580
|
+
if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
|
|
581
|
+
return loadedConfig;
|
|
537
582
|
}
|
|
538
583
|
function _define_property(obj, key, value) {
|
|
539
584
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -547,13 +592,8 @@ function _define_property(obj, key, value) {
|
|
|
547
592
|
}
|
|
548
593
|
class RspackCLI {
|
|
549
594
|
async createCompiler(options, rspackCommand, callback) {
|
|
550
|
-
var _process_env, _process;
|
|
551
595
|
process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
|
|
552
596
|
process.env.WATCHPACK_WATCHER_LIMIT = process.env.WATCHPACK_WATCHER_LIMIT || "20";
|
|
553
|
-
const nodeEnv = null === (_process = process) || void 0 === _process ? void 0 : null === (_process_env = _process.env) || void 0 === _process_env ? void 0 : _process_env.NODE_ENV;
|
|
554
|
-
const rspackCommandDefaultEnv = "build" === rspackCommand ? "production" : "development";
|
|
555
|
-
if ("string" == typeof options.nodeEnv) process.env.NODE_ENV = nodeEnv || options.nodeEnv;
|
|
556
|
-
else process.env.NODE_ENV = nodeEnv || rspackCommandDefaultEnv;
|
|
557
597
|
let config = await this.loadConfig(options);
|
|
558
598
|
config = await this.buildConfig(config, options, rspackCommand);
|
|
559
599
|
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
@@ -612,7 +652,6 @@ class RspackCLI {
|
|
|
612
652
|
async buildConfig(item, options, command) {
|
|
613
653
|
const isBuild = "build" === command;
|
|
614
654
|
const isServe = "serve" === command;
|
|
615
|
-
const commandDefaultEnv = isBuild ? "production" : "development";
|
|
616
655
|
const internalBuildConfig = async (item)=>{
|
|
617
656
|
if (options.entry) item.entry = {
|
|
618
657
|
main: options.entry.map((x)=>external_node_path_["default"].resolve(process.cwd(), x))[0]
|
|
@@ -632,11 +671,11 @@ class RspackCLI {
|
|
|
632
671
|
}
|
|
633
672
|
if (options.profile) item.profile = true;
|
|
634
673
|
if (process.env.RSPACK_PROFILE) {
|
|
635
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
674
|
+
const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
636
675
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
637
676
|
}
|
|
638
677
|
if (options.watch) item.watch = options.watch;
|
|
639
|
-
if (!item.mode) item.mode =
|
|
678
|
+
if (!item.mode) item.mode = isBuild ? "production" : "development";
|
|
640
679
|
if (options.mode) item.mode = options.mode;
|
|
641
680
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
642
681
|
if (isServe) {
|
|
@@ -665,8 +704,13 @@ class RspackCLI {
|
|
|
665
704
|
let loadedConfig = await loadRspackConfig(options);
|
|
666
705
|
if ("function" == typeof loadedConfig) {
|
|
667
706
|
var _options_argv;
|
|
668
|
-
|
|
669
|
-
if ("function" == typeof
|
|
707
|
+
let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
708
|
+
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
709
|
+
loadedConfig = functionResult;
|
|
710
|
+
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
711
|
+
const tempConfigPath = external_node_path_["default"].resolve(process.cwd(), "rspack.config.js");
|
|
712
|
+
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
713
|
+
}
|
|
670
714
|
}
|
|
671
715
|
if (options.configName) {
|
|
672
716
|
const notFoundConfigNames = [];
|
package/dist/types.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface RspackCLIOptions {
|
|
|
22
22
|
argv?: Record<string, any>;
|
|
23
23
|
configName?: string[];
|
|
24
24
|
configLoader?: string;
|
|
25
|
+
nodeEnv?: string;
|
|
25
26
|
}
|
|
26
27
|
export interface RspackBuildCLIOptions extends RspackCLIOptions {
|
|
27
28
|
entry?: string[];
|
|
@@ -31,7 +32,6 @@ export interface RspackBuildCLIOptions extends RspackCLIOptions {
|
|
|
31
32
|
analyze?: boolean;
|
|
32
33
|
profile?: boolean;
|
|
33
34
|
env?: Record<string, any>;
|
|
34
|
-
nodeEnv?: string;
|
|
35
35
|
outputPath?: string;
|
|
36
36
|
}
|
|
37
37
|
export interface RspackPreviewCLIOptions extends RspackCLIOptions {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MultiRspackOptions, type RspackOptions } from "@rspack/core";
|
|
2
2
|
import type { RspackCLIOptions } from "../types";
|
|
3
3
|
export type LoadedRspackConfig = undefined | RspackOptions | MultiRspackOptions | ((env: Record<string, any>, argv?: Record<string, any>) => RspackOptions | MultiRspackOptions);
|
|
4
|
+
/**
|
|
5
|
+
* Loads and merges configurations from the 'extends' property
|
|
6
|
+
* @param config The configuration object that may contain an 'extends' property
|
|
7
|
+
* @param configPath The path to the configuration file
|
|
8
|
+
* @param cwd The current working directory
|
|
9
|
+
* @param options CLI options
|
|
10
|
+
* @returns The merged configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadExtendedConfig(config: RspackOptions | MultiRspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<RspackOptions | MultiRspackOptions>;
|
|
4
13
|
export declare function loadRspackConfig(options: RspackCLIOptions, cwd?: string): Promise<LoadedRspackConfig>;
|
package/dist/utils/options.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type yargs from "yargs";
|
|
|
2
2
|
/**
|
|
3
3
|
* Apply common options for all commands
|
|
4
4
|
*/
|
|
5
|
-
export declare const commonOptions: (yargs: yargs.Argv) => yargs.Argv<yargs.Omit<{}, "config" | "configName" | "configLoader"> & yargs.InferredOptionTypes<{
|
|
5
|
+
export declare const commonOptions: (yargs: yargs.Argv) => yargs.Argv<yargs.Omit<{}, "nodeEnv" | "config" | "configName" | "configLoader"> & yargs.InferredOptionTypes<{
|
|
6
6
|
config: {
|
|
7
7
|
g: boolean;
|
|
8
8
|
type: "string";
|
|
@@ -19,11 +19,15 @@ export declare const commonOptions: (yargs: yargs.Argv) => yargs.Argv<yargs.Omit
|
|
|
19
19
|
default: string;
|
|
20
20
|
describe: string;
|
|
21
21
|
};
|
|
22
|
+
nodeEnv: {
|
|
23
|
+
string: true;
|
|
24
|
+
describe: string;
|
|
25
|
+
};
|
|
22
26
|
}>>;
|
|
23
27
|
/**
|
|
24
28
|
* Apply common options for `build` and `serve` commands
|
|
25
29
|
*/
|
|
26
|
-
export declare const commonOptionsForBuildAndServe: (yargs: yargs.Argv) => yargs.Argv<yargs.Omit<{}, "entry" | "devtool" | "mode" | "watch" | "env" | "
|
|
30
|
+
export declare const commonOptionsForBuildAndServe: (yargs: yargs.Argv) => yargs.Argv<yargs.Omit<{}, "entry" | "devtool" | "mode" | "watch" | "env" | "outputPath"> & yargs.InferredOptionTypes<{
|
|
27
31
|
entry: {
|
|
28
32
|
type: "array";
|
|
29
33
|
string: true;
|
|
@@ -50,10 +54,6 @@ export declare const commonOptionsForBuildAndServe: (yargs: yargs.Argv) => yargs
|
|
|
50
54
|
string: true;
|
|
51
55
|
describe: string;
|
|
52
56
|
};
|
|
53
|
-
nodeEnv: {
|
|
54
|
-
string: true;
|
|
55
|
-
describe: string;
|
|
56
|
-
};
|
|
57
57
|
devtool: {
|
|
58
58
|
type: "boolean";
|
|
59
59
|
default: boolean;
|
|
@@ -74,3 +74,4 @@ export declare function setBuiltinEnvArg(env: Record<string, any>, envNameSuffix
|
|
|
74
74
|
* @returns the reference of `argv.env` object
|
|
75
75
|
*/
|
|
76
76
|
export declare function ensureEnvObject<T extends Record<string, unknown>>(options: yargs.Arguments): T;
|
|
77
|
+
export declare function setDefaultNodeEnv(options: yargs.Arguments, defaultEnv: string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.0",
|
|
4
4
|
"description": "CLI for rspack",
|
|
5
5
|
"homepage": "https://rspack.dev",
|
|
6
6
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@discoveryjs/json-ext": "^0.5.7",
|
|
32
|
-
"@rspack/dev-server": "1.0
|
|
32
|
+
"@rspack/dev-server": "1.1.0",
|
|
33
33
|
"colorette": "2.0.20",
|
|
34
34
|
"exit-hook": "^4.0.0",
|
|
35
35
|
"interpret": "^3.1.1",
|
|
36
36
|
"rechoir": "^0.8.0",
|
|
37
|
-
"webpack-bundle-analyzer": "4.
|
|
37
|
+
"webpack-bundle-analyzer": "4.10.2",
|
|
38
38
|
"yargs": "17.7.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@rslib/core": "0.5.
|
|
41
|
+
"@rslib/core": "0.5.4",
|
|
42
42
|
"@types/interpret": "^1.1.3",
|
|
43
43
|
"@types/rechoir": "^0.6.4",
|
|
44
44
|
"@types/webpack-bundle-analyzer": "^4.7.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"execa": "^5.1.1",
|
|
49
49
|
"ts-node": "^10.9.2",
|
|
50
50
|
"typescript": "^5.7.3",
|
|
51
|
-
"@rspack/
|
|
52
|
-
"@rspack/
|
|
51
|
+
"@rspack/core": "1.3.0-beta.0",
|
|
52
|
+
"@rspack/tracing": "1.3.0-beta.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@rspack/core": "^1.0.0-alpha || ^1.x",
|