@rspack/cli 1.2.8 → 1.3.0-beta.1
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/{390.js → 957.js} +1 -1
- package/dist/{390.mjs → 957.mjs} +1 -1
- package/dist/index.js +72 -10
- package/dist/index.mjs +72 -10
- package/dist/utils/loadConfig.d.ts +10 -1
- package/package.json +6 -6
package/dist/{390.js → 957.js}
RENAMED
package/dist/{390.mjs → 957.mjs}
RENAMED
package/dist/index.js
CHANGED
|
@@ -440,6 +440,19 @@ var __webpack_exports__ = {};
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
443
|
+
if (compilerForDevServer.options.experiments.lazyCompilation) {
|
|
444
|
+
const options = compilerForDevServer.options.experiments.lazyCompilation;
|
|
445
|
+
const setupMiddlewares = result.setupMiddlewares;
|
|
446
|
+
const lazyCompileMiddleware = core_.rspack.experiments.lazyCompilationMiddleware(compilerForDevServer, options);
|
|
447
|
+
result.setupMiddlewares = (middlewares, server)=>{
|
|
448
|
+
let finalMiddlewares = middlewares;
|
|
449
|
+
if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
|
|
450
|
+
return [
|
|
451
|
+
lazyCompileMiddleware,
|
|
452
|
+
...finalMiddlewares
|
|
453
|
+
];
|
|
454
|
+
};
|
|
455
|
+
}
|
|
443
456
|
result.hot = options.hot ?? result.hot ?? true;
|
|
444
457
|
result.host = options.host || result.host;
|
|
445
458
|
result.port = options.port || result.port;
|
|
@@ -542,19 +555,63 @@ var __webpack_exports__ = {};
|
|
|
542
555
|
throw error;
|
|
543
556
|
}
|
|
544
557
|
};
|
|
558
|
+
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
559
|
+
if (!("extends" in config) || !config.extends) return config;
|
|
560
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
561
|
+
config.extends
|
|
562
|
+
];
|
|
563
|
+
const { extends: _, ...configWithoutExtends } = config;
|
|
564
|
+
const baseDir = external_node_path_default().dirname(configPath);
|
|
565
|
+
let resultConfig = configWithoutExtends;
|
|
566
|
+
for (const extendPath of extendsList){
|
|
567
|
+
let resolvedPath;
|
|
568
|
+
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
569
|
+
resolvedPath = external_node_path_default().resolve(baseDir, extendPath);
|
|
570
|
+
if (!external_node_path_default().extname(resolvedPath)) {
|
|
571
|
+
const foundConfig = utils_findConfig(resolvedPath);
|
|
572
|
+
if (foundConfig) resolvedPath = foundConfig;
|
|
573
|
+
else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
574
|
+
}
|
|
575
|
+
} else try {
|
|
576
|
+
resolvedPath = require.resolve(extendPath, {
|
|
577
|
+
paths: [
|
|
578
|
+
baseDir,
|
|
579
|
+
cwd
|
|
580
|
+
]
|
|
581
|
+
});
|
|
582
|
+
} catch (error) {
|
|
583
|
+
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
584
|
+
}
|
|
585
|
+
if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
586
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
|
|
587
|
+
let extendedConfig = await crossImport(resolvedPath, cwd);
|
|
588
|
+
if ("function" == typeof extendedConfig) {
|
|
589
|
+
var _options_argv;
|
|
590
|
+
extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
591
|
+
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
592
|
+
}
|
|
593
|
+
extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
|
|
594
|
+
resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
|
|
595
|
+
}
|
|
596
|
+
return resultConfig;
|
|
597
|
+
}
|
|
545
598
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
599
|
+
let configPath;
|
|
600
|
+
let loadedConfig;
|
|
546
601
|
if (options.config) {
|
|
547
|
-
|
|
602
|
+
configPath = external_node_path_default().resolve(cwd, options.config);
|
|
548
603
|
if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
549
604
|
if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
605
|
+
loadedConfig = await crossImport(configPath, cwd);
|
|
606
|
+
} else {
|
|
607
|
+
const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
608
|
+
if (!defaultConfig) return {};
|
|
609
|
+
configPath = defaultConfig;
|
|
554
610
|
if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
555
|
-
|
|
611
|
+
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
556
612
|
}
|
|
557
|
-
|
|
613
|
+
if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
|
|
614
|
+
return loadedConfig;
|
|
558
615
|
}
|
|
559
616
|
function _define_property(obj, key, value) {
|
|
560
617
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -647,7 +704,7 @@ var __webpack_exports__ = {};
|
|
|
647
704
|
}
|
|
648
705
|
if (options.profile) item.profile = true;
|
|
649
706
|
if (process.env.RSPACK_PROFILE) {
|
|
650
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
707
|
+
const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
651
708
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
652
709
|
}
|
|
653
710
|
if (options.watch) item.watch = options.watch;
|
|
@@ -680,8 +737,13 @@ var __webpack_exports__ = {};
|
|
|
680
737
|
let loadedConfig = await loadRspackConfig(options);
|
|
681
738
|
if ("function" == typeof loadedConfig) {
|
|
682
739
|
var _options_argv;
|
|
683
|
-
|
|
684
|
-
if ("function" == typeof
|
|
740
|
+
let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
741
|
+
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
742
|
+
loadedConfig = functionResult;
|
|
743
|
+
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
744
|
+
const tempConfigPath = external_node_path_default().resolve(process.cwd(), "rspack.config.js");
|
|
745
|
+
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
746
|
+
}
|
|
685
747
|
}
|
|
686
748
|
if (options.configName) {
|
|
687
749
|
const notFoundConfigNames = [];
|
package/dist/index.mjs
CHANGED
|
@@ -420,6 +420,19 @@ class ServeCommand {
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
423
|
+
if (compilerForDevServer.options.experiments.lazyCompilation) {
|
|
424
|
+
const options = compilerForDevServer.options.experiments.lazyCompilation;
|
|
425
|
+
const setupMiddlewares = result.setupMiddlewares;
|
|
426
|
+
const lazyCompileMiddleware = core_.rspack.experiments.lazyCompilationMiddleware(compilerForDevServer, options);
|
|
427
|
+
result.setupMiddlewares = (middlewares, server)=>{
|
|
428
|
+
let finalMiddlewares = middlewares;
|
|
429
|
+
if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
|
|
430
|
+
return [
|
|
431
|
+
lazyCompileMiddleware,
|
|
432
|
+
...finalMiddlewares
|
|
433
|
+
];
|
|
434
|
+
};
|
|
435
|
+
}
|
|
423
436
|
result.hot = options.hot ?? result.hot ?? true;
|
|
424
437
|
result.host = options.host || result.host;
|
|
425
438
|
result.port = options.port || result.port;
|
|
@@ -522,19 +535,63 @@ const registerLoader = async (configPath)=>{
|
|
|
522
535
|
throw error;
|
|
523
536
|
}
|
|
524
537
|
};
|
|
538
|
+
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
539
|
+
if (!("extends" in config) || !config.extends) return config;
|
|
540
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
541
|
+
config.extends
|
|
542
|
+
];
|
|
543
|
+
const { extends: _, ...configWithoutExtends } = config;
|
|
544
|
+
const baseDir = external_node_path_["default"].dirname(configPath);
|
|
545
|
+
let resultConfig = configWithoutExtends;
|
|
546
|
+
for (const extendPath of extendsList){
|
|
547
|
+
let resolvedPath;
|
|
548
|
+
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
549
|
+
resolvedPath = external_node_path_["default"].resolve(baseDir, extendPath);
|
|
550
|
+
if (!external_node_path_["default"].extname(resolvedPath)) {
|
|
551
|
+
const foundConfig = utils_findConfig(resolvedPath);
|
|
552
|
+
if (foundConfig) resolvedPath = foundConfig;
|
|
553
|
+
else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
554
|
+
}
|
|
555
|
+
} else try {
|
|
556
|
+
resolvedPath = require.resolve(extendPath, {
|
|
557
|
+
paths: [
|
|
558
|
+
baseDir,
|
|
559
|
+
cwd
|
|
560
|
+
]
|
|
561
|
+
});
|
|
562
|
+
} catch (error) {
|
|
563
|
+
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
564
|
+
}
|
|
565
|
+
if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
566
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
|
|
567
|
+
let extendedConfig = await crossImport(resolvedPath, cwd);
|
|
568
|
+
if ("function" == typeof extendedConfig) {
|
|
569
|
+
var _options_argv;
|
|
570
|
+
extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
571
|
+
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
572
|
+
}
|
|
573
|
+
extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
|
|
574
|
+
resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
|
|
575
|
+
}
|
|
576
|
+
return resultConfig;
|
|
577
|
+
}
|
|
525
578
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
579
|
+
let configPath;
|
|
580
|
+
let loadedConfig;
|
|
526
581
|
if (options.config) {
|
|
527
|
-
|
|
582
|
+
configPath = external_node_path_["default"].resolve(cwd, options.config);
|
|
528
583
|
if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
529
584
|
if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
585
|
+
loadedConfig = await crossImport(configPath, cwd);
|
|
586
|
+
} else {
|
|
587
|
+
const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
588
|
+
if (!defaultConfig) return {};
|
|
589
|
+
configPath = defaultConfig;
|
|
534
590
|
if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
535
|
-
|
|
591
|
+
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
536
592
|
}
|
|
537
|
-
|
|
593
|
+
if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
|
|
594
|
+
return loadedConfig;
|
|
538
595
|
}
|
|
539
596
|
function _define_property(obj, key, value) {
|
|
540
597
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -627,7 +684,7 @@ class RspackCLI {
|
|
|
627
684
|
}
|
|
628
685
|
if (options.profile) item.profile = true;
|
|
629
686
|
if (process.env.RSPACK_PROFILE) {
|
|
630
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
687
|
+
const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
631
688
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
632
689
|
}
|
|
633
690
|
if (options.watch) item.watch = options.watch;
|
|
@@ -660,8 +717,13 @@ class RspackCLI {
|
|
|
660
717
|
let loadedConfig = await loadRspackConfig(options);
|
|
661
718
|
if ("function" == typeof loadedConfig) {
|
|
662
719
|
var _options_argv;
|
|
663
|
-
|
|
664
|
-
if ("function" == typeof
|
|
720
|
+
let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
721
|
+
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
722
|
+
loadedConfig = functionResult;
|
|
723
|
+
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
724
|
+
const tempConfigPath = external_node_path_["default"].resolve(process.cwd(), "rspack.config.js");
|
|
725
|
+
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
726
|
+
}
|
|
665
727
|
}
|
|
666
728
|
if (options.configName) {
|
|
667
729
|
const notFoundConfigNames = [];
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.1",
|
|
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/tracing": "1.3.0-beta.1",
|
|
52
|
+
"@rspack/core": "1.3.0-beta.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@rspack/core": "^1.0.0-alpha || ^1.x",
|