@rsbuild/core 1.4.15 → 1.5.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/compiled/css-loader/index.js +18 -18
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/launch-editor-middleware/index.js +18 -15
- package/compiled/launch-editor-middleware/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/rspack-chain/types/index.d.ts +1 -0
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/client/hmr.js +3 -9
- package/dist/ignoreCssLoader.mjs +1 -1
- package/dist/index.cjs +814 -474
- package/dist/index.cjs.LICENSE.txt +14 -0
- package/dist/index.js +845 -500
- package/dist/index.js.LICENSE.txt +14 -0
- package/dist/transformLoader.mjs +1 -2
- package/dist/transformRawLoader.mjs +1 -2
- package/dist-types/helpers/index.d.ts +1 -0
- package/dist-types/hooks.d.ts +2 -1
- package/dist-types/index.d.ts +1 -1
- package/dist-types/plugins/esm.d.ts +2 -0
- package/dist-types/types/config.d.ts +8 -0
- package/dist-types/types/hooks.d.ts +4 -0
- package/dist-types/types/plugin.d.ts +5 -1
- package/dist-types/types/rsbuild.d.ts +1 -1
- package/package.json +7 -7
- package/compiled/postcss-load-config/index.d.ts +0 -1
- package/compiled/postcss-load-config/index.js +0 -745
- package/compiled/postcss-load-config/license +0 -20
- package/compiled/postcss-load-config/package.json +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
2
|
let swcHelpersPath, pluginHelper_htmlPlugin, cssExtractPlugin, isDockerCached, cachedResult, hmrClientPath, overlayClientPath;
|
|
3
|
-
import {
|
|
3
|
+
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
|
+
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_os__ from "os";
|
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE_url__ from "url";
|
|
4
12
|
import { logger } from "../compiled/rslog/index.js";
|
|
5
|
-
import node_path, { dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, sep } from "node:path";
|
|
6
|
-
import { URL as external_node_url_URL, fileURLToPath, pathToFileURL } from "node:url";
|
|
7
13
|
import picocolors from "../compiled/picocolors/index.js";
|
|
8
|
-
import node_fs, {
|
|
14
|
+
import node_fs, { existsSync } from "node:fs";
|
|
9
15
|
import { EventEmitter } from "events";
|
|
10
16
|
import node_os, { constants as external_node_os_constants } from "node:os";
|
|
11
17
|
import node_process from "node:process";
|
|
@@ -14,7 +20,7 @@ import { promisify as external_node_util_promisify } from "node:util";
|
|
|
14
20
|
import node_zlib from "node:zlib";
|
|
15
21
|
import { Buffer as external_node_buffer_Buffer } from "node:buffer";
|
|
16
22
|
import node_child_process, { execFile } from "node:child_process";
|
|
17
|
-
import promises from "node:fs/promises";
|
|
23
|
+
import promises, { constants as promises_constants } from "node:fs/promises";
|
|
18
24
|
var superClass, superClass1, EsmMode, __webpack_modules__ = {
|
|
19
25
|
"../../node_modules/.pnpm/clone-deep@4.0.1/node_modules/clone-deep/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
20
26
|
let clone = __webpack_require__("../../node_modules/.pnpm/shallow-clone@3.0.1/node_modules/shallow-clone/index.js"), typeOf = __webpack_require__("../../node_modules/.pnpm/kind-of@6.0.3/node_modules/kind-of/index.js"), isPlainObject = __webpack_require__("../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js");
|
|
@@ -541,6 +547,399 @@ var superClass, superClass1, EsmMode, __webpack_modules__ = {
|
|
|
541
547
|
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
542
548
|
};
|
|
543
549
|
},
|
|
550
|
+
"../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
551
|
+
let path = __webpack_require__("path"), fs = __webpack_require__("fs"), os = __webpack_require__("os"), url = __webpack_require__("url"), fsReadFileAsync = fs.promises.readFile;
|
|
552
|
+
function parentDir(p) {
|
|
553
|
+
return path.dirname(p) || path.sep;
|
|
554
|
+
}
|
|
555
|
+
let jsonLoader = (_, content)=>JSON.parse(content), requireFunc = __WEBPACK_EXTERNAL_createRequire(import.meta.url), defaultLoadersSync = Object.freeze({
|
|
556
|
+
'.js': requireFunc,
|
|
557
|
+
'.json': requireFunc,
|
|
558
|
+
'.cjs': requireFunc,
|
|
559
|
+
noExt: jsonLoader
|
|
560
|
+
});
|
|
561
|
+
module.exports.defaultLoadersSync = defaultLoadersSync;
|
|
562
|
+
let dynamicImport = async (id)=>{
|
|
563
|
+
try {
|
|
564
|
+
let fileUrl = url.pathToFileURL(id).href;
|
|
565
|
+
return (await import(fileUrl)).default;
|
|
566
|
+
} catch (e) {
|
|
567
|
+
try {
|
|
568
|
+
return requireFunc(id);
|
|
569
|
+
} catch (requireE) {
|
|
570
|
+
if ('ERR_REQUIRE_ESM' === requireE.code || requireE instanceof SyntaxError && requireE.toString().includes('Cannot use import statement outside a module')) throw e;
|
|
571
|
+
throw requireE;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}, defaultLoaders = Object.freeze({
|
|
575
|
+
'.js': dynamicImport,
|
|
576
|
+
'.mjs': dynamicImport,
|
|
577
|
+
'.cjs': dynamicImport,
|
|
578
|
+
'.json': jsonLoader,
|
|
579
|
+
noExt: jsonLoader
|
|
580
|
+
});
|
|
581
|
+
function getOptions(name, options, sync) {
|
|
582
|
+
let conf = {
|
|
583
|
+
stopDir: os.homedir(),
|
|
584
|
+
searchPlaces: [
|
|
585
|
+
'package.json',
|
|
586
|
+
`.${name}rc.json`,
|
|
587
|
+
`.${name}rc.js`,
|
|
588
|
+
`.${name}rc.cjs`,
|
|
589
|
+
...sync ? [] : [
|
|
590
|
+
`.${name}rc.mjs`
|
|
591
|
+
],
|
|
592
|
+
`.config/${name}rc`,
|
|
593
|
+
`.config/${name}rc.json`,
|
|
594
|
+
`.config/${name}rc.js`,
|
|
595
|
+
`.config/${name}rc.cjs`,
|
|
596
|
+
...sync ? [] : [
|
|
597
|
+
`.config/${name}rc.mjs`
|
|
598
|
+
],
|
|
599
|
+
`${name}.config.js`,
|
|
600
|
+
`${name}.config.cjs`,
|
|
601
|
+
...sync ? [] : [
|
|
602
|
+
`${name}.config.mjs`
|
|
603
|
+
]
|
|
604
|
+
],
|
|
605
|
+
ignoreEmptySearchPlaces: !0,
|
|
606
|
+
cache: !0,
|
|
607
|
+
transform: (x)=>x,
|
|
608
|
+
packageProp: [
|
|
609
|
+
name
|
|
610
|
+
],
|
|
611
|
+
...options,
|
|
612
|
+
loaders: {
|
|
613
|
+
...sync ? defaultLoadersSync : defaultLoaders,
|
|
614
|
+
...options.loaders
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
return conf.searchPlaces.forEach((place)=>{
|
|
618
|
+
let key = path.extname(place) || 'noExt', loader = conf.loaders[key];
|
|
619
|
+
if (!loader) throw Error(`Missing loader for extension "${place}"`);
|
|
620
|
+
if ('function' != typeof loader) throw Error(`Loader for extension "${place}" is not a function: Received ${typeof loader}.`);
|
|
621
|
+
}), conf;
|
|
622
|
+
}
|
|
623
|
+
function getPackageProp(props, obj) {
|
|
624
|
+
return 'string' == typeof props && props in obj ? obj[props] : (Array.isArray(props) ? props : props.split('.')).reduce((acc, prop)=>void 0 === acc ? acc : acc[prop], obj) || null;
|
|
625
|
+
}
|
|
626
|
+
function validateFilePath(filepath) {
|
|
627
|
+
if (!filepath) throw Error('load must pass a non-empty string');
|
|
628
|
+
}
|
|
629
|
+
function validateLoader(loader, ext) {
|
|
630
|
+
if (!loader) throw Error(`No loader specified for extension "${ext}"`);
|
|
631
|
+
if ('function' != typeof loader) throw Error('loader is not a function');
|
|
632
|
+
}
|
|
633
|
+
module.exports.defaultLoaders = defaultLoaders;
|
|
634
|
+
let makeEmplace = (enableCache)=>(c, filepath, res)=>(enableCache && c.set(filepath, res), res);
|
|
635
|
+
module.exports.lilconfig = function(name, options) {
|
|
636
|
+
let { ignoreEmptySearchPlaces, loaders, packageProp, searchPlaces, stopDir, transform, cache } = getOptions(name, options ?? {}, !1), searchCache = new Map(), loadCache = new Map(), emplace = makeEmplace(cache);
|
|
637
|
+
return {
|
|
638
|
+
async search (searchFrom = process.cwd()) {
|
|
639
|
+
let result = {
|
|
640
|
+
config: null,
|
|
641
|
+
filepath: ''
|
|
642
|
+
}, visited = new Set(), dir = searchFrom;
|
|
643
|
+
dirLoop: for(;;){
|
|
644
|
+
if (cache) {
|
|
645
|
+
let r = searchCache.get(dir);
|
|
646
|
+
if (void 0 !== r) {
|
|
647
|
+
for (let p of visited)searchCache.set(p, r);
|
|
648
|
+
return r;
|
|
649
|
+
}
|
|
650
|
+
visited.add(dir);
|
|
651
|
+
}
|
|
652
|
+
for (let searchPlace of searchPlaces){
|
|
653
|
+
let filepath = path.join(dir, searchPlace);
|
|
654
|
+
try {
|
|
655
|
+
await fs.promises.access(filepath);
|
|
656
|
+
} catch {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
let content = String(await fsReadFileAsync(filepath)), loaderKey = path.extname(searchPlace) || 'noExt', loader = loaders[loaderKey];
|
|
660
|
+
if ('package.json' === searchPlace) {
|
|
661
|
+
let maybeConfig = getPackageProp(packageProp, await loader(filepath, content));
|
|
662
|
+
if (null != maybeConfig) {
|
|
663
|
+
result.config = maybeConfig, result.filepath = filepath;
|
|
664
|
+
break dirLoop;
|
|
665
|
+
}
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
let isEmpty = '' === content.trim();
|
|
669
|
+
if (!isEmpty || !ignoreEmptySearchPlaces) {
|
|
670
|
+
isEmpty ? (result.isEmpty = !0, result.config = void 0) : (validateLoader(loader, loaderKey), result.config = await loader(filepath, content)), result.filepath = filepath;
|
|
671
|
+
break dirLoop;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (dir === stopDir || dir === parentDir(dir)) break;
|
|
675
|
+
dir = parentDir(dir);
|
|
676
|
+
}
|
|
677
|
+
let transformed = '' === result.filepath && null === result.config ? transform(null) : transform(result);
|
|
678
|
+
if (cache) for (let p of visited)searchCache.set(p, transformed);
|
|
679
|
+
return transformed;
|
|
680
|
+
},
|
|
681
|
+
async load (filepath) {
|
|
682
|
+
validateFilePath(filepath);
|
|
683
|
+
let absPath = path.resolve(process.cwd(), filepath);
|
|
684
|
+
if (cache && loadCache.has(absPath)) return loadCache.get(absPath);
|
|
685
|
+
let { base, ext } = path.parse(absPath), loaderKey = ext || 'noExt', loader = loaders[loaderKey];
|
|
686
|
+
validateLoader(loader, loaderKey);
|
|
687
|
+
let content = String(await fsReadFileAsync(absPath));
|
|
688
|
+
if ('package.json' === base) {
|
|
689
|
+
let pkg = await loader(absPath, content);
|
|
690
|
+
return emplace(loadCache, absPath, transform({
|
|
691
|
+
config: getPackageProp(packageProp, pkg),
|
|
692
|
+
filepath: absPath
|
|
693
|
+
}));
|
|
694
|
+
}
|
|
695
|
+
let result = {
|
|
696
|
+
config: null,
|
|
697
|
+
filepath: absPath
|
|
698
|
+
}, isEmpty = '' === content.trim();
|
|
699
|
+
return isEmpty && ignoreEmptySearchPlaces ? emplace(loadCache, absPath, transform({
|
|
700
|
+
config: void 0,
|
|
701
|
+
filepath: absPath,
|
|
702
|
+
isEmpty: !0
|
|
703
|
+
})) : (result.config = isEmpty ? void 0 : await loader(absPath, content), emplace(loadCache, absPath, transform(isEmpty ? {
|
|
704
|
+
...result,
|
|
705
|
+
isEmpty,
|
|
706
|
+
config: void 0
|
|
707
|
+
} : result)));
|
|
708
|
+
},
|
|
709
|
+
clearLoadCache () {
|
|
710
|
+
cache && loadCache.clear();
|
|
711
|
+
},
|
|
712
|
+
clearSearchCache () {
|
|
713
|
+
cache && searchCache.clear();
|
|
714
|
+
},
|
|
715
|
+
clearCaches () {
|
|
716
|
+
cache && (loadCache.clear(), searchCache.clear());
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
}, module.exports.lilconfigSync = function(name, options) {
|
|
720
|
+
let { ignoreEmptySearchPlaces, loaders, packageProp, searchPlaces, stopDir, transform, cache } = getOptions(name, options ?? {}, !0), searchCache = new Map(), loadCache = new Map(), emplace = makeEmplace(cache);
|
|
721
|
+
return {
|
|
722
|
+
search (searchFrom = process.cwd()) {
|
|
723
|
+
let result = {
|
|
724
|
+
config: null,
|
|
725
|
+
filepath: ''
|
|
726
|
+
}, visited = new Set(), dir = searchFrom;
|
|
727
|
+
dirLoop: for(;;){
|
|
728
|
+
if (cache) {
|
|
729
|
+
let r = searchCache.get(dir);
|
|
730
|
+
if (void 0 !== r) {
|
|
731
|
+
for (let p of visited)searchCache.set(p, r);
|
|
732
|
+
return r;
|
|
733
|
+
}
|
|
734
|
+
visited.add(dir);
|
|
735
|
+
}
|
|
736
|
+
for (let searchPlace of searchPlaces){
|
|
737
|
+
let filepath = path.join(dir, searchPlace);
|
|
738
|
+
try {
|
|
739
|
+
fs.accessSync(filepath);
|
|
740
|
+
} catch {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
let loaderKey = path.extname(searchPlace) || 'noExt', loader = loaders[loaderKey], content = String(fs.readFileSync(filepath));
|
|
744
|
+
if ('package.json' === searchPlace) {
|
|
745
|
+
let maybeConfig = getPackageProp(packageProp, loader(filepath, content));
|
|
746
|
+
if (null != maybeConfig) {
|
|
747
|
+
result.config = maybeConfig, result.filepath = filepath;
|
|
748
|
+
break dirLoop;
|
|
749
|
+
}
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
let isEmpty = '' === content.trim();
|
|
753
|
+
if (!isEmpty || !ignoreEmptySearchPlaces) {
|
|
754
|
+
isEmpty ? (result.isEmpty = !0, result.config = void 0) : (validateLoader(loader, loaderKey), result.config = loader(filepath, content)), result.filepath = filepath;
|
|
755
|
+
break dirLoop;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (dir === stopDir || dir === parentDir(dir)) break;
|
|
759
|
+
dir = parentDir(dir);
|
|
760
|
+
}
|
|
761
|
+
let transformed = '' === result.filepath && null === result.config ? transform(null) : transform(result);
|
|
762
|
+
if (cache) for (let p of visited)searchCache.set(p, transformed);
|
|
763
|
+
return transformed;
|
|
764
|
+
},
|
|
765
|
+
load (filepath) {
|
|
766
|
+
validateFilePath(filepath);
|
|
767
|
+
let absPath = path.resolve(process.cwd(), filepath);
|
|
768
|
+
if (cache && loadCache.has(absPath)) return loadCache.get(absPath);
|
|
769
|
+
let { base, ext } = path.parse(absPath), loaderKey = ext || 'noExt', loader = loaders[loaderKey];
|
|
770
|
+
validateLoader(loader, loaderKey);
|
|
771
|
+
let content = String(fs.readFileSync(absPath));
|
|
772
|
+
if ('package.json' === base) return transform({
|
|
773
|
+
config: getPackageProp(packageProp, loader(absPath, content)),
|
|
774
|
+
filepath: absPath
|
|
775
|
+
});
|
|
776
|
+
let result = {
|
|
777
|
+
config: null,
|
|
778
|
+
filepath: absPath
|
|
779
|
+
}, isEmpty = '' === content.trim();
|
|
780
|
+
return isEmpty && ignoreEmptySearchPlaces ? emplace(loadCache, absPath, transform({
|
|
781
|
+
filepath: absPath,
|
|
782
|
+
config: void 0,
|
|
783
|
+
isEmpty: !0
|
|
784
|
+
})) : (result.config = isEmpty ? void 0 : loader(absPath, content), emplace(loadCache, absPath, transform(isEmpty ? {
|
|
785
|
+
...result,
|
|
786
|
+
isEmpty,
|
|
787
|
+
config: void 0
|
|
788
|
+
} : result)));
|
|
789
|
+
},
|
|
790
|
+
clearLoadCache () {
|
|
791
|
+
cache && loadCache.clear();
|
|
792
|
+
},
|
|
793
|
+
clearSearchCache () {
|
|
794
|
+
cache && searchCache.clear();
|
|
795
|
+
},
|
|
796
|
+
clearCaches () {
|
|
797
|
+
cache && (loadCache.clear(), searchCache.clear());
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
};
|
|
801
|
+
},
|
|
802
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
803
|
+
let yaml, { resolve } = __webpack_require__("node:path"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/req.js");
|
|
804
|
+
async function processResult(ctx, result) {
|
|
805
|
+
let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
|
|
806
|
+
default: obj
|
|
807
|
+
}).default || {};
|
|
808
|
+
(projectConfig = 'function' == typeof projectConfig ? projectConfig(ctx) : Object.assign({}, projectConfig, ctx)).plugins || (projectConfig.plugins = []);
|
|
809
|
+
let res = {
|
|
810
|
+
file,
|
|
811
|
+
options: await loadOptions(projectConfig, file),
|
|
812
|
+
plugins: await loadPlugins(projectConfig, file)
|
|
813
|
+
};
|
|
814
|
+
return delete projectConfig.plugins, res;
|
|
815
|
+
}
|
|
816
|
+
async function loader(filepath) {
|
|
817
|
+
return req(filepath);
|
|
818
|
+
}
|
|
819
|
+
async function yamlLoader(_, content) {
|
|
820
|
+
if (!yaml) try {
|
|
821
|
+
yaml = await import("yaml");
|
|
822
|
+
} catch (e) {
|
|
823
|
+
throw Error(`'yaml' is required for the YAML configuration files. Make sure it is installed\nError: ${e.message}`);
|
|
824
|
+
}
|
|
825
|
+
return yaml.parse(content);
|
|
826
|
+
}
|
|
827
|
+
module.exports = function(ctx, path, options) {
|
|
828
|
+
var ctx1;
|
|
829
|
+
return ctx1 = ctx, (ctx1 = Object.assign({
|
|
830
|
+
cwd: process.cwd(),
|
|
831
|
+
env: process.env.NODE_ENV
|
|
832
|
+
}, ctx1)).env || (process.env.NODE_ENV = 'development'), ctx = ctx1, path = path ? resolve(path) : process.cwd(), config.lilconfig('postcss', ((options = {})=>{
|
|
833
|
+
let moduleName = 'postcss';
|
|
834
|
+
return {
|
|
835
|
+
...options,
|
|
836
|
+
loaders: {
|
|
837
|
+
...options.loaders,
|
|
838
|
+
'.cjs': loader,
|
|
839
|
+
'.cts': loader,
|
|
840
|
+
'.js': loader,
|
|
841
|
+
'.mjs': loader,
|
|
842
|
+
'.mts': loader,
|
|
843
|
+
'.ts': loader,
|
|
844
|
+
'.yaml': yamlLoader,
|
|
845
|
+
'.yml': yamlLoader
|
|
846
|
+
},
|
|
847
|
+
searchPlaces: [
|
|
848
|
+
...options.searchPlaces || [],
|
|
849
|
+
'package.json',
|
|
850
|
+
`.${moduleName}rc`,
|
|
851
|
+
`.${moduleName}rc.json`,
|
|
852
|
+
`.${moduleName}rc.yaml`,
|
|
853
|
+
`.${moduleName}rc.yml`,
|
|
854
|
+
`.${moduleName}rc.ts`,
|
|
855
|
+
`.${moduleName}rc.cts`,
|
|
856
|
+
`.${moduleName}rc.mts`,
|
|
857
|
+
`.${moduleName}rc.js`,
|
|
858
|
+
`.${moduleName}rc.cjs`,
|
|
859
|
+
`.${moduleName}rc.mjs`,
|
|
860
|
+
`${moduleName}.config.ts`,
|
|
861
|
+
`${moduleName}.config.cts`,
|
|
862
|
+
`${moduleName}.config.mts`,
|
|
863
|
+
`${moduleName}.config.js`,
|
|
864
|
+
`${moduleName}.config.cjs`,
|
|
865
|
+
`${moduleName}.config.mjs`
|
|
866
|
+
]
|
|
867
|
+
};
|
|
868
|
+
})(options)).search(path).then((result)=>{
|
|
869
|
+
if (!result) throw Error(`No PostCSS Config found in: ${path}`);
|
|
870
|
+
return processResult(ctx, result);
|
|
871
|
+
});
|
|
872
|
+
};
|
|
873
|
+
},
|
|
874
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/options.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
875
|
+
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/req.js");
|
|
876
|
+
module.exports = async function(config, file) {
|
|
877
|
+
if (config.parser && 'string' == typeof config.parser) try {
|
|
878
|
+
config.parser = await req(config.parser, file);
|
|
879
|
+
} catch (err) {
|
|
880
|
+
throw Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`);
|
|
881
|
+
}
|
|
882
|
+
if (config.syntax && 'string' == typeof config.syntax) try {
|
|
883
|
+
config.syntax = await req(config.syntax, file);
|
|
884
|
+
} catch (err) {
|
|
885
|
+
throw Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`);
|
|
886
|
+
}
|
|
887
|
+
if (config.stringifier && 'string' == typeof config.stringifier) try {
|
|
888
|
+
config.stringifier = await req(config.stringifier, file);
|
|
889
|
+
} catch (err) {
|
|
890
|
+
throw Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`);
|
|
891
|
+
}
|
|
892
|
+
return config;
|
|
893
|
+
};
|
|
894
|
+
},
|
|
895
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/plugins.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
896
|
+
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/req.js");
|
|
897
|
+
async function load(plugin, options, file) {
|
|
898
|
+
try {
|
|
899
|
+
if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
|
|
900
|
+
return (await req(plugin, file))(options);
|
|
901
|
+
} catch (err) {
|
|
902
|
+
throw Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
module.exports = async function(config, file) {
|
|
906
|
+
let list = [];
|
|
907
|
+
return Array.isArray(config.plugins) ? list = config.plugins.filter(Boolean) : (list = Object.entries(config.plugins).filter(([, options])=>!1 !== options).map(([plugin, options])=>load(plugin, options, file)), list = await Promise.all(list)), list.length && list.length > 0 && list.forEach((plugin, i)=>{
|
|
908
|
+
if (plugin.default && (plugin = plugin.default), !0 === plugin.postcss ? plugin = plugin() : plugin.postcss && (plugin = plugin.postcss), !('object' == typeof plugin && Array.isArray(plugin.plugins) || 'object' == typeof plugin && plugin.postcssPlugin || 'function' == typeof plugin)) throw TypeError(`Invalid PostCSS Plugin found at: plugins[${i}]\n\n(@${file})`);
|
|
909
|
+
}), list;
|
|
910
|
+
};
|
|
911
|
+
},
|
|
912
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/req.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
913
|
+
let tsx, jiti;
|
|
914
|
+
var __filename = __webpack_fileURLToPath__(import.meta.url);
|
|
915
|
+
let { createRequire } = __webpack_require__("node:module"), { pathToFileURL } = __webpack_require__("node:url"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
916
|
+
module.exports = async function(name, rootFile = __filename) {
|
|
917
|
+
let url = createRequire(rootFile).resolve(name);
|
|
918
|
+
try {
|
|
919
|
+
return (await import(`${pathToFileURL(url)}?t=${Date.now()}`)).default;
|
|
920
|
+
} catch (err) {
|
|
921
|
+
if (!TS_EXT_RE.test(url)) throw err;
|
|
922
|
+
}
|
|
923
|
+
if (void 0 === tsx) try {
|
|
924
|
+
tsx = await import("tsx/cjs/api");
|
|
925
|
+
} catch (error) {
|
|
926
|
+
importError.push(error);
|
|
927
|
+
}
|
|
928
|
+
if (tsx) {
|
|
929
|
+
let loaded = tsx.require(name, rootFile);
|
|
930
|
+
return loaded && '__esModule' in loaded ? loaded.default : loaded;
|
|
931
|
+
}
|
|
932
|
+
if (void 0 === jiti) try {
|
|
933
|
+
jiti = (await import("jiti")).default;
|
|
934
|
+
} catch (error) {
|
|
935
|
+
importError.push(error);
|
|
936
|
+
}
|
|
937
|
+
if (jiti) return jiti(rootFile, {
|
|
938
|
+
interopDefault: !0
|
|
939
|
+
})(name);
|
|
940
|
+
throw Error(`'tsx' or 'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${importError.map((error)=>error.message).join('\n')}`);
|
|
941
|
+
};
|
|
942
|
+
},
|
|
544
943
|
"../../node_modules/.pnpm/shallow-clone@3.0.1/node_modules/shallow-clone/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
545
944
|
let valueOf = Symbol.prototype.valueOf, typeOf = __webpack_require__("../../node_modules/.pnpm/kind-of@6.0.3/node_modules/kind-of/index.js");
|
|
546
945
|
module.exports = function(val, deep) {
|
|
@@ -1010,6 +1409,27 @@ var superClass, superClass1, EsmMode, __webpack_modules__ = {
|
|
|
1010
1409
|
var matcher = new WildcardMatcher(text, separator || /[\/\.]/);
|
|
1011
1410
|
return void 0 !== test ? matcher.match(test) : matcher;
|
|
1012
1411
|
};
|
|
1412
|
+
},
|
|
1413
|
+
fs: function(module) {
|
|
1414
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_fs__;
|
|
1415
|
+
},
|
|
1416
|
+
"node:module": function(module) {
|
|
1417
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__;
|
|
1418
|
+
},
|
|
1419
|
+
"node:path": function(module) {
|
|
1420
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
|
|
1421
|
+
},
|
|
1422
|
+
"node:url": function(module) {
|
|
1423
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
|
|
1424
|
+
},
|
|
1425
|
+
os: function(module) {
|
|
1426
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_os__;
|
|
1427
|
+
},
|
|
1428
|
+
path: function(module) {
|
|
1429
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
1430
|
+
},
|
|
1431
|
+
url: function(module) {
|
|
1432
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_url__;
|
|
1013
1433
|
}
|
|
1014
1434
|
}, __webpack_module_cache__ = {};
|
|
1015
1435
|
function __webpack_require__(moduleId) {
|
|
@@ -1054,8 +1474,9 @@ __webpack_require__.r(provider_helpers_namespaceObject), __webpack_require__.d(p
|
|
|
1054
1474
|
setCssExtractPlugin: ()=>setCssExtractPlugin,
|
|
1055
1475
|
setHTMLPlugin: ()=>setHTMLPlugin
|
|
1056
1476
|
});
|
|
1057
|
-
|
|
1058
|
-
|
|
1477
|
+
var external_node_module_ = __webpack_require__("node:module");
|
|
1478
|
+
let rspack_rspack = (0, external_node_module_.createRequire)(import.meta.url)('@rspack/core');
|
|
1479
|
+
var external_node_path_ = __webpack_require__("node:path"), external_node_url_ = __webpack_require__("node:url"), cjs = __webpack_require__("../../node_modules/.pnpm/deepmerge@4.3.1/node_modules/deepmerge/dist/cjs.js"), cjs_default = __webpack_require__.n(cjs), dist = __webpack_require__("../../node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/index.js");
|
|
1059
1480
|
function createMap(superClass) {
|
|
1060
1481
|
return class extends superClass {
|
|
1061
1482
|
extend(methods) {
|
|
@@ -1782,11 +2203,12 @@ class src_class extends ChainedMap {
|
|
|
1782
2203
|
'recordsOutputPath',
|
|
1783
2204
|
'name',
|
|
1784
2205
|
'infrastructureLogging',
|
|
1785
|
-
'snapshot'
|
|
2206
|
+
'snapshot',
|
|
2207
|
+
'lazyCompilation'
|
|
1786
2208
|
]);
|
|
1787
2209
|
}
|
|
1788
2210
|
}
|
|
1789
|
-
let constants_filename = fileURLToPath(import.meta.url), constants_dirname = dirname(constants_filename), ROOT_DIST_DIR = 'dist', LOADER_PATH = join(constants_dirname), STATIC_PATH = join(constants_dirname, '../static'), COMPILED_PATH = join(constants_dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
|
|
2211
|
+
let constants_filename = (0, external_node_url_.fileURLToPath)(import.meta.url), constants_dirname = (0, external_node_path_.dirname)(constants_filename), ROOT_DIST_DIR = 'dist', LOADER_PATH = (0, external_node_path_.join)(constants_dirname), STATIC_PATH = (0, external_node_path_.join)(constants_dirname, '../static'), COMPILED_PATH = (0, external_node_path_.join)(constants_dirname, '../compiled'), RSBUILD_OUTPUTS_PATH = '.rsbuild', DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_ASSET_PREFIX = '/', DEFAULT_WEB_BROWSERSLIST = [
|
|
1790
2212
|
'chrome >= 87',
|
|
1791
2213
|
'edge >= 88',
|
|
1792
2214
|
'firefox >= 78',
|
|
@@ -1832,18 +2254,17 @@ let constants_filename = fileURLToPath(import.meta.url), constants_dirname = dir
|
|
|
1832
2254
|
'aac',
|
|
1833
2255
|
'm4a',
|
|
1834
2256
|
'opus'
|
|
1835
|
-
], getCompiledPath = (packageName)=>join(COMPILED_PATH, packageName, 'index.js'), ensureAbsolutePath = (base, filePath)=>
|
|
2257
|
+
], getCompiledPath = (packageName)=>(0, external_node_path_.join)(COMPILED_PATH, packageName, 'index.js'), ensureAbsolutePath = (base, filePath)=>(0, external_node_path_.isAbsolute)(filePath) ? filePath : (0, external_node_path_.join)(base, filePath), getPathnameFromUrl = (publicPath)=>{
|
|
1836
2258
|
try {
|
|
1837
2259
|
return publicPath ? new URL(publicPath).pathname : publicPath;
|
|
1838
2260
|
} catch {
|
|
1839
2261
|
return publicPath;
|
|
1840
2262
|
}
|
|
1841
|
-
}, dedupeNestedPaths = (paths)=>paths.sort((p1, p2)=>p2.length > p1.length ? -1 : 1).reduce((prev, curr)=>prev.find((p)=>curr.startsWith(p) || curr === p) ? prev : prev.concat(curr), []), toPosixPath = (filepath)=>'/' === sep ? filepath : filepath.replace(/\\/g, '/'), isFileSync = (filePath)=>{
|
|
2263
|
+
}, dedupeNestedPaths = (paths)=>paths.sort((p1, p2)=>p2.length > p1.length ? -1 : 1).reduce((prev, curr)=>prev.find((p)=>curr.startsWith(p) || curr === p) ? prev : prev.concat(curr), []), toPosixPath = (filepath)=>'/' === external_node_path_.sep ? filepath : filepath.replace(/\\/g, '/'), isFileSync = (filePath)=>{
|
|
1842
2264
|
try {
|
|
1843
|
-
|
|
1844
|
-
return null == (_fs_statSync = node_fs.statSync(filePath, {
|
|
2265
|
+
return node_fs.statSync(filePath, {
|
|
1845
2266
|
throwIfNoEntry: !1
|
|
1846
|
-
})
|
|
2267
|
+
})?.isFile();
|
|
1847
2268
|
} catch (_) {
|
|
1848
2269
|
return !1;
|
|
1849
2270
|
}
|
|
@@ -1861,7 +2282,7 @@ async function fileExistsByCompilation({ inputFileSystem }, filePath) {
|
|
|
1861
2282
|
return new Promise((resolve)=>{
|
|
1862
2283
|
if (!inputFileSystem) return void resolve(!1);
|
|
1863
2284
|
inputFileSystem.stat(filePath, (err, stats)=>{
|
|
1864
|
-
err ? resolve(!1) : resolve(!!
|
|
2285
|
+
err ? resolve(!1) : resolve(!!stats?.isFile());
|
|
1865
2286
|
});
|
|
1866
2287
|
});
|
|
1867
2288
|
}
|
|
@@ -1871,7 +2292,7 @@ async function emptyDir(dir, keep = [], checkExists = !0) {
|
|
|
1871
2292
|
withFileTypes: !0
|
|
1872
2293
|
});
|
|
1873
2294
|
await Promise.all(entries.map(async (entry)=>{
|
|
1874
|
-
let fullPath =
|
|
2295
|
+
let fullPath = external_node_path_.default.join(dir, entry.name);
|
|
1875
2296
|
!keep.some((reg)=>reg.test(toPosixPath(fullPath))) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await node_fs.promises.rmdir(fullPath)) : await node_fs.promises.unlink(fullPath));
|
|
1876
2297
|
}));
|
|
1877
2298
|
} catch (err) {
|
|
@@ -1997,16 +2418,12 @@ function formatMessage(stats, verbose) {
|
|
|
1997
2418
|
}(message))).split('\n').filter((line, index, arr)=>0 === index || '' !== line.trim() || line.trim() !== arr[index - 1].trim()).join('\n')).trim();
|
|
1998
2419
|
}
|
|
1999
2420
|
function formatStatsMessages(stats, verbose) {
|
|
2000
|
-
var _stats_errors, _stats_warnings;
|
|
2001
2421
|
return {
|
|
2002
|
-
errors:
|
|
2003
|
-
warnings:
|
|
2422
|
+
errors: stats.errors?.map((error)=>formatMessage(error, verbose)) || [],
|
|
2423
|
+
warnings: stats.warnings?.map((warning)=>formatMessage(warning, verbose)) || []
|
|
2004
2424
|
};
|
|
2005
2425
|
}
|
|
2006
|
-
let getAllStatsErrors = (statsData)=>{
|
|
2007
|
-
var _statsData_errors, _statsData_children;
|
|
2008
|
-
return statsData.errorsCount && (null == (_statsData_errors = statsData.errors) ? void 0 : _statsData_errors.length) === 0 ? null == (_statsData_children = statsData.children) ? void 0 : _statsData_children.reduce((errors, curr)=>errors.concat(curr.errors || []), []) : statsData.errors;
|
|
2009
|
-
}, getAssetsFromStats = (stats)=>stats.toJson({
|
|
2426
|
+
let getAllStatsErrors = (statsData)=>statsData.errorsCount && statsData.errors?.length === 0 ? statsData.children?.reduce((errors, curr)=>errors.concat(curr.errors || []), []) : statsData.errors, getAssetsFromStats = (stats)=>stats.toJson({
|
|
2010
2427
|
all: !1,
|
|
2011
2428
|
assets: !0,
|
|
2012
2429
|
cachedAssets: !0,
|
|
@@ -2015,10 +2432,7 @@ let getAllStatsErrors = (statsData)=>{
|
|
|
2015
2432
|
groupAssetsByChunk: !1,
|
|
2016
2433
|
groupAssetsByExtension: !1,
|
|
2017
2434
|
groupAssetsByEmitStatus: !1
|
|
2018
|
-
}).assets || [], getAllStatsWarnings = (statsData)=>
|
|
2019
|
-
var _statsData_warnings, _statsData_children;
|
|
2020
|
-
return statsData.warningsCount && (null == (_statsData_warnings = statsData.warnings) ? void 0 : _statsData_warnings.length) === 0 ? null == (_statsData_children = statsData.children) ? void 0 : _statsData_children.reduce((warnings, curr)=>warnings.concat(curr.warnings || []), []) : statsData.warnings;
|
|
2021
|
-
};
|
|
2435
|
+
}).assets || [], getAllStatsWarnings = (statsData)=>statsData.warningsCount && statsData.warnings?.length === 0 ? statsData.children?.reduce((warnings, curr)=>warnings.concat(curr.warnings || []), []) : statsData.warnings;
|
|
2022
2436
|
function getStatsOptions(compiler) {
|
|
2023
2437
|
if (helpers_isMultiCompiler(compiler)) return {
|
|
2024
2438
|
children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
|
|
@@ -2072,33 +2486,36 @@ let rspackMinVersion = '1.2.4', setNodeEnv = (env)=>{
|
|
|
2072
2486
|
return 'string' == typeof publicPath ? 'auto' === publicPath ? '' : publicPath.endsWith('/') ? publicPath : `${publicPath}/` : DEFAULT_ASSET_PREFIX;
|
|
2073
2487
|
}, urlJoin = (base, path)=>{
|
|
2074
2488
|
let [urlProtocol, baseUrl] = base.split('://');
|
|
2075
|
-
return `${urlProtocol}://${posix.join(baseUrl, path)}`;
|
|
2489
|
+
return `${urlProtocol}://${external_node_path_.posix.join(baseUrl, path)}`;
|
|
2076
2490
|
}, canParse = (url)=>{
|
|
2077
2491
|
try {
|
|
2078
|
-
return new
|
|
2492
|
+
return new external_node_url_.URL(url), !0;
|
|
2079
2493
|
} catch {
|
|
2080
2494
|
return !1;
|
|
2081
2495
|
}
|
|
2082
|
-
}, ensureAssetPrefix = (url, assetPrefix = DEFAULT_ASSET_PREFIX)=>url.startsWith('//') || canParse(url) || 'auto' === assetPrefix || 'function' == typeof assetPrefix ? url : assetPrefix.startsWith('http') ? urlJoin(assetPrefix, url) : assetPrefix.startsWith('//') ? urlJoin(`https:${assetPrefix}`, url).replace('https:', '') : posix.join(assetPrefix, url);
|
|
2496
|
+
}, ensureAssetPrefix = (url, assetPrefix = DEFAULT_ASSET_PREFIX)=>url.startsWith('//') || canParse(url) || 'auto' === assetPrefix || 'function' == typeof assetPrefix ? url : assetPrefix.startsWith('http') ? urlJoin(assetPrefix, url) : assetPrefix.startsWith('//') ? urlJoin(`https:${assetPrefix}`, url).replace('https:', '') : external_node_path_.posix.join(assetPrefix, url);
|
|
2083
2497
|
function getFilename(config, type, isProd, isServer) {
|
|
2084
|
-
let { filename, filenameHash } = config.output,
|
|
2498
|
+
let { filename, filenameHash } = config.output, getHash = (dot = !0)=>'string' == typeof filenameHash ? filenameHash ? `${dot ? '.' : ''}[${filenameHash}]` : '' : filenameHash ? `${dot ? '.' : ''}[contenthash:8]` : '';
|
|
2085
2499
|
switch(type){
|
|
2086
2500
|
case 'js':
|
|
2087
|
-
return filename.js ?? `[name]${isProd && !isServer ?
|
|
2501
|
+
return filename.js ?? `[name]${isProd && !isServer ? getHash() : ''}.js`;
|
|
2088
2502
|
case 'css':
|
|
2089
|
-
return filename.css ?? `[name]${isProd ?
|
|
2503
|
+
return filename.css ?? `[name]${isProd ? getHash() : ''}.css`;
|
|
2090
2504
|
case 'svg':
|
|
2091
|
-
return filename.svg ?? `[name]${
|
|
2505
|
+
return filename.svg ?? `[name]${getHash()}.svg`;
|
|
2092
2506
|
case 'font':
|
|
2093
|
-
return filename.font ?? `[name]${
|
|
2507
|
+
return filename.font ?? `[name]${getHash()}[ext]`;
|
|
2094
2508
|
case 'image':
|
|
2095
|
-
return filename.image ?? `[name]${
|
|
2509
|
+
return filename.image ?? `[name]${getHash()}[ext]`;
|
|
2096
2510
|
case 'media':
|
|
2097
|
-
return filename.media ?? `[name]${
|
|
2511
|
+
return filename.media ?? `[name]${getHash()}[ext]`;
|
|
2098
2512
|
case 'assets':
|
|
2099
|
-
return filename.assets ?? `[name]${
|
|
2513
|
+
return filename.assets ?? `[name]${getHash()}[ext]`;
|
|
2100
2514
|
case 'wasm':
|
|
2101
|
-
return filename.wasm ??
|
|
2515
|
+
return filename.wasm ?? `${getHash(!1)}.module.wasm`;
|
|
2516
|
+
case 'html':
|
|
2517
|
+
if (filename.html) return filename.html;
|
|
2518
|
+
return 'flat' === config.html.outputStructure ? '[name].html' : '[name]/index.html';
|
|
2102
2519
|
default:
|
|
2103
2520
|
throw Error(`${picocolors.dim('[rsbuild:config]')} unknown key ${picocolors.yellow(type)} in ${picocolors.yellow('output.filename')}`);
|
|
2104
2521
|
}
|
|
@@ -2536,13 +2953,13 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
|
|
|
2536
2953
|
for(let index = 0; index < compilers.length; index++){
|
|
2537
2954
|
let compiler = compilers[index], compilerDone = !1;
|
|
2538
2955
|
(isWatch ? compiler.hooks.watchRun : compiler.hooks.run).tapPromise(name, async ()=>{
|
|
2539
|
-
!compilerDone && (compilerDone = !0, doneCompilers++), waitBeforeCompileDone || (waitBeforeCompileDone =
|
|
2956
|
+
!compilerDone && (compilerDone = !0, doneCompilers++), waitBeforeCompileDone || (waitBeforeCompileDone = beforeCompile?.()), await waitBeforeCompileDone, await beforeEnvironmentCompiler(index);
|
|
2540
2957
|
}), compiler.hooks.invalid.tap(name, ()=>{
|
|
2541
2958
|
compilerDone && (compilerDone = !1, doneCompilers--), doneCompilers <= 0 && (waitBeforeCompileDone = void 0);
|
|
2542
2959
|
});
|
|
2543
2960
|
}
|
|
2544
2961
|
} else (isWatch ? compiler.hooks.watchRun : compiler.hooks.run).tapPromise(name, async ()=>{
|
|
2545
|
-
await
|
|
2962
|
+
await beforeCompile?.(), await beforeEnvironmentCompiler(0);
|
|
2546
2963
|
});
|
|
2547
2964
|
}, onCompileDone = ({ compiler, onDone, onEnvironmentDone, MultiStatsCtor })=>{
|
|
2548
2965
|
if (helpers_isMultiCompiler(compiler)) {
|
|
@@ -2594,7 +3011,7 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
|
|
|
2594
3011
|
environment: environmentList[buildIndex].name,
|
|
2595
3012
|
args: [
|
|
2596
3013
|
{
|
|
2597
|
-
bundlerConfig:
|
|
3014
|
+
bundlerConfig: bundlerConfigs?.[buildIndex],
|
|
2598
3015
|
environment: environmentList[buildIndex],
|
|
2599
3016
|
isWatch,
|
|
2600
3017
|
isFirstCompile
|
|
@@ -2635,13 +3052,19 @@ let onBeforeCompile = ({ compiler, beforeCompile, beforeEnvironmentCompiler, isW
|
|
|
2635
3052
|
environment: environmentList[buildIndex].name,
|
|
2636
3053
|
args: [
|
|
2637
3054
|
{
|
|
2638
|
-
bundlerConfig:
|
|
3055
|
+
bundlerConfig: bundlerConfigs?.[buildIndex],
|
|
2639
3056
|
environment: environmentList[buildIndex],
|
|
2640
3057
|
isWatch: !0,
|
|
2641
3058
|
isFirstCompile
|
|
2642
3059
|
}
|
|
2643
3060
|
]
|
|
2644
3061
|
}),
|
|
3062
|
+
beforeCompile: async ()=>context.hooks.onBeforeDevCompile.callBatch({
|
|
3063
|
+
bundlerConfigs,
|
|
3064
|
+
environments: context.environments,
|
|
3065
|
+
isFirstCompile,
|
|
3066
|
+
isWatch: !0
|
|
3067
|
+
}),
|
|
2645
3068
|
isWatch: !0
|
|
2646
3069
|
}), onCompileDone({
|
|
2647
3070
|
compiler,
|
|
@@ -2700,7 +3123,7 @@ function parseConfig(string) {
|
|
|
2700
3123
|
}), result;
|
|
2701
3124
|
}
|
|
2702
3125
|
function parsePackageOrReadConfig(file) {
|
|
2703
|
-
if ('package.json' ===
|
|
3126
|
+
if ('package.json' === external_node_path_.default.basename(file)) return parsePackage(file);
|
|
2704
3127
|
if (!isFile(file)) throw new BrowserslistError(`Can't read ${file} config`);
|
|
2705
3128
|
return parseConfig(node_fs.readFileSync(file, 'utf-8'));
|
|
2706
3129
|
}
|
|
@@ -2708,11 +3131,11 @@ function pickEnv(config, opts) {
|
|
|
2708
3131
|
return 'object' != typeof config ? config : config['string' == typeof opts.env ? opts.env : process.env.BROWSERSLIST_ENV ? process.env.BROWSERSLIST_ENV : process.env.NODE_ENV ? process.env.NODE_ENV : 'production'] || config.defaults;
|
|
2709
3132
|
}
|
|
2710
3133
|
function eachParent(file, callback) {
|
|
2711
|
-
let dir = isFile(file) ?
|
|
3134
|
+
let dir = isFile(file) ? external_node_path_.default.dirname(file) : file, loc = external_node_path_.default.resolve(dir);
|
|
2712
3135
|
do {
|
|
2713
3136
|
let result = callback(loc);
|
|
2714
3137
|
if (void 0 !== result) return result;
|
|
2715
|
-
}while (loc !== (loc =
|
|
3138
|
+
}while (loc !== (loc = external_node_path_.default.dirname(loc)));
|
|
2716
3139
|
}
|
|
2717
3140
|
let configCache = {}, OVERRIDE_PATHS = [
|
|
2718
3141
|
'performance.removeConsole',
|
|
@@ -2758,7 +3181,7 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
2758
3181
|
merged[key] = merge(x[key], y[key], childPath);
|
|
2759
3182
|
}
|
|
2760
3183
|
return merged;
|
|
2761
|
-
}, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), defaultConfig_require = createRequire(import.meta.url), defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, createDefaultConfig = ()=>({
|
|
3184
|
+
}, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), defaultConfig_require = (0, external_node_module_.createRequire)(import.meta.url), defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, createDefaultConfig = ()=>({
|
|
2762
3185
|
dev: {
|
|
2763
3186
|
hmr: !0,
|
|
2764
3187
|
liveReload: !0,
|
|
@@ -2802,7 +3225,7 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
2802
3225
|
outputStructure: 'flat',
|
|
2803
3226
|
scriptLoading: 'defer'
|
|
2804
3227
|
},
|
|
2805
|
-
resolve: (swcHelpersPath || (swcHelpersPath = dirname(defaultConfig_require.resolve('@swc/helpers/package.json'))), {
|
|
3228
|
+
resolve: (swcHelpersPath || (swcHelpersPath = (0, external_node_path_.dirname)(defaultConfig_require.resolve('@swc/helpers/package.json'))), {
|
|
2806
3229
|
alias: {
|
|
2807
3230
|
'@swc/helpers': swcHelpersPath
|
|
2808
3231
|
},
|
|
@@ -2852,6 +3275,7 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
2852
3275
|
legalComments: 'linked',
|
|
2853
3276
|
injectStyles: !1,
|
|
2854
3277
|
minify: !0,
|
|
3278
|
+
module: !1,
|
|
2855
3279
|
manifest: !1,
|
|
2856
3280
|
sourceMap: {
|
|
2857
3281
|
js: void 0,
|
|
@@ -2893,10 +3317,12 @@ let configCache = {}, OVERRIDE_PATHS = [
|
|
|
2893
3317
|
},
|
|
2894
3318
|
environments: {}
|
|
2895
3319
|
}), withDefaultConfig = async (rootPath, config)=>{
|
|
2896
|
-
var _merged_server, _config_dev, _config_output;
|
|
2897
3320
|
let merged = mergeRsbuildConfig(createDefaultConfig(), config);
|
|
2898
|
-
if (merged.root ||= rootPath, merged.source ||= {},
|
|
2899
|
-
|
|
3321
|
+
if (merged.root ||= rootPath, merged.source ||= {}, merged.server?.base && (config.dev?.assetPrefix === void 0 && (merged.dev ||= {}, merged.dev.assetPrefix = merged.server.base), config.output?.assetPrefix === void 0 && (merged.output ||= {}, merged.output.assetPrefix = merged.server.base)), merged.dev?.lazyCompilation === void 0 && (merged.dev ||= {}, merged.dev.lazyCompilation = {
|
|
3322
|
+
imports: !0,
|
|
3323
|
+
entries: !1
|
|
3324
|
+
}), !merged.source.tsconfigPath) {
|
|
3325
|
+
let tsconfigPath = (0, external_node_path_.join)(rootPath, 'tsconfig.json');
|
|
2900
3326
|
await isFileExists(tsconfigPath) && (merged.source.tsconfigPath = tsconfigPath);
|
|
2901
3327
|
}
|
|
2902
3328
|
return merged;
|
|
@@ -2976,9 +3402,8 @@ async function initPlugins({ context, pluginManager }) {
|
|
|
2976
3402
|
for (let { environment, instance } of plugins)if (instance.remove) if (environment) for (let item of (removedEnvPlugins[environment] ??= new Set(), instance.remove))removedEnvPlugins[environment].add(item);
|
|
2977
3403
|
else for (let item of instance.remove)removedPlugins.add(item);
|
|
2978
3404
|
for (let { instance, environment } of plugins){
|
|
2979
|
-
var _removedEnvPlugins_environment;
|
|
2980
3405
|
let { name, setup } = instance;
|
|
2981
|
-
if (!(removedPlugins.has(name) || environment &&
|
|
3406
|
+
if (!(removedPlugins.has(name) || environment && removedEnvPlugins[environment]?.has(name))) {
|
|
2982
3407
|
if (instance.apply && context.action) if (isFunction(instance.apply)) {
|
|
2983
3408
|
if (!instance.apply(context.originalConfig, {
|
|
2984
3409
|
action: context.action
|
|
@@ -3037,14 +3462,13 @@ let mapProcessAssetsStage = (compiler, stage)=>{
|
|
|
3037
3462
|
}, browsersListCache = new Map(), getEnvironmentHTMLPaths = (entry, config)=>'web' !== config.output.target || !1 === config.tools.htmlPlugin ? {} : Object.keys(entry).reduce((prev, key)=>{
|
|
3038
3463
|
let entryValue = entry[key];
|
|
3039
3464
|
return ('string' == typeof entryValue || Array.isArray(entryValue) || !1 !== entryValue.html) && (prev[key] = function(entryName, config) {
|
|
3040
|
-
let filename;
|
|
3041
|
-
|
|
3042
|
-
let prefix = config.output.distPath.html;
|
|
3043
|
-
return prefix.startsWith('/') && logger.warn(`${picocolors.dim('[rsbuild:config]')} Absolute path is not recommended at ${picocolors.yellow(`output.distPath.html: "${prefix}"`)}, use relative path instead.`), removeLeadingSlash(posix.join(prefix, filename));
|
|
3465
|
+
let filename = getFilename(config, 'html').replace('[name]', entryName), prefix = config.output.distPath.html;
|
|
3466
|
+
return prefix.startsWith('/') && logger.warn(`${picocolors.dim('[rsbuild:config]')} Absolute path is not recommended at ${picocolors.yellow(`output.distPath.html: "${prefix}"`)}, use relative path instead.`), removeLeadingSlash(external_node_path_.posix.join(prefix, filename));
|
|
3044
3467
|
}(key, config)), prev;
|
|
3045
3468
|
}, {});
|
|
3046
3469
|
async function updateEnvironmentContext(context, configs) {
|
|
3047
3470
|
for (let [index, [name, config]] of (context.environments ||= {}, Object.entries(configs).entries())){
|
|
3471
|
+
var cwd;
|
|
3048
3472
|
let browserslist = function(path, config) {
|
|
3049
3473
|
let { target, overrideBrowserslist } = config.output;
|
|
3050
3474
|
if (Array.isArray(overrideBrowserslist)) return overrideBrowserslist;
|
|
@@ -3056,10 +3480,10 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
3056
3480
|
if (opts.config) return pickEnv(parsePackageOrReadConfig(opts.config), opts);
|
|
3057
3481
|
if (opts.path) {
|
|
3058
3482
|
let config = function(from) {
|
|
3059
|
-
let resolved, fromDir = isFile(from =
|
|
3483
|
+
let resolved, fromDir = isFile(from = external_node_path_.default.resolve(from)) ? external_node_path_.default.dirname(from) : from;
|
|
3060
3484
|
if (fromDir in configCache) return configCache[fromDir];
|
|
3061
3485
|
let configFile = eachParent(from, (dir)=>{
|
|
3062
|
-
let pkgBrowserslist, config =
|
|
3486
|
+
let pkgBrowserslist, config = external_node_path_.default.join(dir, 'browserslist'), pkg = external_node_path_.default.join(dir, 'package.json'), rc = external_node_path_.default.join(dir, '.browserslistrc');
|
|
3063
3487
|
if (isFile(pkg)) try {
|
|
3064
3488
|
pkgBrowserslist = parsePackage(pkg);
|
|
3065
3489
|
} catch (e) {
|
|
@@ -3072,7 +3496,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
3072
3496
|
return isFile(config) ? config : isFile(rc) ? rc : pkgBrowserslist ? pkg : void 0;
|
|
3073
3497
|
});
|
|
3074
3498
|
configFile && (resolved = parsePackageOrReadConfig(configFile));
|
|
3075
|
-
let configDir = configFile &&
|
|
3499
|
+
let configDir = configFile && external_node_path_.default.dirname(configFile);
|
|
3076
3500
|
return eachParent(from, (dir)=>{
|
|
3077
3501
|
if (resolved && (configCache[dir] = resolved), dir === configDir) return null;
|
|
3078
3502
|
}), resolved;
|
|
@@ -3092,10 +3516,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
3092
3516
|
}(context.rootPath, config), { entry = {}, tsconfigPath } = config.source, htmlPaths = getEnvironmentHTMLPaths(entry, config), webSocketToken = 'dev' === context.action ? await helpers_hash(context.rootPath + name) : '', environmentContext = {
|
|
3093
3517
|
index,
|
|
3094
3518
|
name,
|
|
3095
|
-
distPath:
|
|
3096
|
-
var _config_output_distPath, _config_output;
|
|
3097
|
-
return ensureAbsolutePath(cwd, (null == (_config_output = config.output) || null == (_config_output_distPath = _config_output.distPath) ? void 0 : _config_output_distPath.root) ?? ROOT_DIST_DIR);
|
|
3098
|
-
}(context.rootPath, config),
|
|
3519
|
+
distPath: (cwd = context.rootPath, ensureAbsolutePath(cwd, config.output?.distPath?.root ?? ROOT_DIST_DIR)),
|
|
3099
3520
|
entry,
|
|
3100
3521
|
browserslist,
|
|
3101
3522
|
htmlPaths,
|
|
@@ -3110,9 +3531,9 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
3110
3531
|
}
|
|
3111
3532
|
}
|
|
3112
3533
|
async function createContext(options, userConfig) {
|
|
3113
|
-
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
3534
|
+
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
3114
3535
|
return {
|
|
3115
|
-
version: "1.
|
|
3536
|
+
version: "1.5.0-beta.1",
|
|
3116
3537
|
rootPath,
|
|
3117
3538
|
distPath: '',
|
|
3118
3539
|
cachePath,
|
|
@@ -3124,6 +3545,7 @@ async function createContext(options, userConfig) {
|
|
|
3124
3545
|
onCloseBuild: createAsyncHook(),
|
|
3125
3546
|
onAfterBuild: createAsyncHook(),
|
|
3126
3547
|
onBeforeBuild: createAsyncHook(),
|
|
3548
|
+
onBeforeDevCompile: createAsyncHook(),
|
|
3127
3549
|
onDevCompileDone: createAsyncHook(),
|
|
3128
3550
|
onCloseDevServer: createAsyncHook(),
|
|
3129
3551
|
onAfterStartDevServer: createAsyncHook(),
|
|
@@ -3159,17 +3581,21 @@ let normalizePluginObject = (plugin)=>{
|
|
|
3159
3581
|
};
|
|
3160
3582
|
async function outputInspectConfigFiles({ rawBundlerConfigs, rawEnvironmentConfigs, inspectOptions, rawExtraConfigs, configType }) {
|
|
3161
3583
|
let { outputPath } = inspectOptions, files = [
|
|
3162
|
-
...rawEnvironmentConfigs.map(({ name, content })=>
|
|
3163
|
-
|
|
3584
|
+
...rawEnvironmentConfigs.map(({ name, content })=>{
|
|
3585
|
+
if (1 === rawEnvironmentConfigs.length) return {
|
|
3586
|
+
path: (0, external_node_path_.join)(outputPath, 'rsbuild.config.mjs'),
|
|
3164
3587
|
label: 'Rsbuild config',
|
|
3165
3588
|
content
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3589
|
+
};
|
|
3590
|
+
let outputFile = `rsbuild.config.${name}.mjs`;
|
|
3591
|
+
return {
|
|
3592
|
+
path: (0, external_node_path_.join)(outputPath, outputFile),
|
|
3168
3593
|
label: `Rsbuild config (${name})`,
|
|
3169
3594
|
content
|
|
3170
|
-
}
|
|
3595
|
+
};
|
|
3596
|
+
}),
|
|
3171
3597
|
...rawBundlerConfigs.map(({ name, content })=>{
|
|
3172
|
-
let
|
|
3598
|
+
let outputFile = `${configType}.config.${name}.mjs`, outputFilePath = (0, external_node_path_.join)(outputPath, outputFile);
|
|
3173
3599
|
return node_fs.existsSync(outputFilePath) && (outputFilePath = outputFilePath.replace(/\.mjs$/, `.${Date.now()}.mjs`)), {
|
|
3174
3600
|
path: outputFilePath,
|
|
3175
3601
|
label: `${upperFirst(configType)} Config (${name})`,
|
|
@@ -3177,7 +3603,7 @@ async function outputInspectConfigFiles({ rawBundlerConfigs, rawEnvironmentConfi
|
|
|
3177
3603
|
};
|
|
3178
3604
|
}),
|
|
3179
3605
|
...(rawExtraConfigs || []).map(({ name, content })=>({
|
|
3180
|
-
path: join(outputPath, `${name}.config.mjs`),
|
|
3606
|
+
path: (0, external_node_path_.join)(outputPath, `${name}.config.mjs`),
|
|
3181
3607
|
label: `${upperFirst(name)} Config`,
|
|
3182
3608
|
content
|
|
3183
3609
|
}))
|
|
@@ -3226,7 +3652,7 @@ async function inspectConfig({ context, pluginManager, bundlerConfigs, inspectOp
|
|
|
3226
3652
|
normalizedConfig: context.normalizedConfig,
|
|
3227
3653
|
inspectOptions,
|
|
3228
3654
|
pluginManager
|
|
3229
|
-
}), outputPath = (context1 = context, (inspectOptions1 = inspectOptions).outputPath ?
|
|
3655
|
+
}), outputPath = (context1 = context, (inspectOptions1 = inspectOptions).outputPath ? (0, external_node_path_.isAbsolute)(inspectOptions1.outputPath) ? inspectOptions1.outputPath : (0, external_node_path_.join)(context1.distPath, inspectOptions1.outputPath) : (0, external_node_path_.join)(context1.distPath, RSBUILD_OUTPUTS_PATH)), rawExtraConfigs = inspectOptions.extraConfigs ? Object.entries(inspectOptions.extraConfigs).map(([name, content])=>({
|
|
3230
3656
|
name,
|
|
3231
3657
|
content: 'string' == typeof content ? content : stringifyConfig(content, inspectOptions.verbose)
|
|
3232
3658
|
})) : void 0;
|
|
@@ -3287,7 +3713,6 @@ function reduceConfigsMergeContext({ initial, config, ctx, mergeFn = Object.assi
|
|
|
3287
3713
|
}
|
|
3288
3714
|
var webpack_merge_dist = __webpack_require__("../../node_modules/.pnpm/webpack-merge@6.0.1/node_modules/webpack-merge/dist/index.js");
|
|
3289
3715
|
async function modifyBundlerChain(context, utils) {
|
|
3290
|
-
var _utils_environment_config_tools;
|
|
3291
3716
|
logger.debug('modify bundler chain');
|
|
3292
3717
|
let bundlerChain = new src_class(), [modifiedBundlerChain] = await context.hooks.modifyBundlerChain.callChain({
|
|
3293
3718
|
environment: utils.environment.name,
|
|
@@ -3296,7 +3721,7 @@ async function modifyBundlerChain(context, utils) {
|
|
|
3296
3721
|
utils
|
|
3297
3722
|
]
|
|
3298
3723
|
});
|
|
3299
|
-
if (
|
|
3724
|
+
if (utils.environment.config.tools?.bundlerChain) for (let item of helpers_castArray(utils.environment.config.tools.bundlerChain))await item(modifiedBundlerChain, utils);
|
|
3300
3725
|
return logger.debug('modify bundler chain done'), modifiedBundlerChain;
|
|
3301
3726
|
}
|
|
3302
3727
|
let configChain_CHAIN_ID = {
|
|
@@ -3381,13 +3806,12 @@ let configChain_CHAIN_ID = {
|
|
|
3381
3806
|
RESOLVE_PLUGIN: {
|
|
3382
3807
|
TS_CONFIG_PATHS: 'ts-config-paths'
|
|
3383
3808
|
}
|
|
3384
|
-
}, pluginHelper_require = createRequire(import.meta.url), setHTMLPlugin = (plugin)=>{
|
|
3809
|
+
}, pluginHelper_require = (0, external_node_module_.createRequire)(import.meta.url), setHTMLPlugin = (plugin)=>{
|
|
3385
3810
|
plugin && (pluginHelper_htmlPlugin = plugin);
|
|
3386
3811
|
}, getHTMLPlugin = ()=>(pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = pluginHelper_require('../compiled/html-rspack-plugin/index.js')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
|
|
3387
3812
|
cssExtractPlugin = plugin;
|
|
3388
3813
|
};
|
|
3389
3814
|
async function modifyRspackConfig(context, rspackConfig, chainUtils) {
|
|
3390
|
-
var _utils_environment_config_tools;
|
|
3391
3815
|
logger.debug('modify Rspack config');
|
|
3392
3816
|
let currentConfig = rspackConfig, utils = getConfigUtils(()=>currentConfig, chainUtils);
|
|
3393
3817
|
if ([currentConfig] = await context.hooks.modifyRspackConfig.callChain({
|
|
@@ -3399,7 +3823,7 @@ async function modifyRspackConfig(context, rspackConfig, chainUtils) {
|
|
|
3399
3823
|
afterEach: ([config])=>{
|
|
3400
3824
|
currentConfig = config;
|
|
3401
3825
|
}
|
|
3402
|
-
}),
|
|
3826
|
+
}), utils.environment.config.tools?.rspack) {
|
|
3403
3827
|
let toolsRspackConfig = utils.environment.config.tools.rspack;
|
|
3404
3828
|
currentConfig = await reduceConfigsAsyncWithContext({
|
|
3405
3829
|
initial: currentConfig,
|
|
@@ -3481,12 +3905,11 @@ let allowedEnvironmentDevKeys = [
|
|
|
3481
3905
|
'lazyCompilation'
|
|
3482
3906
|
];
|
|
3483
3907
|
async function modifyRsbuildConfig(context) {
|
|
3484
|
-
var _context_config_plugins, _modified_plugins;
|
|
3485
3908
|
logger.debug('modify Rsbuild config');
|
|
3486
|
-
let pluginsCount =
|
|
3909
|
+
let pluginsCount = context.config.plugins?.length ?? 0, [modified] = await context.hooks.modifyRsbuildConfig.callChain(context.config, {
|
|
3487
3910
|
mergeRsbuildConfig: mergeRsbuildConfig
|
|
3488
3911
|
});
|
|
3489
|
-
context.config = modified, (
|
|
3912
|
+
context.config = modified, (modified.plugins?.length ?? 0) !== pluginsCount && logger.warn(`${picocolors.dim('[rsbuild]')} Cannot change plugins via ${picocolors.yellow('modifyRsbuildConfig')} as plugins are already initialized when it executes.`), logger.debug('modify Rsbuild config done');
|
|
3490
3913
|
}
|
|
3491
3914
|
async function modifyEnvironmentConfig(context, config, name) {
|
|
3492
3915
|
logger.debug(`modify Rsbuild environment(${name}) config`);
|
|
@@ -3536,7 +3959,7 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
3536
3959
|
'cts',
|
|
3537
3960
|
'mjs',
|
|
3538
3961
|
'cjs'
|
|
3539
|
-
].map((ext)=>join(root, `src/index.${ext}`)));
|
|
3962
|
+
].map((ext)=>(0, external_node_path_.join)(root, `src/index.${ext}`)));
|
|
3540
3963
|
return entryFile ? {
|
|
3541
3964
|
index: entryFile
|
|
3542
3965
|
} : {};
|
|
@@ -3594,13 +4017,13 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
3594
4017
|
...new Set(paths)
|
|
3595
4018
|
];
|
|
3596
4019
|
if (1 === uniquePaths.length) return uniquePaths[0];
|
|
3597
|
-
let [first, ...rest] = uniquePaths.map((p)=>p.split(sep)), common = [];
|
|
4020
|
+
let [first, ...rest] = uniquePaths.map((p)=>p.split(external_node_path_.sep)), common = [];
|
|
3598
4021
|
for(let i = 0; i < first.length; i++){
|
|
3599
4022
|
let segment = first[i];
|
|
3600
4023
|
if (rest.every((p)=>p[i] === segment)) common.push(segment);
|
|
3601
4024
|
else break;
|
|
3602
4025
|
}
|
|
3603
|
-
return common.join(sep);
|
|
4026
|
+
return common.join(external_node_path_.sep);
|
|
3604
4027
|
}(distPaths), ((config)=>{
|
|
3605
4028
|
if (config.server.base && !config.server.base.startsWith('/')) throw Error(`${picocolors.dim('[rsbuild:config]')} The ${picocolors.yellow('"server.base"')} option should start with a slash, for example: "/base"`);
|
|
3606
4029
|
if (!config.environments) return;
|
|
@@ -3647,7 +4070,7 @@ async function initConfigs({ context, pluginManager, rsbuildOptions }) {
|
|
|
3647
4070
|
};
|
|
3648
4071
|
}
|
|
3649
4072
|
function isLikelyFile(filePath) {
|
|
3650
|
-
return (filePath.split(sep).pop() || '').includes('.');
|
|
4073
|
+
return (filePath.split(external_node_path_.sep).pop() || '').includes('.');
|
|
3651
4074
|
}
|
|
3652
4075
|
function formatFileList(paths, rootPath) {
|
|
3653
4076
|
let files = paths.filter(isLikelyFile);
|
|
@@ -3655,10 +4078,10 @@ function formatFileList(paths, rootPath) {
|
|
|
3655
4078
|
paths[0]
|
|
3656
4079
|
]);
|
|
3657
4080
|
let fileInfo = files.slice(0, 1).map((file)=>(function(originalFilePath, root) {
|
|
3658
|
-
let prefix = root.endsWith(sep) ? root : root + sep, filePath = originalFilePath;
|
|
4081
|
+
let prefix = root.endsWith(external_node_path_.sep) ? root : root + external_node_path_.sep, filePath = originalFilePath;
|
|
3659
4082
|
filePath.startsWith(prefix) && (filePath = filePath.slice(prefix.length));
|
|
3660
|
-
let parts = filePath.split(sep).filter(Boolean);
|
|
3661
|
-
return parts.length > 3 ? parts.slice(-3).join(sep) : parts.join(sep);
|
|
4083
|
+
let parts = filePath.split(external_node_path_.sep).filter(Boolean);
|
|
4084
|
+
return parts.length > 3 ? parts.slice(-3).join(external_node_path_.sep) : parts.join(external_node_path_.sep);
|
|
3662
4085
|
})(file, rootPath)).join(', ');
|
|
3663
4086
|
return files.length > 1 ? `${fileInfo} and ${files.length - 1} more` : fileInfo;
|
|
3664
4087
|
}
|
|
@@ -3684,13 +4107,13 @@ async function createCompiler_createCompiler(options) {
|
|
|
3684
4107
|
return compiler.hooks.watchRun.tap('rsbuild:compiling', (compiler)=>{
|
|
3685
4108
|
logRspackVersion(), isCompiling || function(compiler, context) {
|
|
3686
4109
|
let changedFiles = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles) : null;
|
|
3687
|
-
if (
|
|
4110
|
+
if (changedFiles?.length) {
|
|
3688
4111
|
let fileInfo = formatFileList(changedFiles, context.rootPath);
|
|
3689
4112
|
logger.start(`building ${picocolors.dim(fileInfo)}`);
|
|
3690
4113
|
return;
|
|
3691
4114
|
}
|
|
3692
4115
|
let removedFiles = compiler.removedFiles ? Array.from(compiler.removedFiles) : null;
|
|
3693
|
-
if (
|
|
4116
|
+
if (removedFiles?.length) {
|
|
3694
4117
|
let fileInfo = formatFileList(removedFiles, context.rootPath);
|
|
3695
4118
|
logger.start(`building ${picocolors.dim(`removed ${fileInfo}`)}`);
|
|
3696
4119
|
return;
|
|
@@ -3713,12 +4136,9 @@ async function createCompiler_createCompiler(options) {
|
|
|
3713
4136
|
logger.ready(`built in ${time}${suffix}`);
|
|
3714
4137
|
}
|
|
3715
4138
|
}, hasErrors = stats.hasErrors();
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
printTime(c, index);
|
|
3720
|
-
}) : printTime(statsJson, 0);
|
|
3721
|
-
}
|
|
4139
|
+
hasErrors || (isMultiCompiler && statsJson.children?.length ? statsJson.children.forEach((c, index)=>{
|
|
4140
|
+
printTime(c, index);
|
|
4141
|
+
}) : printTime(statsJson, 0));
|
|
3722
4142
|
let { message, level } = formatStats(statsJson, hasErrors);
|
|
3723
4143
|
'error' === level && logger.error(message), 'warning' === level && logger.warn(message), isCompiling = !1;
|
|
3724
4144
|
})(stats);
|
|
@@ -3763,7 +4183,7 @@ let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOption
|
|
|
3763
4183
|
let { stats } = await new Promise((resolve, reject)=>{
|
|
3764
4184
|
compiler.run((err, stats)=>{
|
|
3765
4185
|
compiler.close((closeErr)=>{
|
|
3766
|
-
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) :
|
|
4186
|
+
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : stats?.hasErrors() ? reject(Error(RSPACK_BUILD_ERROR)) : resolve({
|
|
3767
4187
|
stats
|
|
3768
4188
|
});
|
|
3769
4189
|
});
|
|
@@ -3785,7 +4205,7 @@ function loadEnv({ cwd = process.cwd(), mode = process.env.NODE_ENV || '', prefi
|
|
|
3785
4205
|
'.env.local',
|
|
3786
4206
|
`.env.${mode}`,
|
|
3787
4207
|
`.env.${mode}.local`
|
|
3788
|
-
].map((filename)=>join(cwd, filename)).filter(isFileSync), parsed = {};
|
|
4208
|
+
].map((filename)=>(0, external_node_path_.join)(cwd, filename)).filter(isFileSync), parsed = {};
|
|
3789
4209
|
for (let envPath of filePaths)Object.assign(parsed, function(src) {
|
|
3790
4210
|
let match, obj = {}, lines = src.toString();
|
|
3791
4211
|
for(lines = lines.replace(/\r\n?/gm, '\n'); null != (match = DOTENV_LINE.exec(lines));){
|
|
@@ -3826,12 +4246,9 @@ let chainStaticAssetRule = ({ emit, rule, maxSize, filename, assetType })=>{
|
|
|
3826
4246
|
maxSize
|
|
3827
4247
|
}
|
|
3828
4248
|
}).set('generator', generatorOptions);
|
|
3829
|
-
}, isUseAnalyzer = (config)=>
|
|
3830
|
-
var _config_performance;
|
|
3831
|
-
return process.env.BUNDLE_ANALYZE || (null == (_config_performance = config.performance) ? void 0 : _config_performance.bundleAnalyze);
|
|
3832
|
-
};
|
|
4249
|
+
}, isUseAnalyzer = (config)=>process.env.BUNDLE_ANALYZE || config.performance?.bundleAnalyze;
|
|
3833
4250
|
async function validateWebpackCache(cacheDirectory, buildDependencies) {
|
|
3834
|
-
let configFile = join(cacheDirectory, 'buildDependencies.json');
|
|
4251
|
+
let configFile = (0, external_node_path_.join)(cacheDirectory, 'buildDependencies.json');
|
|
3835
4252
|
if (await isFileExists(configFile)) {
|
|
3836
4253
|
let rawConfigFile = await node_fs.promises.readFile(configFile, 'utf-8'), prevBuildDependencies = null;
|
|
3837
4254
|
try {
|
|
@@ -3850,15 +4267,14 @@ async function validateWebpackCache(cacheDirectory, buildDependencies) {
|
|
|
3850
4267
|
}), await node_fs.promises.writeFile(configFile, JSON.stringify(buildDependencies));
|
|
3851
4268
|
}
|
|
3852
4269
|
async function getBuildDependencies(context, config, environmentContext, userBuildDependencies) {
|
|
3853
|
-
|
|
3854
|
-
let rootPackageJson = join(context.rootPath, 'package.json'), browserslistConfig = join(context.rootPath, '.browserslistrc'), buildDependencies = {};
|
|
4270
|
+
let rootPackageJson = (0, external_node_path_.join)(context.rootPath, 'package.json'), browserslistConfig = (0, external_node_path_.join)(context.rootPath, '.browserslistrc'), buildDependencies = {};
|
|
3855
4271
|
await isFileExists(rootPackageJson) && (buildDependencies.packageJson = [
|
|
3856
4272
|
rootPackageJson
|
|
3857
4273
|
]);
|
|
3858
4274
|
let { tsconfigPath } = environmentContext;
|
|
3859
4275
|
tsconfigPath && (buildDependencies.tsconfig = [
|
|
3860
4276
|
tsconfigPath
|
|
3861
|
-
]),
|
|
4277
|
+
]), config._privateMeta?.configFilePath && (buildDependencies.rsbuildConfig = [
|
|
3862
4278
|
config._privateMeta.configFilePath
|
|
3863
4279
|
]), await isFileExists(browserslistConfig) && (buildDependencies.browserslistrc = [
|
|
3864
4280
|
browserslistConfig
|
|
@@ -3868,7 +4284,7 @@ async function getBuildDependencies(context, config, environmentContext, userBui
|
|
|
3868
4284
|
'js',
|
|
3869
4285
|
'cjs',
|
|
3870
4286
|
'mjs'
|
|
3871
|
-
].map((ext)=>join(context.rootPath, `tailwind.config.${ext}`)));
|
|
4287
|
+
].map((ext)=>(0, external_node_path_.join)(context.rootPath, `tailwind.config.${ext}`)));
|
|
3872
4288
|
return tailwindConfig && (buildDependencies.tailwindcss = [
|
|
3873
4289
|
tailwindConfig
|
|
3874
4290
|
]), {
|
|
@@ -3876,7 +4292,7 @@ async function getBuildDependencies(context, config, environmentContext, userBui
|
|
|
3876
4292
|
...userBuildDependencies
|
|
3877
4293
|
};
|
|
3878
4294
|
}
|
|
3879
|
-
let addTrailingSep = (dir)=>dir.endsWith(sep) ? dir : dir + sep, isStrictSubdir = (parent, child)=>{
|
|
4295
|
+
let addTrailingSep = (dir)=>dir.endsWith(external_node_path_.sep) ? dir : dir + external_node_path_.sep, isStrictSubdir = (parent, child)=>{
|
|
3880
4296
|
let parentDir = addTrailingSep(parent), childDir = addTrailingSep(child);
|
|
3881
4297
|
return parentDir !== childDir && childDir.startsWith(parentDir);
|
|
3882
4298
|
}, normalizeCleanDistPath = (userOptions)=>{
|
|
@@ -3890,7 +4306,9 @@ let addTrailingSep = (dir)=>dir.endsWith(sep) ? dir : dir + sep, isStrictSubdir
|
|
|
3890
4306
|
...defaultOptions,
|
|
3891
4307
|
...userOptions
|
|
3892
4308
|
};
|
|
3893
|
-
}
|
|
4309
|
+
};
|
|
4310
|
+
var postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.5.1_postcss@8.5.6_yaml@2.8.0/node_modules/postcss-load-config/src/index.js"), src_default = __webpack_require__.n(postcss_load_config_src);
|
|
4311
|
+
let parseMinifyOptions = (config)=>{
|
|
3894
4312
|
let isProd = 'production' === config.mode, { minify } = config.output;
|
|
3895
4313
|
if ('boolean' == typeof minify) {
|
|
3896
4314
|
let shouldMinify = minify && isProd;
|
|
@@ -3926,9 +4344,8 @@ let addTrailingSep = (dir)=>dir.endsWith(sep) ? dir : dir + sep, isStrictSubdir
|
|
|
3926
4344
|
async function loadUserPostcssrc(root, postcssrcCache) {
|
|
3927
4345
|
let cached = postcssrcCache.get(root);
|
|
3928
4346
|
if (cached) return clonePostCSSConfig(await cached);
|
|
3929
|
-
let
|
|
3930
|
-
|
|
3931
|
-
if (null == (_err_message = err.message) ? void 0 : _err_message.includes('No PostCSS Config found')) return {};
|
|
4347
|
+
let promise = src_default()({}, root).catch((err)=>{
|
|
4348
|
+
if (err.message?.includes('No PostCSS Config found')) return {};
|
|
3932
4349
|
throw err;
|
|
3933
4350
|
});
|
|
3934
4351
|
return postcssrcCache.set(root, promise), promise.then((config)=>(postcssrcCache.set(root, config), clonePostCSSConfig(config)));
|
|
@@ -3983,11 +4400,11 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
|
3983
4400
|
let logs = [], showTotal = !1 !== options.total, showDetail = !1 !== options.detail, exclude = options.exclude ?? excludeAsset;
|
|
3984
4401
|
if (!showTotal && !showDetail) return logs;
|
|
3985
4402
|
let formatAsset = async (asset, distPath, distFolder)=>{
|
|
3986
|
-
let fileName = asset.name.split('?')[0], contents = await node_fs.promises.readFile(
|
|
4403
|
+
let fileName = asset.name.split('?')[0], contents = await node_fs.promises.readFile(external_node_path_.default.join(distPath, fileName)), size = Buffer.byteLength(contents), gzippedSize = options.compressed && COMPRESSIBLE_REGEX.test(fileName) ? await gzipSize(contents) : null, gzipSizeLabel = gzippedSize ? getAssetColor(gzippedSize)(calcFileSize(gzippedSize)) : null;
|
|
3987
4404
|
return {
|
|
3988
4405
|
size,
|
|
3989
|
-
folder:
|
|
3990
|
-
name:
|
|
4406
|
+
folder: external_node_path_.default.join(distFolder, external_node_path_.default.dirname(fileName)),
|
|
4407
|
+
name: external_node_path_.default.basename(fileName),
|
|
3991
4408
|
gzippedSize,
|
|
3992
4409
|
sizeLabel: calcFileSize(size),
|
|
3993
4410
|
gzipSizeLabel
|
|
@@ -4001,7 +4418,7 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
|
4001
4418
|
size: asset.size
|
|
4002
4419
|
};
|
|
4003
4420
|
return !exclude(assetInfo) && (!options.include || options.include(assetInfo));
|
|
4004
|
-
}), distFolder =
|
|
4421
|
+
}), distFolder = external_node_path_.default.relative(rootPath, distPath);
|
|
4005
4422
|
return Promise.all(filteredAssets.map((asset)=>formatAsset(asset, distPath, distFolder)));
|
|
4006
4423
|
}, assets = await getAssets();
|
|
4007
4424
|
if (0 === assets.length) return logs;
|
|
@@ -4010,7 +4427,7 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
|
4010
4427
|
for (let asset of (showTotal = showTotal && !(showDetail && 1 === assets.length), assets))totalSize += asset.size, options.compressed && (totalGzipSize += asset.gzippedSize ?? asset.size);
|
|
4011
4428
|
let fileHeader = showDetail ? `File (${environmentName})` : '', totalSizeLabel = showTotal ? showDetail ? 'Total:' : `Total size (${environmentName}):` : '', totalSizeStr = showTotal ? calcFileSize(totalSize) : '';
|
|
4012
4429
|
if (showDetail) {
|
|
4013
|
-
let maxFileLength = Math.max(...assets.map((a)=>(a.folder +
|
|
4430
|
+
let maxFileLength = Math.max(...assets.map((a)=>(a.folder + external_node_path_.default.sep + a.name).length), showTotal ? totalSizeLabel.length : 0, fileHeader.length), maxSizeLength = Math.max(...assets.map((a)=>a.sizeLabel.length), totalSizeStr.length), showGzipHeader = !!(options.compressed && assets.some((item)=>null !== item.gzippedSize));
|
|
4014
4431
|
for (let asset of (logs.push(function(maxFileLength, maxSizeLength, fileHeader, showGzipHeader) {
|
|
4015
4432
|
let lengths = [
|
|
4016
4433
|
maxFileLength,
|
|
@@ -4026,9 +4443,9 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
|
4026
4443
|
}, '');
|
|
4027
4444
|
return picocolors.blue(headerRow);
|
|
4028
4445
|
}(maxFileLength, maxSizeLength, fileHeader, showGzipHeader)), assets)){
|
|
4029
|
-
let { sizeLabel } = asset, { name, folder, gzipSizeLabel } = asset, fileNameLength = (folder +
|
|
4446
|
+
let { sizeLabel } = asset, { name, folder, gzipSizeLabel } = asset, fileNameLength = (folder + external_node_path_.default.sep + name).length, sizeLength = sizeLabel.length;
|
|
4030
4447
|
sizeLength < maxSizeLength && (sizeLabel += ' '.repeat(maxSizeLength - sizeLength));
|
|
4031
|
-
let fileNameLabel = picocolors.dim(asset.folder +
|
|
4448
|
+
let fileNameLabel = picocolors.dim(asset.folder + external_node_path_.default.sep) + coloringAssetName(asset.name);
|
|
4032
4449
|
fileNameLength < maxFileLength && (fileNameLabel += ' '.repeat(maxFileLength - fileNameLength));
|
|
4033
4450
|
let log = `${fileNameLabel} ${sizeLabel}`;
|
|
4034
4451
|
gzipSizeLabel && (log += ` ${gzipSizeLabel}`), logs.push(log);
|
|
@@ -4048,14 +4465,6 @@ async function printFileSizes(options, stats, rootPath, environmentName) {
|
|
|
4048
4465
|
}
|
|
4049
4466
|
return logs.push(''), logs;
|
|
4050
4467
|
}
|
|
4051
|
-
function RsbuildHtmlPlugin_define_property(obj, key, value) {
|
|
4052
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
4053
|
-
value: value,
|
|
4054
|
-
enumerable: !0,
|
|
4055
|
-
configurable: !0,
|
|
4056
|
-
writable: !0
|
|
4057
|
-
}) : obj[key] = value, obj;
|
|
4058
|
-
}
|
|
4059
4468
|
let entryNameSymbol = Symbol('entryName'), VOID_TAGS = [
|
|
4060
4469
|
'area',
|
|
4061
4470
|
'base',
|
|
@@ -4104,18 +4513,23 @@ let entryNameSymbol = Symbol('entryName'), VOID_TAGS = [
|
|
|
4104
4513
|
...override
|
|
4105
4514
|
}));
|
|
4106
4515
|
class RsbuildHtmlPlugin {
|
|
4516
|
+
name;
|
|
4517
|
+
getExtraData;
|
|
4518
|
+
constructor(getExtraData){
|
|
4519
|
+
this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
|
|
4520
|
+
}
|
|
4107
4521
|
apply(compiler) {
|
|
4108
4522
|
let emitFavicon = async ({ compilation, favicon, faviconDistPath })=>{
|
|
4109
|
-
let buffer, name =
|
|
4523
|
+
let buffer, name = external_node_path_.default.basename(favicon);
|
|
4110
4524
|
if (compilation.assets[name]) return name;
|
|
4111
4525
|
if (!compilation.inputFileSystem) return addCompilationError(compilation, `${picocolors.dim('[rsbuild:html]')} Failed to read the favicon file as ${picocolors.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
4112
|
-
let inputFilename =
|
|
4526
|
+
let inputFilename = external_node_path_.default.isAbsolute(favicon) ? favicon : external_node_path_.default.join(compilation.compiler.context, favicon);
|
|
4113
4527
|
try {
|
|
4114
4528
|
if (!(buffer = await external_node_util_promisify(compilation.inputFileSystem.readFile)(inputFilename))) throw Error('Buffer is undefined');
|
|
4115
4529
|
} catch (error) {
|
|
4116
4530
|
return logger.debug(`read favicon error: ${error}`), addCompilationError(compilation, `${picocolors.dim('[rsbuild:html]')} Failed to read the favicon file at ${picocolors.yellow(inputFilename)}.`), null;
|
|
4117
4531
|
}
|
|
4118
|
-
let source = new compiler.webpack.sources.RawSource(buffer, !1), outputFilename =
|
|
4532
|
+
let source = new compiler.webpack.sources.RawSource(buffer, !1), outputFilename = external_node_path_.default.posix.join(faviconDistPath, name);
|
|
4119
4533
|
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
4120
4534
|
}, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath })=>{
|
|
4121
4535
|
let href = favicon;
|
|
@@ -4149,19 +4563,15 @@ class RsbuildHtmlPlugin {
|
|
|
4149
4563
|
let extraData = getExtraDataByPlugin(data.plugin);
|
|
4150
4564
|
if (!extraData) return data;
|
|
4151
4565
|
let { headTags, bodyTags } = data, { favicon, faviconDistPath, context, tagConfig, entryName, environment, templateContent } = extraData;
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
});
|
|
4162
|
-
})(headTags, null == (_data_plugin_options = data.plugin.options) ? void 0 : _data_plugin_options.title);
|
|
4163
|
-
}
|
|
4164
|
-
favicon && await addFavicon({
|
|
4566
|
+
templateContent && /<title/i.test(templateContent) && /<\/title/i.test(templateContent) || ((headTags, title = '')=>{
|
|
4567
|
+
'' !== title && void 0 !== title && headTags.unshift({
|
|
4568
|
+
tagName: 'title',
|
|
4569
|
+
innerHTML: title,
|
|
4570
|
+
attributes: {},
|
|
4571
|
+
voidTag: !1,
|
|
4572
|
+
meta: {}
|
|
4573
|
+
});
|
|
4574
|
+
})(headTags, data.plugin.options?.title), favicon && await addFavicon({
|
|
4165
4575
|
headTags,
|
|
4166
4576
|
favicon,
|
|
4167
4577
|
faviconDistPath,
|
|
@@ -4188,8 +4598,7 @@ class RsbuildHtmlPlugin {
|
|
|
4188
4598
|
headTags: modified.headTags.map(fromBasicTag),
|
|
4189
4599
|
bodyTags: modified.bodyTags.map(fromBasicTag)
|
|
4190
4600
|
}), tagConfig && ((data, tagConfig, compilationHash, entryName)=>{
|
|
4191
|
-
|
|
4192
|
-
if (!(null == (_tagConfig_tags = tagConfig.tags) ? void 0 : _tagConfig_tags.length)) return;
|
|
4601
|
+
if (!tagConfig.tags?.length) return;
|
|
4193
4602
|
let fromInjectTags = (tags)=>{
|
|
4194
4603
|
let ret = [];
|
|
4195
4604
|
for (let tag of tags){
|
|
@@ -4251,9 +4660,6 @@ class RsbuildHtmlPlugin {
|
|
|
4251
4660
|
});
|
|
4252
4661
|
});
|
|
4253
4662
|
}
|
|
4254
|
-
constructor(getExtraData){
|
|
4255
|
-
RsbuildHtmlPlugin_define_property(this, "name", void 0), RsbuildHtmlPlugin_define_property(this, "getExtraData", void 0), this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData;
|
|
4256
|
-
}
|
|
4257
4663
|
}
|
|
4258
4664
|
let existTemplatePath = new Set();
|
|
4259
4665
|
async function getTemplate(entryName, config, rootPath) {
|
|
@@ -4271,7 +4677,7 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
4271
4677
|
templateContent: (mountId = config.html.mountId, `<!doctype html><html><head></head><body><div id="${mountId}"></div></body></html>`)
|
|
4272
4678
|
};
|
|
4273
4679
|
}
|
|
4274
|
-
let absolutePath =
|
|
4680
|
+
let absolutePath = (0, external_node_path_.isAbsolute)(templatePath) ? templatePath : external_node_path_.default.join(rootPath, templatePath);
|
|
4275
4681
|
if (!existTemplatePath.has(absolutePath)) {
|
|
4276
4682
|
if (!await isFileExists(absolutePath)) throw Error(`${picocolors.dim('[rsbuild:html]')} Failed to resolve HTML template, check if the file exists: ${picocolors.yellow(absolutePath)}`);
|
|
4277
4683
|
existTemplatePath.add(absolutePath);
|
|
@@ -4285,7 +4691,7 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
4285
4691
|
function updateSourceMappingURL({ source, compilation, publicPath, type, config }) {
|
|
4286
4692
|
let { devtool } = compilation.options;
|
|
4287
4693
|
if (devtool && !devtool.includes('inline') && source.includes('# sourceMappingURL')) {
|
|
4288
|
-
let prefix = addTrailingSlash(
|
|
4694
|
+
let prefix = addTrailingSlash(external_node_path_.default.join(publicPath, config.output.distPath[type] || ''));
|
|
4289
4695
|
return source.replace(/# sourceMappingURL=/, `# sourceMappingURL=${prefix}`);
|
|
4290
4696
|
}
|
|
4291
4697
|
return source;
|
|
@@ -4338,7 +4744,7 @@ let isWsl = ()=>{
|
|
|
4338
4744
|
if (mountPoint) return mountPoint;
|
|
4339
4745
|
let configFilePath = '/etc/wsl.conf', isConfigFileExists = !1;
|
|
4340
4746
|
try {
|
|
4341
|
-
await promises.access(configFilePath,
|
|
4747
|
+
await promises.access(configFilePath, promises_constants.F_OK), isConfigFileExists = !0;
|
|
4342
4748
|
} catch {}
|
|
4343
4749
|
if (!isConfigFileExists) return defaultMountPoint;
|
|
4344
4750
|
let configContent = await promises.readFile(configFilePath, {
|
|
@@ -4468,7 +4874,7 @@ async function default_browser_defaultBrowser() {
|
|
|
4468
4874
|
if ('win32' === node_process.platform) return defaultBrowser();
|
|
4469
4875
|
throw Error('Only macOS, Linux, and Windows are supported');
|
|
4470
4876
|
}
|
|
4471
|
-
let open_execFile = external_node_util_promisify(node_child_process.execFile), open_dirname =
|
|
4877
|
+
let open_execFile = external_node_util_promisify(node_child_process.execFile), open_dirname = external_node_path_.default.dirname((0, external_node_url_.fileURLToPath)(import.meta.url)), localXdgOpenPath = external_node_path_.default.join(open_dirname, 'xdg-open'), { platform, arch } = node_process;
|
|
4472
4878
|
async function getWindowsDefaultBrowserFromWsl() {
|
|
4473
4879
|
let powershellPath = await powerShellPath(), rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`, encodedCommand = external_node_buffer_Buffer.from(rawCommand, 'utf16le').toString('base64'), { stdout } = await open_execFile(powershellPath, [
|
|
4474
4880
|
'-NoProfile',
|
|
@@ -4555,7 +4961,7 @@ let pTryEach = async (array, mapper)=>{
|
|
|
4555
4961
|
else {
|
|
4556
4962
|
let exeLocalXdgOpen = !1;
|
|
4557
4963
|
try {
|
|
4558
|
-
await promises.access(localXdgOpenPath,
|
|
4964
|
+
await promises.access(localXdgOpenPath, promises_constants.X_OK), exeLocalXdgOpen = !0;
|
|
4559
4965
|
} catch {}
|
|
4560
4966
|
command = node_process.versions.electron ?? ('android' === platform || !open_dirname || '/' === open_dirname || !exeLocalXdgOpen) ? 'xdg-open' : localXdgOpenPath;
|
|
4561
4967
|
}
|
|
@@ -4640,12 +5046,12 @@ let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), joinUrlSegments = (
|
|
|
4640
5046
|
let trailingSlashBase = addTrailingSlash(base);
|
|
4641
5047
|
return path.startsWith(trailingSlashBase) ? path.slice(trailingSlashBase.length - 1) : path;
|
|
4642
5048
|
}, getRoutes = (context)=>Object.values(context.environments).reduce((prev, environmentContext)=>{
|
|
4643
|
-
let { distPath, config } = environmentContext, distPrefix = relative(context.distPath, distPath).split(sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
|
|
5049
|
+
let { distPath, config } = environmentContext, distPrefix = (0, external_node_path_.relative)(context.distPath, distPath).split(external_node_path_.sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, external_node_path_.posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
|
|
4644
5050
|
return prev.concat(...routes);
|
|
4645
5051
|
}, []), formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
|
|
4646
5052
|
let prefix = joinUrlSegments(base, ((input)=>{
|
|
4647
5053
|
let prefix = input;
|
|
4648
|
-
if (
|
|
5054
|
+
if (prefix?.startsWith('./') && (prefix = prefix.replace('./', '')), !prefix) return '/';
|
|
4649
5055
|
let hasLeadingSlash = prefix.startsWith('/'), hasTailSlash = prefix.endsWith('/');
|
|
4650
5056
|
return `${hasLeadingSlash ? '' : '/'}${prefix}${hasTailSlash ? '' : '/'}`;
|
|
4651
5057
|
})(distPathPrefix));
|
|
@@ -4822,7 +5228,7 @@ async function openBrowser(url) {
|
|
|
4822
5228
|
let options = browser ? {
|
|
4823
5229
|
app: {
|
|
4824
5230
|
name: apps[browser] ?? browser,
|
|
4825
|
-
arguments:
|
|
5231
|
+
arguments: browserArgs?.split(' ')
|
|
4826
5232
|
}
|
|
4827
5233
|
} : {};
|
|
4828
5234
|
return (await ((target, options)=>{
|
|
@@ -4881,6 +5287,10 @@ function recursiveChunkEntryNames(chunk) {
|
|
|
4881
5287
|
];
|
|
4882
5288
|
}
|
|
4883
5289
|
class PatchSplitChunksPlugin {
|
|
5290
|
+
name;
|
|
5291
|
+
constructor(name){
|
|
5292
|
+
this.name = name;
|
|
5293
|
+
}
|
|
4884
5294
|
apply(compiler) {
|
|
4885
5295
|
let { splitChunks } = compiler.options.optimization;
|
|
4886
5296
|
if (!splitChunks) return;
|
|
@@ -4906,33 +5316,27 @@ class PatchSplitChunksPlugin {
|
|
|
4906
5316
|
let { cacheGroups } = splitChunks;
|
|
4907
5317
|
if (cacheGroups) for (let cacheGroupKey of Object.keys(cacheGroups))cacheGroups[cacheGroupKey] && applyPatch(cacheGroups[cacheGroupKey]);
|
|
4908
5318
|
}
|
|
4909
|
-
constructor(name){
|
|
4910
|
-
var key, value;
|
|
4911
|
-
value = void 0, (key = "name") in this ? Object.defineProperty(this, key, {
|
|
4912
|
-
value: value,
|
|
4913
|
-
enumerable: !0,
|
|
4914
|
-
configurable: !0,
|
|
4915
|
-
writable: !0
|
|
4916
|
-
}) : this[key] = value, this.name = name;
|
|
4917
|
-
}
|
|
4918
5319
|
}
|
|
4919
|
-
let resolve_require = createRequire(import.meta.url);
|
|
5320
|
+
let resolve_require = (0, external_node_module_.createRequire)(import.meta.url);
|
|
4920
5321
|
function isAsyncChunk(chunk) {
|
|
4921
5322
|
return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
|
|
4922
5323
|
}
|
|
4923
|
-
function HtmlResourceHintsPlugin_define_property(obj, key, value) {
|
|
4924
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
4925
|
-
value: value,
|
|
4926
|
-
enumerable: !0,
|
|
4927
|
-
configurable: !0,
|
|
4928
|
-
writable: !0
|
|
4929
|
-
}) : obj[key] = value, obj;
|
|
4930
|
-
}
|
|
4931
5324
|
let HtmlResourceHintsPlugin_defaultOptions = {
|
|
4932
5325
|
type: 'async-chunks',
|
|
4933
5326
|
dedupe: !0
|
|
4934
5327
|
};
|
|
4935
5328
|
class HtmlResourceHintsPlugin {
|
|
5329
|
+
options;
|
|
5330
|
+
name = 'HtmlResourceHintsPlugin';
|
|
5331
|
+
resourceHints = [];
|
|
5332
|
+
type;
|
|
5333
|
+
HTMLCount;
|
|
5334
|
+
constructor(options, type, HTMLCount){
|
|
5335
|
+
this.options = {
|
|
5336
|
+
...HtmlResourceHintsPlugin_defaultOptions,
|
|
5337
|
+
...options
|
|
5338
|
+
}, this.type = type, this.HTMLCount = HTMLCount;
|
|
5339
|
+
}
|
|
4936
5340
|
apply(compiler) {
|
|
4937
5341
|
compiler.hooks.compilation.tap(this.name, (compilation)=>{
|
|
4938
5342
|
let pluginHooks = getHTMLPlugin().getCompilationHooks(compilation), pluginName = `HTML${upperFirst(this.type)}Plugin`;
|
|
@@ -4945,13 +5349,9 @@ class HtmlResourceHintsPlugin {
|
|
|
4945
5349
|
if ('initial' === includeType) return chunks.filter((chunk)=>!isAsyncChunk(chunk));
|
|
4946
5350
|
if ('all-chunks' === includeType) return chunks;
|
|
4947
5351
|
if ('all-assets' === includeType) {
|
|
4948
|
-
var _compilation_assetsInfo;
|
|
4949
5352
|
let licenseAssets = [
|
|
4950
|
-
...
|
|
4951
|
-
].map((info)
|
|
4952
|
-
var _info_related;
|
|
4953
|
-
return null != (_info_related = info.related) && !!_info_related.license && info.related.license;
|
|
4954
|
-
}).filter(Boolean);
|
|
5353
|
+
...compilation.assetsInfo?.values() || []
|
|
5354
|
+
].map((info)=>!!info.related?.license && info.related.license).filter(Boolean);
|
|
4955
5355
|
return [
|
|
4956
5356
|
{
|
|
4957
5357
|
files: Object.keys(compilation.assets).filter((t)=>!licenseAssets.includes(t))
|
|
@@ -4977,7 +5377,7 @@ class HtmlResourceHintsPlugin {
|
|
|
4977
5377
|
let { options } = htmlPluginData.plugin;
|
|
4978
5378
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>{
|
|
4979
5379
|
var includeChunks, excludeChunks;
|
|
4980
|
-
return includeChunks =
|
|
5380
|
+
return includeChunks = options?.chunks, excludeChunks = options?.excludeChunks, !(Array.isArray(includeChunks) && -1 === includeChunks.indexOf(chunkName) || Array.isArray(excludeChunks) && -1 !== excludeChunks.indexOf(chunkName));
|
|
4981
5381
|
});
|
|
4982
5382
|
})({
|
|
4983
5383
|
chunk: chunk,
|
|
@@ -4995,7 +5395,7 @@ class HtmlResourceHintsPlugin {
|
|
|
4995
5395
|
rel: type
|
|
4996
5396
|
};
|
|
4997
5397
|
'preload' === type && (attributes.as = function({ href, file }) {
|
|
4998
|
-
let url = new
|
|
5398
|
+
let url = new external_node_url_.URL(file || href, 'https://example.com'), extension = external_node_path_.default.extname(url.pathname).slice(1);
|
|
4999
5399
|
return [
|
|
5000
5400
|
'css'
|
|
5001
5401
|
].includes(extension) ? 'style' : IMAGE_EXTENSIONS.includes(extension) ? 'image' : VIDEO_EXTENSIONS.includes(extension) ? 'video' : AUDIO_EXTENSIONS.includes(extension) ? 'audio' : FONT_EXTENSIONS.includes(extension) ? 'font' : [
|
|
@@ -5021,12 +5421,6 @@ class HtmlResourceHintsPlugin {
|
|
|
5021
5421
|
});
|
|
5022
5422
|
});
|
|
5023
5423
|
}
|
|
5024
|
-
constructor(options, type, HTMLCount){
|
|
5025
|
-
HtmlResourceHintsPlugin_define_property(this, "options", void 0), HtmlResourceHintsPlugin_define_property(this, "name", 'HtmlResourceHintsPlugin'), HtmlResourceHintsPlugin_define_property(this, "resourceHints", []), HtmlResourceHintsPlugin_define_property(this, "type", void 0), HtmlResourceHintsPlugin_define_property(this, "HTMLCount", void 0), this.options = {
|
|
5026
|
-
...HtmlResourceHintsPlugin_defaultOptions,
|
|
5027
|
-
...options
|
|
5028
|
-
}, this.type = type, this.HTMLCount = HTMLCount;
|
|
5029
|
-
}
|
|
5030
5424
|
}
|
|
5031
5425
|
let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
5032
5426
|
tag: 'link',
|
|
@@ -5034,9 +5428,9 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
5034
5428
|
rel,
|
|
5035
5429
|
...option
|
|
5036
5430
|
}
|
|
5037
|
-
})), rsdoctor_require = createRequire(import.meta.url);
|
|
5431
|
+
})), rsdoctor_require = (0, external_node_module_.createRequire)(import.meta.url);
|
|
5038
5432
|
async function ensureFileDir(outputFilePath) {
|
|
5039
|
-
let dir =
|
|
5433
|
+
let dir = external_node_path_.default.dirname(outputFilePath);
|
|
5040
5434
|
await node_fs.promises.mkdir(dir, {
|
|
5041
5435
|
recursive: !0
|
|
5042
5436
|
});
|
|
@@ -5044,7 +5438,7 @@ async function ensureFileDir(outputFilePath) {
|
|
|
5044
5438
|
async function applyProfile(root, filterValue, traceLayer = 'perfetto', traceOutput) {
|
|
5045
5439
|
if ('perfetto' !== traceLayer && 'logger' !== traceLayer) throw Error(`unsupported trace layer: ${traceLayer}`);
|
|
5046
5440
|
if (!traceOutput) {
|
|
5047
|
-
let timestamp = Date.now(), defaultOutputDir =
|
|
5441
|
+
let timestamp = Date.now(), defaultOutputDir = external_node_path_.default.join(root, `.rspack-profile-${timestamp}-${process.pid}`), defaultRustTracePerfettoOutput = external_node_path_.default.join(defaultOutputDir, 'rspack.pftrace');
|
|
5048
5442
|
traceOutput = 'perfetto' === traceLayer ? defaultRustTracePerfettoOutput : 'stdout';
|
|
5049
5443
|
}
|
|
5050
5444
|
return await ensureFileDir(traceOutput), await rspack_rspack.experiments.globalTrace.register("OVERVIEW" === filterValue ? 'info' : "ALL" === filterValue ? 'trace' : filterValue, traceLayer, traceOutput), traceOutput;
|
|
@@ -5087,7 +5481,7 @@ let MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\
|
|
|
5087
5481
|
priority: -9,
|
|
5088
5482
|
test: NODE_MODULES_REGEX,
|
|
5089
5483
|
name: (module)=>module ? function(modulePath) {
|
|
5090
|
-
let handleModuleContext =
|
|
5484
|
+
let handleModuleContext = modulePath?.match(MODULE_PATH_REGEX);
|
|
5091
5485
|
if (!handleModuleContext) return;
|
|
5092
5486
|
let [, scope, name] = handleModuleContext;
|
|
5093
5487
|
return [
|
|
@@ -5149,7 +5543,7 @@ let MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\
|
|
|
5149
5543
|
}
|
|
5150
5544
|
};
|
|
5151
5545
|
}
|
|
5152
|
-
}, swc_require = createRequire(import.meta.url), builtinSwcLoaderName = 'builtin:swc-loader', isCliShortcutsEnabled = (config)=>config.dev.cliShortcuts && isTTY('stdin');
|
|
5546
|
+
}, swc_require = (0, external_node_module_.createRequire)(import.meta.url), builtinSwcLoaderName = 'builtin:swc-loader', isCliShortcutsEnabled = (config)=>config.dev.cliShortcuts && isTTY('stdin');
|
|
5153
5547
|
async function setupCliShortcuts({ help = !0, openPage, closeServer, printUrls, restartServer, customShortcuts }) {
|
|
5154
5548
|
let shortcuts = [
|
|
5155
5549
|
{
|
|
@@ -5222,7 +5616,7 @@ async function resolveHostname(host = 'localhost') {
|
|
|
5222
5616
|
'0000:0000:0000:0000:0000:0000:0000:0000'
|
|
5223
5617
|
]).has(host) ? 'localhost' : host;
|
|
5224
5618
|
}
|
|
5225
|
-
let compilationMiddleware_require = createRequire(import.meta.url), getCompilationMiddleware = async ({ config, compiler, callbacks, environments, resolvedPort })=>{
|
|
5619
|
+
let compilationMiddleware_require = (0, external_node_module_.createRequire)(import.meta.url), getCompilationMiddleware = async ({ config, compiler, callbacks, environments, resolvedPort })=>{
|
|
5226
5620
|
let { default: rsbuildDevMiddleware } = await import("../compiled/rsbuild-dev-middleware/index.js"), resolvedHost = await resolveHostname(config.server.host);
|
|
5227
5621
|
return applyToCompiler(compiler, (compiler, index)=>{
|
|
5228
5622
|
let environment = Object.values(environments).find((env)=>env.index === index);
|
|
@@ -5234,9 +5628,8 @@ let compilationMiddleware_require = createRequire(import.meta.url), getCompilati
|
|
|
5234
5628
|
return !!target && (Array.isArray(target) ? target.includes('web') : 'web' === target);
|
|
5235
5629
|
})(compiler)) return;
|
|
5236
5630
|
let clientPaths = function(devConfig) {
|
|
5237
|
-
var _devConfig_client;
|
|
5238
5631
|
let clientPaths = [];
|
|
5239
|
-
return (devConfig.hmr || devConfig.liveReload) && (hmrClientPath || (hmrClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/hmr')), clientPaths.push(hmrClientPath),
|
|
5632
|
+
return (devConfig.hmr || devConfig.liveReload) && (hmrClientPath || (hmrClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/hmr')), clientPaths.push(hmrClientPath), devConfig.client?.overlay && (overlayClientPath || (overlayClientPath = compilationMiddleware_require.resolve('@rsbuild/core/client/overlay')), clientPaths.push(overlayClientPath))), clientPaths;
|
|
5240
5633
|
}(config.dev);
|
|
5241
5634
|
if (!clientPaths.length) return;
|
|
5242
5635
|
let clientConfig = {
|
|
@@ -5317,30 +5710,42 @@ let closeCode = [
|
|
|
5317
5710
|
29,
|
|
5318
5711
|
39,
|
|
5319
5712
|
49
|
|
5320
|
-
]
|
|
5321
|
-
function socketServer_define_property(obj, key, value) {
|
|
5322
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
5323
|
-
value: value,
|
|
5324
|
-
enumerable: !0,
|
|
5325
|
-
configurable: !0,
|
|
5326
|
-
writable: !0
|
|
5327
|
-
}) : obj[key] = value, obj;
|
|
5328
|
-
}
|
|
5329
|
-
let parseQueryString = (req)=>{
|
|
5713
|
+
], parseQueryString = (req)=>{
|
|
5330
5714
|
let queryStr = req.url ? req.url.split('?')[1] : '';
|
|
5331
5715
|
return queryStr ? Object.fromEntries(new URLSearchParams(queryStr)) : {};
|
|
5332
5716
|
};
|
|
5333
5717
|
class SocketServer {
|
|
5718
|
+
wsServer;
|
|
5719
|
+
sockets = new Map();
|
|
5720
|
+
options;
|
|
5721
|
+
stats;
|
|
5722
|
+
initialChunks;
|
|
5723
|
+
heartbeatTimer = null;
|
|
5724
|
+
environments;
|
|
5725
|
+
constructor(options, environments){
|
|
5726
|
+
this.options = options, this.stats = {}, this.initialChunks = {}, this.environments = environments;
|
|
5727
|
+
}
|
|
5728
|
+
upgrade = (req, socket, head)=>{
|
|
5729
|
+
if (!this.wsServer.shouldHandle(req)) return;
|
|
5730
|
+
let query = parseQueryString(req);
|
|
5731
|
+
if (!Object.values(this.environments).map((env)=>env.webSocketToken).includes(query.token)) return void socket.destroy();
|
|
5732
|
+
this.wsServer.handleUpgrade(req, socket, head, (connection)=>{
|
|
5733
|
+
this.wsServer.emit('connection', connection, req);
|
|
5734
|
+
});
|
|
5735
|
+
};
|
|
5736
|
+
checkSockets = ()=>{
|
|
5737
|
+
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
5738
|
+
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
|
|
5739
|
+
};
|
|
5334
5740
|
clearHeartbeatTimer() {
|
|
5335
5741
|
this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
5336
5742
|
}
|
|
5337
5743
|
async prepare() {
|
|
5338
|
-
var _this_options_client;
|
|
5339
5744
|
this.clearHeartbeatTimer();
|
|
5340
5745
|
let { default: ws } = await import("../compiled/ws/index.js");
|
|
5341
5746
|
this.wsServer = new ws.Server({
|
|
5342
5747
|
noServer: !0,
|
|
5343
|
-
path:
|
|
5748
|
+
path: this.options.client?.path
|
|
5344
5749
|
}), this.wsServer.on('error', (err)=>{
|
|
5345
5750
|
logger.error(err);
|
|
5346
5751
|
}), this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref(), this.wsServer.on('connection', (socket, req)=>{
|
|
@@ -5443,9 +5848,9 @@ class SocketServer {
|
|
|
5443
5848
|
let pathRegex = /(?:\.\.?[/\\]|[a-zA-Z]:\\|\/)[^:]*:\d+:\d+/g, urlRegex = /(https?:\/\/(?:[\w-]+\.)+[a-z0-9](?:[\w-.~:/?#[\]@!$&'*+,;=])*)/gi;
|
|
5444
5849
|
return text.split('\n').map((line)=>{
|
|
5445
5850
|
let replacedLine = line.replace(pathRegex, (file)=>{
|
|
5446
|
-
let hasClosingSpan = file.includes('</span>') && !file.includes('<span'), filePath = hasClosingSpan ? file.replace('</span>', '') : file, isAbsolute =
|
|
5447
|
-
let relativePath = relative(base, filepath);
|
|
5448
|
-
return '' === relativePath ? `.${sep}` : relativePath.startsWith('.') ? relativePath : `.${sep}${relativePath}`;
|
|
5851
|
+
let hasClosingSpan = file.includes('</span>') && !file.includes('<span'), filePath = hasClosingSpan ? file.replace('</span>', '') : file, isAbsolute = external_node_path_.default.isAbsolute(filePath), absolutePath = root1 && !isAbsolute ? external_node_path_.default.join(root1, filePath) : filePath, relativePath = root1 && isAbsolute ? function(base, filepath) {
|
|
5852
|
+
let relativePath = (0, external_node_path_.relative)(base, filepath);
|
|
5853
|
+
return '' === relativePath ? `.${external_node_path_.sep}` : relativePath.startsWith('.') ? relativePath : `.${external_node_path_.sep}${relativePath}`;
|
|
5449
5854
|
}(root1, filePath) : filePath;
|
|
5450
5855
|
return `<a class="file-link" data-file="${absolutePath}">${relativePath}</a>${hasClosingSpan ? '</span>' : ''}`;
|
|
5451
5856
|
});
|
|
@@ -5608,29 +6013,19 @@ class SocketServer {
|
|
|
5608
6013
|
send(connection, message) {
|
|
5609
6014
|
1 === connection.readyState && connection.send(message);
|
|
5610
6015
|
}
|
|
5611
|
-
constructor(options, environments){
|
|
5612
|
-
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", new Map()), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "environments", void 0), socketServer_define_property(this, "upgrade", (req, socket, head)=>{
|
|
5613
|
-
if (!this.wsServer.shouldHandle(req)) return;
|
|
5614
|
-
let query = parseQueryString(req);
|
|
5615
|
-
if (!Object.values(this.environments).map((env)=>env.webSocketToken).includes(query.token)) return void socket.destroy();
|
|
5616
|
-
this.wsServer.handleUpgrade(req, socket, head, (connection)=>{
|
|
5617
|
-
this.wsServer.emit('connection', connection, req);
|
|
5618
|
-
});
|
|
5619
|
-
}), socketServer_define_property(this, "checkSockets", ()=>{
|
|
5620
|
-
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
5621
|
-
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
|
|
5622
|
-
}), this.options = options, this.stats = {}, this.initialChunks = {}, this.environments = environments;
|
|
5623
|
-
}
|
|
5624
|
-
}
|
|
5625
|
-
function compilationManager_define_property(obj, key, value) {
|
|
5626
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
5627
|
-
value: value,
|
|
5628
|
-
enumerable: !0,
|
|
5629
|
-
configurable: !0,
|
|
5630
|
-
writable: !0
|
|
5631
|
-
}) : obj[key] = value, obj;
|
|
5632
6016
|
}
|
|
5633
6017
|
class CompilationManager {
|
|
6018
|
+
middleware;
|
|
6019
|
+
outputFileSystem;
|
|
6020
|
+
config;
|
|
6021
|
+
compiler;
|
|
6022
|
+
environments;
|
|
6023
|
+
publicPaths;
|
|
6024
|
+
socketServer;
|
|
6025
|
+
resolvedPort;
|
|
6026
|
+
constructor({ config, compiler, publicPaths, resolvedPort, environments }){
|
|
6027
|
+
this.config = config, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.resolvedPort = resolvedPort, this.outputFileSystem = node_fs, this.socketServer = new SocketServer(config.dev, environments);
|
|
6028
|
+
}
|
|
5634
6029
|
async init() {
|
|
5635
6030
|
await this.setupCompilationMiddleware(), await this.socketServer.prepare();
|
|
5636
6031
|
let { compiler } = this;
|
|
@@ -5650,6 +6045,7 @@ class CompilationManager {
|
|
|
5650
6045
|
});
|
|
5651
6046
|
});
|
|
5652
6047
|
}
|
|
6048
|
+
readFileSync = (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : node_fs.readFileSync(fileName, 'utf-8');
|
|
5653
6049
|
async setupCompilationMiddleware() {
|
|
5654
6050
|
let { config, publicPaths, environments } = this, middleware = await getCompilationMiddleware({
|
|
5655
6051
|
config,
|
|
@@ -5674,9 +6070,6 @@ class CompilationManager {
|
|
|
5674
6070
|
};
|
|
5675
6071
|
wrapper.close = middleware.close, wrapper.watch = middleware.watch, this.middleware = wrapper;
|
|
5676
6072
|
}
|
|
5677
|
-
constructor({ config, compiler, publicPaths, resolvedPort, environments }){
|
|
5678
|
-
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "config", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "environments", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "resolvedPort", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : node_fs.readFileSync(fileName, 'utf-8')), this.config = config, this.compiler = compiler, this.environments = environments, this.publicPaths = publicPaths, this.resolvedPort = resolvedPort, this.outputFileSystem = node_fs, this.socketServer = new SocketServer(config.dev, environments);
|
|
5679
|
-
}
|
|
5680
6073
|
}
|
|
5681
6074
|
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, gzipMiddleware = ({ filter, level = node_zlib.constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
5682
6075
|
let gzip, writeHeadStatus;
|
|
@@ -5737,15 +6130,14 @@ function historyApiFallbackMiddleware(options = {}) {
|
|
|
5737
6130
|
let parsedUrl = function(req) {
|
|
5738
6131
|
let proto = req.headers['x-forwarded-proto'] || 'http', host = req.headers['x-forwarded-host'] || req.headers.host || 'localhost';
|
|
5739
6132
|
try {
|
|
5740
|
-
return new
|
|
6133
|
+
return new external_node_url_.URL(req.url || '/', `${proto}://${host}`);
|
|
5741
6134
|
} catch {
|
|
5742
6135
|
return null;
|
|
5743
6136
|
}
|
|
5744
6137
|
}(req);
|
|
5745
6138
|
if (null === parsedUrl) return void next();
|
|
5746
6139
|
for (let rewrite of rewrites){
|
|
5747
|
-
|
|
5748
|
-
let match = null == (_parsedUrl_pathname = parsedUrl.pathname) ? void 0 : _parsedUrl_pathname.match(rewrite.from);
|
|
6140
|
+
let match = parsedUrl.pathname?.match(rewrite.from);
|
|
5749
6141
|
if (!match) continue;
|
|
5750
6142
|
let rule = rewrite.to;
|
|
5751
6143
|
'/' !== (rewriteTarget = 'string' == typeof rule ? rule : rule({
|
|
@@ -5772,7 +6164,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5772
6164
|
let _startAt = process.hrtime();
|
|
5773
6165
|
onFinished(res, ()=>{
|
|
5774
6166
|
let method = req.method, url = req.originalUrl || req.url, status = Number(res.statusCode), statusColor = status >= 500 ? picocolors.red : status >= 400 ? picocolors.yellow : status >= 300 ? picocolors.cyan : status >= 200 ? picocolors.green : (res)=>res, endAt = process.hrtime(), totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
|
|
5775
|
-
logger.debug(`${statusColor(status)} ${method} ${
|
|
6167
|
+
logger.debug(`${statusColor(status)} ${method} ${url} ${picocolors.dim(`${totalTime.toFixed(3)} ms`)}`);
|
|
5776
6168
|
}), next();
|
|
5777
6169
|
};
|
|
5778
6170
|
}, notFoundMiddleware = (_req, res, _next)=>{
|
|
@@ -5785,14 +6177,13 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5785
6177
|
next();
|
|
5786
6178
|
}, middlewares_isFileExists = async (filePath, outputFileSystem)=>new Promise((resolve)=>{
|
|
5787
6179
|
outputFileSystem.stat(filePath, (_error, stats)=>{
|
|
5788
|
-
resolve(
|
|
6180
|
+
resolve(stats?.isFile());
|
|
5789
6181
|
});
|
|
5790
6182
|
}), maybeHTMLRequest = (req)=>{
|
|
5791
6183
|
if (!req.url || !req.headers || 'GET' !== req.method && 'HEAD' !== req.method) return !1;
|
|
5792
6184
|
let { accept } = req.headers;
|
|
5793
6185
|
return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
|
|
5794
6186
|
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getBaseMiddleware = ({ base })=>(req, res, next)=>{
|
|
5795
|
-
var _req_headers_accept;
|
|
5796
6187
|
let url = req.url, pathname = getUrlPathname(url);
|
|
5797
6188
|
if (pathname.startsWith(base)) {
|
|
5798
6189
|
req.url = stripBase(url, base), next();
|
|
@@ -5805,7 +6196,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5805
6196
|
}), res.end();
|
|
5806
6197
|
return;
|
|
5807
6198
|
}
|
|
5808
|
-
if (
|
|
6199
|
+
if (req.headers.accept?.includes('text/html')) {
|
|
5809
6200
|
res.writeHead(404, {
|
|
5810
6201
|
'Content-Type': 'text/html'
|
|
5811
6202
|
}), res.end(`The server is configured with a base URL of ${base} - did you mean to visit <a href="${redirectPath}">${redirectPath}</a> instead?`);
|
|
@@ -5865,12 +6256,8 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5865
6256
|
}
|
|
5866
6257
|
let { compress } = server;
|
|
5867
6258
|
if (compress && middlewares.push(gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && 'rspack' === context.bundlerType && compilationManager) {
|
|
5868
|
-
var _compiler_options_experiments;
|
|
5869
6259
|
let { compiler } = compilationManager;
|
|
5870
|
-
(helpers_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>
|
|
5871
|
-
var _childCompiler_options_experiments;
|
|
5872
|
-
return null == (_childCompiler_options_experiments = childCompiler.options.experiments) ? void 0 : _childCompiler_options_experiments.lazyCompilation;
|
|
5873
|
-
}) : null == (_compiler_options_experiments = compiler.options.experiments) ? void 0 : _compiler_options_experiments.lazyCompilation) && middlewares.push(rspack_rspack.experiments.lazyCompilationMiddleware(compiler));
|
|
6260
|
+
(helpers_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.experiments?.lazyCompilation || childCompiler.options.lazyCompilation) : compiler.options.experiments?.lazyCompilation || compiler.options.lazyCompilation) && middlewares.push(rspack_rspack.experiments.lazyCompilationMiddleware(compiler));
|
|
5874
6261
|
}
|
|
5875
6262
|
server.base && '/' !== server.base && middlewares.push(getBaseMiddleware({
|
|
5876
6263
|
base: server.base
|
|
@@ -5930,8 +6317,8 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5930
6317
|
for(let key in environments){
|
|
5931
6318
|
res.write(`<h2>Environment: ${key}</h2>`);
|
|
5932
6319
|
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetsFromStats(stats);
|
|
5933
|
-
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${
|
|
5934
|
-
res.write(
|
|
6320
|
+
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset?.name}">${asset?.name}</a></li>`);
|
|
6321
|
+
res.write(list?.join('')), res.write('</ul>');
|
|
5935
6322
|
}
|
|
5936
6323
|
res.end('</body></html>');
|
|
5937
6324
|
} catch (err) {
|
|
@@ -5940,8 +6327,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5940
6327
|
})({
|
|
5941
6328
|
environments: devServerAPI.environments
|
|
5942
6329
|
})), compilationManager && (middlewares.push(compilationManager.middleware), upgradeEvents.push(compilationManager.socketServer.upgrade), middlewares.push((req, res, next)=>{
|
|
5943
|
-
|
|
5944
|
-
(null == (_req_url = req.url) ? void 0 : _req_url.endsWith('.hot-update.json')) && 'OPTIONS' !== req.method ? (res.statusCode = 404, res.end()) : next();
|
|
6330
|
+
req.url?.endsWith('.hot-update.json') && 'OPTIONS' !== req.method ? (res.statusCode = 404, res.end()) : next();
|
|
5945
6331
|
})), compilationManager && middlewares.push((({ distPath, compilationManager })=>async (req, res, next)=>{
|
|
5946
6332
|
if (!maybeHTMLRequest(req)) return void next();
|
|
5947
6333
|
let pathname = getUrlPathname(req.url), rewrite = (newUrl)=>{
|
|
@@ -5950,18 +6336,18 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5950
6336
|
});
|
|
5951
6337
|
};
|
|
5952
6338
|
if (pathname.endsWith('/')) {
|
|
5953
|
-
let newUrl = `${pathname}index.html`, filePath =
|
|
6339
|
+
let newUrl = `${pathname}index.html`, filePath = external_node_path_.default.join(distPath, newUrl);
|
|
5954
6340
|
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return void rewrite(newUrl);
|
|
5955
|
-
} else if (!
|
|
5956
|
-
let newUrl = `${pathname}.html`, filePath =
|
|
6341
|
+
} else if (!external_node_path_.default.extname(pathname)) {
|
|
6342
|
+
let newUrl = `${pathname}.html`, filePath = external_node_path_.default.join(distPath, newUrl);
|
|
5957
6343
|
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return void rewrite(newUrl);
|
|
5958
6344
|
}
|
|
5959
6345
|
next();
|
|
5960
6346
|
})({
|
|
5961
6347
|
compilationManager,
|
|
5962
6348
|
distPath: context.distPath
|
|
5963
|
-
})), normalizePublicDirs(
|
|
5964
|
-
let { default: sirv } = await import("../compiled/sirv/index.js"), { name } = publicDir, assetMiddleware = sirv(
|
|
6349
|
+
})), normalizePublicDirs(server?.publicDir))){
|
|
6350
|
+
let { default: sirv } = await import("../compiled/sirv/index.js"), { name } = publicDir, assetMiddleware = sirv((0, external_node_path_.isAbsolute)(name) ? name : (0, external_node_path_.join)(pwd, name), {
|
|
5965
6351
|
etag: !0,
|
|
5966
6352
|
dev: !0
|
|
5967
6353
|
});
|
|
@@ -5970,10 +6356,10 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5970
6356
|
for (let callback of postCallbacks)callback();
|
|
5971
6357
|
return compilationManager && middlewares.push((({ htmlFallback, distPath, compilationManager })=>async (req, res, next)=>{
|
|
5972
6358
|
if (!maybeHTMLRequest(req) || '/favicon.ico' === req.url || 'index' !== htmlFallback) return void next();
|
|
5973
|
-
let filePath =
|
|
6359
|
+
let filePath = external_node_path_.default.join(distPath, 'index.html');
|
|
5974
6360
|
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) {
|
|
5975
6361
|
let newUrl = '/index.html';
|
|
5976
|
-
'verbose' === logger.level && logger.debug(
|
|
6362
|
+
'verbose' === logger.level && logger.debug(` ${req.method} ${req.url} ${picocolors.yellow('fallback to')} ${newUrl}`), req.url = newUrl, compilationManager.middleware(req, res, (...args)=>{
|
|
5977
6363
|
next(...args);
|
|
5978
6364
|
});
|
|
5979
6365
|
return;
|
|
@@ -5983,7 +6369,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
5983
6369
|
compilationManager,
|
|
5984
6370
|
distPath: context.distPath,
|
|
5985
6371
|
htmlFallback: server.htmlFallback
|
|
5986
|
-
})), server.historyApiFallback && (middlewares.push(historyApiFallbackMiddleware(!0 === server.historyApiFallback ? {} : server.historyApiFallback)),
|
|
6372
|
+
})), server.historyApiFallback && (middlewares.push(historyApiFallbackMiddleware(!0 === server.historyApiFallback ? {} : server.historyApiFallback)), compilationManager?.middleware && middlewares.push(compilationManager.middleware)), middlewares.push(faviconFallbackMiddleware), {
|
|
5987
6373
|
onUpgrade: (...args)=>{
|
|
5988
6374
|
for (let cb of upgradeEvents)cb(...args);
|
|
5989
6375
|
}
|
|
@@ -6012,7 +6398,7 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
6012
6398
|
});
|
|
6013
6399
|
return middlewares.push(...after), {
|
|
6014
6400
|
close: async ()=>{
|
|
6015
|
-
await
|
|
6401
|
+
await compilationManager?.close();
|
|
6016
6402
|
},
|
|
6017
6403
|
onUpgrade,
|
|
6018
6404
|
middlewares
|
|
@@ -6032,15 +6418,14 @@ let faviconFallbackMiddleware = (req, res, next)=>{
|
|
|
6032
6418
|
});
|
|
6033
6419
|
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
6034
6420
|
};
|
|
6035
|
-
function basic_define_property(obj, key, value) {
|
|
6036
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
6037
|
-
value: value,
|
|
6038
|
-
enumerable: !0,
|
|
6039
|
-
configurable: !0,
|
|
6040
|
-
writable: !0
|
|
6041
|
-
}) : obj[key] = value, obj;
|
|
6042
|
-
}
|
|
6043
6421
|
class BasicRunner {
|
|
6422
|
+
_options;
|
|
6423
|
+
globalContext = null;
|
|
6424
|
+
baseModuleScope = null;
|
|
6425
|
+
requirers = new Map();
|
|
6426
|
+
constructor(_options){
|
|
6427
|
+
this._options = _options;
|
|
6428
|
+
}
|
|
6044
6429
|
run(file) {
|
|
6045
6430
|
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
6046
6431
|
let res = this.getRequire()(this._options.dist, file.startsWith('./') ? file : `./${file}`);
|
|
@@ -6052,11 +6437,11 @@ class BasicRunner {
|
|
|
6052
6437
|
}
|
|
6053
6438
|
getFile(modulePath, currentDirectory) {
|
|
6054
6439
|
if (Array.isArray(modulePath)) return {
|
|
6055
|
-
path:
|
|
6440
|
+
path: external_node_path_.default.join(currentDirectory, '.array-require.js'),
|
|
6056
6441
|
content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
|
|
6057
6442
|
subPath: ''
|
|
6058
6443
|
};
|
|
6059
|
-
let joinedPath = /^\.\.?\//.test(modulePath) ?
|
|
6444
|
+
let joinedPath = /^\.\.?\//.test(modulePath) ? external_node_path_.default.join(currentDirectory, modulePath) : modulePath;
|
|
6060
6445
|
return this._options.isBundleOutput(joinedPath) ? {
|
|
6061
6446
|
path: joinedPath,
|
|
6062
6447
|
content: this._options.readFileSync(joinedPath),
|
|
@@ -6080,11 +6465,8 @@ class BasicRunner {
|
|
|
6080
6465
|
throw Error(`${picocolors.dim('[rsbuild:runner]')} Not implemented`);
|
|
6081
6466
|
});
|
|
6082
6467
|
}
|
|
6083
|
-
constructor(_options){
|
|
6084
|
-
basic_define_property(this, "_options", void 0), basic_define_property(this, "globalContext", void 0), basic_define_property(this, "baseModuleScope", void 0), basic_define_property(this, "requirers", void 0), this._options = _options, this.globalContext = null, this.baseModuleScope = null, this.requirers = new Map();
|
|
6085
|
-
}
|
|
6086
6468
|
}
|
|
6087
|
-
let cjs_require = createRequire(import.meta.url), cjs_define = (...args)=>{
|
|
6469
|
+
let cjs_require = (0, external_node_module_.createRequire)(import.meta.url), cjs_define = (...args)=>{
|
|
6088
6470
|
args.pop()();
|
|
6089
6471
|
};
|
|
6090
6472
|
class CommonJsRunner extends BasicRunner {
|
|
@@ -6113,10 +6495,10 @@ class CommonJsRunner extends BasicRunner {
|
|
|
6113
6495
|
createModuleScope(requireFn, m, file) {
|
|
6114
6496
|
return {
|
|
6115
6497
|
...this.baseModuleScope,
|
|
6116
|
-
require: requireFn.bind(null,
|
|
6498
|
+
require: requireFn.bind(null, external_node_path_.default.dirname(file.path)),
|
|
6117
6499
|
module: m,
|
|
6118
6500
|
exports: m.exports,
|
|
6119
|
-
__dirname:
|
|
6501
|
+
__dirname: external_node_path_.default.dirname(file.path),
|
|
6120
6502
|
__filename: file.path,
|
|
6121
6503
|
define: cjs_define
|
|
6122
6504
|
};
|
|
@@ -6157,12 +6539,11 @@ class CommonJsRunner extends BasicRunner {
|
|
|
6157
6539
|
}
|
|
6158
6540
|
}
|
|
6159
6541
|
var type_EsmMode = ((EsmMode = {})[EsmMode.Unknown = 0] = "Unknown", EsmMode[EsmMode.Evaluated = 1] = "Evaluated", EsmMode[EsmMode.Unlinked = 2] = "Unlinked", EsmMode);
|
|
6160
|
-
let esm_require = createRequire(import.meta.url);
|
|
6542
|
+
let esm_require = (0, external_node_module_.createRequire)(import.meta.url);
|
|
6161
6543
|
class EsmRunner extends CommonJsRunner {
|
|
6162
6544
|
createRunner() {
|
|
6163
|
-
var _this__options_compilerOptions_experiments;
|
|
6164
6545
|
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
6165
|
-
let outputModule =
|
|
6546
|
+
let outputModule = this._options.compilerOptions.experiments?.outputModule;
|
|
6166
6547
|
this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
|
|
6167
6548
|
let file = this.getFile(modulePath, currentDirectory);
|
|
6168
6549
|
return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
@@ -6183,15 +6564,15 @@ class EsmRunner extends CommonJsRunner {
|
|
|
6183
6564
|
let esm = esmCache.get(file.path);
|
|
6184
6565
|
return (esm || (esm = new vm.SourceTextModule(file.content, {
|
|
6185
6566
|
identifier: `${esmIdentifier}-${file.path}`,
|
|
6186
|
-
url: `${pathToFileURL(file.path).href}?${esmIdentifier}`,
|
|
6567
|
+
url: `${(0, external_node_url_.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
6187
6568
|
initializeImportMeta: (meta, _)=>{
|
|
6188
|
-
meta.url = pathToFileURL(file.path).href;
|
|
6569
|
+
meta.url = (0, external_node_url_.pathToFileURL)(file.path).href;
|
|
6189
6570
|
},
|
|
6190
|
-
importModuleDynamically: async (specifier, module)=>asModule(await _require(
|
|
6571
|
+
importModuleDynamically: async (specifier, module)=>asModule(await _require(external_node_path_.default.dirname(file.path), specifier, {
|
|
6191
6572
|
esmMode: type_EsmMode.Evaluated
|
|
6192
6573
|
}), module.context)
|
|
6193
6574
|
}), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
|
|
6194
|
-
if (await esm.link(async (specifier, referencingModule)=>asModule(await _require(
|
|
6575
|
+
if (await esm.link(async (specifier, referencingModule)=>asModule(await _require(external_node_path_.default.dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, external_node_url_.fileURLToPath)(referencingModule.url)), specifier, {
|
|
6195
6576
|
esmMode: type_EsmMode.Unlinked
|
|
6196
6577
|
}), referencingModule.context, !0)), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
|
|
6197
6578
|
let ns = esm.namespace;
|
|
@@ -6201,6 +6582,10 @@ class EsmRunner extends CommonJsRunner {
|
|
|
6201
6582
|
}
|
|
6202
6583
|
}
|
|
6203
6584
|
class BasicRunnerFactory {
|
|
6585
|
+
name;
|
|
6586
|
+
constructor(name){
|
|
6587
|
+
this.name = name;
|
|
6588
|
+
}
|
|
6204
6589
|
create(options) {
|
|
6205
6590
|
return this.createRunner(options);
|
|
6206
6591
|
}
|
|
@@ -6212,15 +6597,6 @@ class BasicRunnerFactory {
|
|
|
6212
6597
|
if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`${picocolors.dim('[rsbuild:runner]')} Not support run ${picocolors.yellow(compilerOptions.target)} resource in Rsbuild server`);
|
|
6213
6598
|
return new EsmRunner(runnerOptions);
|
|
6214
6599
|
}
|
|
6215
|
-
constructor(name){
|
|
6216
|
-
var key, value;
|
|
6217
|
-
value = void 0, (key = "name") in this ? Object.defineProperty(this, key, {
|
|
6218
|
-
value: value,
|
|
6219
|
-
enumerable: !0,
|
|
6220
|
-
configurable: !0,
|
|
6221
|
-
writable: !0
|
|
6222
|
-
}) : this[key] = value, this.name = name;
|
|
6223
|
-
}
|
|
6224
6600
|
}
|
|
6225
6601
|
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
6226
6602
|
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
@@ -6232,17 +6608,14 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
6232
6608
|
entrypoints: !0,
|
|
6233
6609
|
outputPath: !0
|
|
6234
6610
|
});
|
|
6235
|
-
if (!
|
|
6611
|
+
if (!entrypoints?.[entryName]) throw Error(`${picocolors.dim('[rsbuild:loadBundle]')} Can't find entry: ${picocolors.yellow(entryName)}`);
|
|
6236
6612
|
let { chunks: entryChunks = [] } = entrypoints[entryName], files = entryChunks.reduce((prev, entryChunkName)=>{
|
|
6237
|
-
let chunk =
|
|
6238
|
-
|
|
6239
|
-
return chunk.entry && (null == (_chunk_names = chunk.names) ? void 0 : _chunk_names.includes(String(entryChunkName)));
|
|
6240
|
-
});
|
|
6241
|
-
return (null == chunk ? void 0 : chunk.files) ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
6613
|
+
let chunk = chunks?.find((chunk)=>chunk.entry && chunk.names?.includes(String(entryChunkName)));
|
|
6614
|
+
return chunk?.files ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
6242
6615
|
}, []);
|
|
6243
6616
|
if (0 === files.length) throw Error(`${picocolors.dim('[rsbuild:loadBundle]')} Failed to get bundle by entryName: ${picocolors.yellow(entryName)}`);
|
|
6244
6617
|
if (files.length > 1) throw Error(`${picocolors.dim('[rsbuild:loadBundle]')} Only support load single entry chunk, but got ${picocolors.yellow(files.length)}: ${files.join(',')}`);
|
|
6245
|
-
let allChunkFiles =
|
|
6618
|
+
let allChunkFiles = chunks?.flatMap((c)=>c.files).map((file)=>(0, external_node_path_.join)(outputPath, file)) || [];
|
|
6246
6619
|
return await runner_run({
|
|
6247
6620
|
bundlePath: files[0],
|
|
6248
6621
|
dist: outputPath,
|
|
@@ -6254,7 +6627,7 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
6254
6627
|
let cache = new WeakMap();
|
|
6255
6628
|
return async (stats, entryName, utils)=>{
|
|
6256
6629
|
let cachedEntries = cache.get(stats);
|
|
6257
|
-
if (
|
|
6630
|
+
if (cachedEntries?.[entryName]) return cachedEntries[entryName];
|
|
6258
6631
|
let res = await getter(stats, entryName, utils);
|
|
6259
6632
|
return cache.set(stats, {
|
|
6260
6633
|
...cachedEntries || {},
|
|
@@ -6313,8 +6686,8 @@ async function setupWatchFiles(options) {
|
|
|
6313
6686
|
return {
|
|
6314
6687
|
async close () {
|
|
6315
6688
|
await Promise.all([
|
|
6316
|
-
|
|
6317
|
-
|
|
6689
|
+
closeDevFilesWatcher?.(),
|
|
6690
|
+
serverFilesWatcher?.close()
|
|
6318
6691
|
]);
|
|
6319
6692
|
}
|
|
6320
6693
|
};
|
|
@@ -6383,7 +6756,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6383
6756
|
let startCompile = async ()=>{
|
|
6384
6757
|
let compiler = customCompiler || await createCompiler();
|
|
6385
6758
|
if (!compiler) throw Error(`${picocolors.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
6386
|
-
|
|
6759
|
+
compiler?.hooks.watchRun.tap('rsbuild:watchRun', ()=>{
|
|
6387
6760
|
lastStats && (waitLastCompileDoneResolve && (waitLastCompileDoneResolve(), waitLastCompileDoneResolve = null), waitLastCompileDone = new Promise((resolve)=>{
|
|
6388
6761
|
waitLastCompileDoneResolve = resolve;
|
|
6389
6762
|
}));
|
|
@@ -6416,9 +6789,9 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6416
6789
|
config,
|
|
6417
6790
|
clearCache: !0
|
|
6418
6791
|
}), cleanupGracefulShutdown = middlewareMode ? null : setupGracefulShutdown(), closeServer = async ()=>{
|
|
6419
|
-
removeCleanup(closeServer),
|
|
6420
|
-
|
|
6421
|
-
|
|
6792
|
+
removeCleanup(closeServer), cleanupGracefulShutdown?.(), await context.hooks.onCloseDevServer.callBatch(), await Promise.all([
|
|
6793
|
+
devMiddlewares?.close(),
|
|
6794
|
+
fileWatcher?.close()
|
|
6422
6795
|
]);
|
|
6423
6796
|
};
|
|
6424
6797
|
middlewareMode || registerCleanup(closeServer);
|
|
@@ -6440,7 +6813,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6440
6813
|
}, cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>((entryName, utils)=>{
|
|
6441
6814
|
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
6442
6815
|
if (!htmlPath) throw Error(`${picocolors.dim('[rsbuild:getTransformedHtml]')} Failed to get HTML file by entryName: ${picocolors.yellow(entryName)}`);
|
|
6443
|
-
let fileName = join(distPath, htmlPath);
|
|
6816
|
+
let fileName = (0, external_node_path_.join)(distPath, htmlPath);
|
|
6444
6817
|
return utils.readFileSync(fileName);
|
|
6445
6818
|
})(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(context.environments).map(([name, environment])=>[
|
|
6446
6819
|
name,
|
|
@@ -6473,7 +6846,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6473
6846
|
middlewares,
|
|
6474
6847
|
environments: environmentAPI,
|
|
6475
6848
|
httpServer,
|
|
6476
|
-
sockWrite: (type, data)=>
|
|
6849
|
+
sockWrite: (type, data)=>compilationManager?.socketServer.sockWrite({
|
|
6477
6850
|
type,
|
|
6478
6851
|
data
|
|
6479
6852
|
}),
|
|
@@ -6527,7 +6900,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
6527
6900
|
context,
|
|
6528
6901
|
postCallbacks
|
|
6529
6902
|
})).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
|
|
6530
|
-
return
|
|
6903
|
+
return compilationManager?.watch(), logger.debug('create dev server done'), devServerAPI;
|
|
6531
6904
|
}
|
|
6532
6905
|
let rspackProvider = ({ context, pluginManager, rsbuildOptions })=>{
|
|
6533
6906
|
let createCompiler = async ()=>(await createCompiler_createCompiler({
|
|
@@ -6566,11 +6939,11 @@ let rspackProvider = ({ context, pluginManager, rsbuildOptions })=>{
|
|
|
6566
6939
|
rsbuildOptions
|
|
6567
6940
|
}, options),
|
|
6568
6941
|
async initConfigs (options) {
|
|
6569
|
-
if (context.action &&
|
|
6942
|
+
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
6570
6943
|
[rsbuild] initConfigs() can only be called with the same action type.
|
|
6571
6944
|
- Expected: ${context.action}
|
|
6572
|
-
- Actual: ${
|
|
6573
|
-
|
|
6945
|
+
- Actual: ${options?.action}`);
|
|
6946
|
+
options?.action && (context.action = options.action);
|
|
6574
6947
|
let { rspackConfigs } = await initConfigs({
|
|
6575
6948
|
context,
|
|
6576
6949
|
pluginManager,
|
|
@@ -6594,15 +6967,13 @@ let rspackProvider = ({ context, pluginManager, rsbuildOptions })=>{
|
|
|
6594
6967
|
}
|
|
6595
6968
|
};
|
|
6596
6969
|
};
|
|
6597
|
-
function prodServer_define_property(obj, key, value) {
|
|
6598
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
6599
|
-
value: value,
|
|
6600
|
-
enumerable: !0,
|
|
6601
|
-
configurable: !0,
|
|
6602
|
-
writable: !0
|
|
6603
|
-
}) : obj[key] = value, obj;
|
|
6604
|
-
}
|
|
6605
6970
|
class RsbuildProdServer {
|
|
6971
|
+
app;
|
|
6972
|
+
options;
|
|
6973
|
+
middlewares;
|
|
6974
|
+
constructor(options, middlewares){
|
|
6975
|
+
this.options = options, this.middlewares = middlewares;
|
|
6976
|
+
}
|
|
6606
6977
|
async onInit(app) {
|
|
6607
6978
|
this.app = app, await this.applyDefaultMiddlewares();
|
|
6608
6979
|
}
|
|
@@ -6642,15 +7013,12 @@ class RsbuildProdServer {
|
|
|
6642
7013
|
});
|
|
6643
7014
|
this.middlewares.use((req, res, next)=>{
|
|
6644
7015
|
let url = req.url, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
6645
|
-
assetPrefix &&
|
|
7016
|
+
assetPrefix && url?.startsWith(assetPrefix) ? (req.url = url.slice(assetPrefix.length), assetMiddleware(req, res, (...args)=>{
|
|
6646
7017
|
req.url = url, next(...args);
|
|
6647
7018
|
})) : assetMiddleware(req, res, next);
|
|
6648
7019
|
});
|
|
6649
7020
|
}
|
|
6650
7021
|
async close() {}
|
|
6651
|
-
constructor(options, middlewares){
|
|
6652
|
-
prodServer_define_property(this, "app", void 0), prodServer_define_property(this, "options", void 0), prodServer_define_property(this, "middlewares", void 0), this.options = options, this.middlewares = middlewares;
|
|
6653
|
-
}
|
|
6654
7022
|
}
|
|
6655
7023
|
async function startProdServer(context, config, { getPortSilently } = {}) {
|
|
6656
7024
|
let { port, host, https, portTip } = await getServerConfig({
|
|
@@ -6730,7 +7098,6 @@ async function createRsbuild(options = {}) {
|
|
|
6730
7098
|
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
6731
7099
|
}) : null, config = isFunction(options.rsbuildConfig) ? await options.rsbuildConfig() : options.rsbuildConfig || {};
|
|
6732
7100
|
config.logLevel && (logger.level = config.logLevel), function(config, envs) {
|
|
6733
|
-
var _config_performance;
|
|
6734
7101
|
if (null !== envs && (config.source ||= {}, config.source.define = {
|
|
6735
7102
|
...envs.publicVars,
|
|
6736
7103
|
...config.source.define
|
|
@@ -6740,7 +7107,7 @@ async function createRsbuild(options = {}) {
|
|
|
6740
7107
|
paths: envs.filePaths,
|
|
6741
7108
|
type: 'reload-server'
|
|
6742
7109
|
}
|
|
6743
|
-
],
|
|
7110
|
+
], config.performance?.buildCache))) {
|
|
6744
7111
|
let { buildCache } = config.performance;
|
|
6745
7112
|
!0 === buildCache ? config.performance.buildCache = {
|
|
6746
7113
|
buildDependencies: envs.filePaths
|
|
@@ -6819,7 +7186,7 @@ async function createRsbuild(options = {}) {
|
|
|
6819
7186
|
}(context);
|
|
6820
7187
|
function getNormalizedConfig(options) {
|
|
6821
7188
|
if (context.normalizedConfig) {
|
|
6822
|
-
if (
|
|
7189
|
+
if (options?.environment) {
|
|
6823
7190
|
let config = context.normalizedConfig.environments[options.environment];
|
|
6824
7191
|
if (!config) throw Error(`${picocolors.dim('[rsbuild]')} Cannot find normalized config by environment: ${options.environment}.`);
|
|
6825
7192
|
return config;
|
|
@@ -6850,6 +7217,7 @@ async function createRsbuild(options = {}) {
|
|
|
6850
7217
|
hooks.modifyBundlerChain.tap((chain, { target, environment })=>{
|
|
6851
7218
|
let pluginName = 'RsbuildCorePlugin';
|
|
6852
7219
|
chain.plugin(pluginName).use(class {
|
|
7220
|
+
name = pluginName;
|
|
6853
7221
|
apply(compiler) {
|
|
6854
7222
|
for (let { handler, environment: pluginEnvironment } of (compiler.__rsbuildTransformer = transformer, resolveFns))(!pluginEnvironment || isEnvironmentMatch(pluginEnvironment, environment.name)) && compiler.hooks.compilation.tap(pluginName, (compilation, { normalModuleFactory })=>{
|
|
6855
7223
|
normalModuleFactory.hooks.resolve.tapPromise(pluginName, async (resolveData)=>handler({
|
|
@@ -6876,15 +7244,6 @@ async function createRsbuild(options = {}) {
|
|
|
6876
7244
|
}));
|
|
6877
7245
|
});
|
|
6878
7246
|
}
|
|
6879
|
-
constructor(){
|
|
6880
|
-
var key;
|
|
6881
|
-
(key = "name") in this ? Object.defineProperty(this, key, {
|
|
6882
|
-
value: pluginName,
|
|
6883
|
-
enumerable: !0,
|
|
6884
|
-
configurable: !0,
|
|
6885
|
-
writable: !0
|
|
6886
|
-
}) : this[key] = pluginName;
|
|
6887
|
-
}
|
|
6888
7247
|
});
|
|
6889
7248
|
});
|
|
6890
7249
|
let onExitListened = !1, onExit = (cb)=>{
|
|
@@ -6916,7 +7275,7 @@ async function createRsbuild(options = {}) {
|
|
|
6916
7275
|
if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
|
|
6917
7276
|
let rule = chain.module.rule(id);
|
|
6918
7277
|
descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with), descriptor.mimetype && rule.mimetype(descriptor.mimetype), descriptor.order && 'default' !== descriptor.order ? rule.enforce(descriptor.order) : descriptor.enforce && rule.enforce(descriptor.enforce);
|
|
6919
|
-
let
|
|
7278
|
+
let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, external_node_path_.join)(LOADER_PATH, loaderName);
|
|
6920
7279
|
rule.use(id).loader(loaderPath).options({
|
|
6921
7280
|
id,
|
|
6922
7281
|
getEnvironment: ()=>environment
|
|
@@ -6946,6 +7305,7 @@ async function createRsbuild(options = {}) {
|
|
|
6946
7305
|
onCloseBuild: hooks.onCloseBuild.tap,
|
|
6947
7306
|
onBeforeBuild: hooks.onBeforeBuild.tap,
|
|
6948
7307
|
onCloseDevServer: hooks.onCloseDevServer.tap,
|
|
7308
|
+
onBeforeDevCompile: hooks.onBeforeDevCompile.tap,
|
|
6949
7309
|
onDevCompileDone: hooks.onDevCompileDone.tap,
|
|
6950
7310
|
onAfterCreateCompiler: hooks.onAfterCreateCompiler.tap,
|
|
6951
7311
|
onAfterStartDevServer: hooks.onAfterStartDevServer.tap,
|
|
@@ -7082,7 +7442,7 @@ async function createRsbuild(options = {}) {
|
|
|
7082
7442
|
if (!1 === buildCache) return;
|
|
7083
7443
|
cacheEnabled = !0;
|
|
7084
7444
|
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = function({ cacheDirectory }, context) {
|
|
7085
|
-
return cacheDirectory ?
|
|
7445
|
+
return cacheDirectory ? (0, external_node_path_.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_.join)(context.rootPath, cacheDirectory) : (0, external_node_path_.join)(context.cachePath, context.bundlerType);
|
|
7086
7446
|
}(cacheConfig, context), buildDependencies = await getBuildDependencies(context, config, environment, cacheConfig.buildDependencies ? {
|
|
7087
7447
|
userBuildDependencies: cacheConfig.buildDependencies
|
|
7088
7448
|
} : {});
|
|
@@ -7140,17 +7500,16 @@ async function createRsbuild(options = {}) {
|
|
|
7140
7500
|
api.modifyBundlerChain((chain, { CHAIN_ID, isDev, isProd, isServer, environment, rspack })=>{
|
|
7141
7501
|
var jsAsync;
|
|
7142
7502
|
let { distPath, config } = environment, publicPath = function({ isDev, config, context }) {
|
|
7143
|
-
var _context_devServer, _context_devServer1, _context_devServer2;
|
|
7144
7503
|
let { dev, output, server } = config, publicPath = DEFAULT_ASSET_PREFIX;
|
|
7145
7504
|
if (isDev) {
|
|
7146
7505
|
if ('string' == typeof dev.assetPrefix) publicPath = dev.assetPrefix;
|
|
7147
7506
|
else if (dev.assetPrefix) {
|
|
7148
|
-
let protocol =
|
|
7507
|
+
let protocol = context.devServer?.https ? 'https' : 'http', hostname = context.devServer?.hostname || DEFAULT_DEV_HOST;
|
|
7149
7508
|
publicPath = hostname === DEFAULT_DEV_HOST ? `${protocol}://localhost:<port>/` : `${protocol}://${hostname}:<port>/`, server.base && '/' !== server.base && (publicPath = urlJoin(publicPath, server.base));
|
|
7150
7509
|
}
|
|
7151
7510
|
} else 'string' == typeof output.assetPrefix && (publicPath = output.assetPrefix);
|
|
7152
7511
|
let defaultPort = server.port ?? 3000;
|
|
7153
|
-
return formatPublicPath(replacePortPlaceholder(publicPath, isDev ?
|
|
7512
|
+
return formatPublicPath(replacePortPlaceholder(publicPath, isDev ? context.devServer?.port ?? defaultPort : defaultPort));
|
|
7154
7513
|
}({
|
|
7155
7514
|
config,
|
|
7156
7515
|
isDev,
|
|
@@ -7158,11 +7517,11 @@ async function createRsbuild(options = {}) {
|
|
|
7158
7517
|
}), jsPath = config.output.distPath.js, jsAsyncPath = void 0 !== (jsAsync = config.output.distPath.jsAsync) ? jsAsync : isServer ? jsPath : jsPath ? `${jsPath}/async` : 'async', jsFilename = getFilename(config, 'js', isProd, isServer), isJsFilenameFn = 'function' == typeof jsFilename;
|
|
7159
7518
|
if (chain.output.path(distPath).filename(isJsFilenameFn ? (...args)=>{
|
|
7160
7519
|
let name = jsFilename(...args);
|
|
7161
|
-
return posix.join(jsPath, name);
|
|
7162
|
-
} : posix.join(jsPath, jsFilename)).chunkFilename(isJsFilenameFn ? (...args)=>{
|
|
7520
|
+
return external_node_path_.posix.join(jsPath, name);
|
|
7521
|
+
} : external_node_path_.posix.join(jsPath, jsFilename)).chunkFilename(isJsFilenameFn ? (...args)=>{
|
|
7163
7522
|
let name = jsFilename(...args);
|
|
7164
|
-
return posix.join(jsAsyncPath, name);
|
|
7165
|
-
} : posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath).pathinfo(!1).hashFunction('xxhash64'), isServer && chain.output.library({
|
|
7523
|
+
return external_node_path_.posix.join(jsAsyncPath, name);
|
|
7524
|
+
} : external_node_path_.posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath).pathinfo(!1).hashFunction('xxhash64'), isServer && chain.output.library({
|
|
7166
7525
|
type: 'commonjs2',
|
|
7167
7526
|
...chain.output.get('library') || {}
|
|
7168
7527
|
}), config.output.copy && 'rspack' === api.context.bundlerType) {
|
|
@@ -7207,7 +7566,7 @@ async function createRsbuild(options = {}) {
|
|
|
7207
7566
|
continue;
|
|
7208
7567
|
}
|
|
7209
7568
|
try {
|
|
7210
|
-
pkgPath = dirname(resolve_require.resolve(`${pkgName}/package.json`, {
|
|
7569
|
+
pkgPath = (0, external_node_path_.dirname)(resolve_require.resolve(`${pkgName}/package.json`, {
|
|
7211
7570
|
paths: [
|
|
7212
7571
|
rootPath
|
|
7213
7572
|
]
|
|
@@ -7222,8 +7581,8 @@ async function createRsbuild(options = {}) {
|
|
|
7222
7581
|
let trailing = [
|
|
7223
7582
|
'node_modules',
|
|
7224
7583
|
...pkgName.split('/')
|
|
7225
|
-
].join(sep);
|
|
7226
|
-
for(; !pkgPath.endsWith(trailing) && pkgPath.includes('node_modules');)pkgPath = dirname(pkgPath);
|
|
7584
|
+
].join(external_node_path_.sep);
|
|
7585
|
+
for(; !pkgPath.endsWith(trailing) && pkgPath.includes('node_modules');)pkgPath = (0, external_node_path_.dirname)(pkgPath);
|
|
7227
7586
|
} catch {
|
|
7228
7587
|
logger.debug(`${picocolors.dim('[rsbuild:resolve]')} The package ${picocolors.yellow(pkgName)} is not resolved in the project, dedupe option for ${picocolors.yellow(pkgName)} will be ignored.`);
|
|
7229
7588
|
continue;
|
|
@@ -7290,7 +7649,7 @@ async function createRsbuild(options = {}) {
|
|
|
7290
7649
|
} : void 0;
|
|
7291
7650
|
})(environment, params.isDev)),
|
|
7292
7651
|
(()=>{
|
|
7293
|
-
let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), targetPath = join(distPath, RSBUILD_OUTPUTS_PATH), { enable } = normalizeCleanDistPath(config.output.cleanDistPath);
|
|
7652
|
+
let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), targetPath = (0, external_node_path_.join)(distPath, RSBUILD_OUTPUTS_PATH), { enable } = normalizeCleanDistPath(config.output.cleanDistPath);
|
|
7294
7653
|
if (!0 === enable || 'auto' === enable && isStrictSubdir(rootPath, targetPath)) return {
|
|
7295
7654
|
path: targetPath
|
|
7296
7655
|
};
|
|
@@ -7317,8 +7676,8 @@ async function createRsbuild(options = {}) {
|
|
|
7317
7676
|
let distDir = config.output.distPath[assetType], filename = getFilename(config, assetType, isProd);
|
|
7318
7677
|
return 'function' == typeof filename ? (...args)=>{
|
|
7319
7678
|
let name = filename(...args);
|
|
7320
|
-
return
|
|
7321
|
-
} :
|
|
7679
|
+
return external_node_path_.default.posix.join(distDir, name);
|
|
7680
|
+
} : external_node_path_.default.posix.join(distDir, filename);
|
|
7322
7681
|
}, createAssetRule = (assetType, exts, emit)=>{
|
|
7323
7682
|
let regExp = function(exts) {
|
|
7324
7683
|
let matcher = exts.map((ext)=>ext.trim()).map((ext)=>ext.startsWith('.') ? ext.slice(1) : ext).join('|');
|
|
@@ -7485,10 +7844,7 @@ async function createRsbuild(options = {}) {
|
|
|
7485
7844
|
];
|
|
7486
7845
|
if (crossorigin) {
|
|
7487
7846
|
let formattedCrossorigin = !0 === crossorigin ? 'anonymous' : crossorigin;
|
|
7488
|
-
for (let tag of allTags)
|
|
7489
|
-
var _tag_attrs, _tag_attrs1;
|
|
7490
|
-
("script" === tag.tag && (null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.src) || 'link' === tag.tag && (null == (_tag_attrs1 = tag.attrs) ? void 0 : _tag_attrs1.rel) === 'stylesheet') && (tag.attrs.crossorigin ??= formattedCrossorigin);
|
|
7491
|
-
}
|
|
7847
|
+
for (let tag of allTags)("script" === tag.tag && tag.attrs?.src || 'link' === tag.tag && tag.attrs?.rel === 'stylesheet') && (tag.attrs.crossorigin ??= formattedCrossorigin);
|
|
7492
7848
|
}
|
|
7493
7849
|
return {
|
|
7494
7850
|
headTags,
|
|
@@ -7521,7 +7877,7 @@ async function createRsbuild(options = {}) {
|
|
|
7521
7877
|
};
|
|
7522
7878
|
return iconFormatMap.set(src, formatted), formatted;
|
|
7523
7879
|
}
|
|
7524
|
-
let absolutePath =
|
|
7880
|
+
let absolutePath = external_node_path_.default.isAbsolute(src) ? src : external_node_path_.default.join(api.context.rootPath, src), relativePath = external_node_path_.default.posix.join(distDir, external_node_path_.default.basename(absolutePath)), formatted = {
|
|
7525
7881
|
...icon,
|
|
7526
7882
|
sizes,
|
|
7527
7883
|
src: ensureAssetPrefix(relativePath, publicPath),
|
|
@@ -7602,7 +7958,7 @@ async function createRsbuild(options = {}) {
|
|
|
7602
7958
|
name: 'rsbuild:wasm',
|
|
7603
7959
|
setup (api) {
|
|
7604
7960
|
api.modifyBundlerChain((chain, { CHAIN_ID, environment, isProd })=>{
|
|
7605
|
-
let { config } = environment, distPath = config.output.distPath.wasm, filename = posix.join(distPath, getFilename(config, 'wasm', isProd));
|
|
7961
|
+
let { config } = environment, distPath = config.output.distPath.wasm, filename = external_node_path_.posix.join(distPath, 'webpack' === api.context.bundlerType ? '[hash].module.wasm' : getFilename(config, 'wasm', isProd));
|
|
7606
7962
|
chain.experiments({
|
|
7607
7963
|
...chain.get('experiments'),
|
|
7608
7964
|
asyncWebAssembly: !0
|
|
@@ -7639,7 +7995,7 @@ async function createRsbuild(options = {}) {
|
|
|
7639
7995
|
let name = ((resourcePath)=>{
|
|
7640
7996
|
let basename = '';
|
|
7641
7997
|
if (resourcePath) {
|
|
7642
|
-
let parsed =
|
|
7998
|
+
let parsed = external_node_path_.default.parse(resourcePath);
|
|
7643
7999
|
parsed.dir && (basename = parsed.name);
|
|
7644
8000
|
}
|
|
7645
8001
|
return basename ? `${basename}.node` : null;
|
|
@@ -7713,14 +8069,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7713
8069
|
});
|
|
7714
8070
|
rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
7715
8071
|
} else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader((cssExtractPlugin || rspack_rspack.CssExtractRspackPlugin).loader).options(config.tools.cssExtract.loaderOptions);
|
|
7716
|
-
else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(
|
|
8072
|
+
else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_.default.join(LOADER_PATH, 'ignoreCssLoader.mjs'));
|
|
7717
8073
|
let importLoaders = 0, updateRules = (callback)=>{
|
|
7718
8074
|
callback(rule, 'normal'), callback(inlineRule, 'inline');
|
|
7719
8075
|
}, cssLoaderPath = getCompiledPath('css-loader');
|
|
7720
8076
|
if (updateRules((rule)=>{
|
|
7721
8077
|
rule.use(CHAIN_ID.USE.CSS).loader(cssLoaderPath);
|
|
7722
8078
|
}), emitCss) {
|
|
7723
|
-
var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
|
|
7724
8079
|
if ('rspack' === api.context.bundlerType && !1 !== config.tools.lightningcssLoader) {
|
|
7725
8080
|
importLoaders++;
|
|
7726
8081
|
let { minifyCss } = parseMinifyOptions(config);
|
|
@@ -7734,7 +8089,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7734
8089
|
root: api.context.rootPath,
|
|
7735
8090
|
postcssrcCache
|
|
7736
8091
|
});
|
|
7737
|
-
if ('function' == typeof postcssLoaderOptions.postcssOptions ||
|
|
8092
|
+
if ('function' == typeof postcssLoaderOptions.postcssOptions || postcssLoaderOptions.postcssOptions?.plugins?.length) {
|
|
7738
8093
|
importLoaders++;
|
|
7739
8094
|
let postcssLoaderPath = getCompiledPath('postcss-loader');
|
|
7740
8095
|
updateRules((rule)=>{
|
|
@@ -7793,12 +8148,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7793
8148
|
{
|
|
7794
8149
|
filename: isCssFilenameFn ? (...args)=>{
|
|
7795
8150
|
let name = cssFilename(...args);
|
|
7796
|
-
return posix.join(cssPath, name);
|
|
7797
|
-
} : posix.join(cssPath, cssFilename),
|
|
8151
|
+
return external_node_path_.posix.join(cssPath, name);
|
|
8152
|
+
} : external_node_path_.posix.join(cssPath, cssFilename),
|
|
7798
8153
|
chunkFilename: isCssFilenameFn ? (...args)=>{
|
|
7799
8154
|
let name = cssFilename(...args);
|
|
7800
|
-
return posix.join(cssAsyncPath, name);
|
|
7801
|
-
} : posix.join(cssAsyncPath, cssFilename),
|
|
8155
|
+
return external_node_path_.posix.join(cssAsyncPath, name);
|
|
8156
|
+
} : external_node_path_.posix.join(cssAsyncPath, cssFilename),
|
|
7802
8157
|
...extractPluginOptions
|
|
7803
8158
|
}
|
|
7804
8159
|
]);
|
|
@@ -7827,7 +8182,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7827
8182
|
pure_funcs: pureFuncs
|
|
7828
8183
|
};
|
|
7829
8184
|
}
|
|
7830
|
-
switch(config.output.legalComments){
|
|
8185
|
+
if (config.output.legalComments) switch(config.output.legalComments){
|
|
7831
8186
|
case 'inline':
|
|
7832
8187
|
options.minimizerOptions.format.comments = 'some', options.extractComments = !1;
|
|
7833
8188
|
break;
|
|
@@ -7883,7 +8238,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7883
8238
|
api.modifyBundlerChain({
|
|
7884
8239
|
order: 'pre',
|
|
7885
8240
|
handler: (chain, { CHAIN_ID, isDev, target, environment })=>{
|
|
7886
|
-
let { config, browserslist } = environment, cacheRoot =
|
|
8241
|
+
let { config, browserslist } = environment, cacheRoot = external_node_path_.default.join(api.context.cachePath, '.swc'), rule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).type("javascript/auto").dependency({
|
|
7887
8242
|
not: 'url'
|
|
7888
8243
|
}).resourceQuery({
|
|
7889
8244
|
not: RAW_QUERY_REGEX
|
|
@@ -7946,7 +8301,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7946
8301
|
for (let item of helpers_castArray(options))isFunction(item) ? imports = item(imports) ?? imports : imports.push(item);
|
|
7947
8302
|
return imports;
|
|
7948
8303
|
})(pluginImport);
|
|
7949
|
-
|
|
8304
|
+
finalPluginImport?.length && (swcConfig.rspackExperiments ??= {}, swcConfig.rspackExperiments.import ??= [], swcConfig.rspackExperiments.import.push(...finalPluginImport));
|
|
7950
8305
|
}(swcConfig, config.source.transformImport), function(swcConfig, config) {
|
|
7951
8306
|
swcConfig.jsc ||= {}, swcConfig.jsc.transform ||= {};
|
|
7952
8307
|
let { version } = config.source.decorators;
|
|
@@ -7973,7 +8328,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7973
8328
|
} catch {
|
|
7974
8329
|
return '3';
|
|
7975
8330
|
}
|
|
7976
|
-
})(coreJsPath), coreJsDir =
|
|
8331
|
+
})(coreJsPath), coreJsDir = external_node_path_.default.dirname(coreJsPath);
|
|
7977
8332
|
return swcConfig.env.coreJs = version, 'usage' === polyfillMode && (swcConfig.env.shippedProposals = !0), coreJsDir;
|
|
7978
8333
|
}(swcConfig, polyfillMode);
|
|
7979
8334
|
for (let item of [
|
|
@@ -7992,6 +8347,24 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
7992
8347
|
});
|
|
7993
8348
|
}
|
|
7994
8349
|
},
|
|
8350
|
+
{
|
|
8351
|
+
name: 'rsbuild:esm',
|
|
8352
|
+
setup (api) {
|
|
8353
|
+
api.modifyBundlerChain((chain, { environment, isServer })=>{
|
|
8354
|
+
let { config } = environment;
|
|
8355
|
+
if (config.output.module) {
|
|
8356
|
+
if (!isServer) throw Error('[rsbuild:config] `output.module` is only supported for Node.js targets.');
|
|
8357
|
+
chain.output.module(!0).chunkFormat('module').chunkLoading('import').workerChunkLoading('import').library({
|
|
8358
|
+
...chain.output.get('library'),
|
|
8359
|
+
type: 'module'
|
|
8360
|
+
}), chain.experiments({
|
|
8361
|
+
...chain.get('experiments'),
|
|
8362
|
+
outputModule: !0
|
|
8363
|
+
});
|
|
8364
|
+
}
|
|
8365
|
+
});
|
|
8366
|
+
}
|
|
8367
|
+
},
|
|
7995
8368
|
{
|
|
7996
8369
|
name: 'rsbuild:externals',
|
|
7997
8370
|
setup (api) {
|
|
@@ -8007,7 +8380,6 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8007
8380
|
name: 'rsbuild:split-chunks',
|
|
8008
8381
|
setup (api) {
|
|
8009
8382
|
api.modifyBundlerChain(async (chain, { environment, isServer, isWebWorker })=>{
|
|
8010
|
-
var _config_moduleFederation_options, _config_moduleFederation;
|
|
8011
8383
|
if (isServer || isWebWorker) {
|
|
8012
8384
|
chain.optimization.splitChunks(!1), isWebWorker && chain.module.parser.merge({
|
|
8013
8385
|
javascript: {
|
|
@@ -8017,7 +8389,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8017
8389
|
return;
|
|
8018
8390
|
}
|
|
8019
8391
|
let { config } = environment, defaultConfig = {
|
|
8020
|
-
chunks:
|
|
8392
|
+
chunks: config.moduleFederation?.options?.exposes ? 'async' : 'all',
|
|
8021
8393
|
cacheGroups: {}
|
|
8022
8394
|
};
|
|
8023
8395
|
'webpack' === api.context.bundlerType && (defaultConfig.enforceSizeThreshold = 50000);
|
|
@@ -8070,47 +8442,46 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8070
8442
|
headTags,
|
|
8071
8443
|
bodyTags
|
|
8072
8444
|
};
|
|
8073
|
-
let publicPath = getPublicPathFromCompiler(compiler), updateTag = (tag)=>{
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
};
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
}
|
|
8111
|
-
return
|
|
8112
|
-
})(publicPath, tag, compilation, styleTests, config)
|
|
8113
|
-
};
|
|
8445
|
+
let publicPath = getPublicPathFromCompiler(compiler), updateTag = (tag)=>((publicPath, tag, compilation, scriptTests, styleTests, config)=>{
|
|
8446
|
+
if ("script" === tag.tag) return ((publicPath, tag, compilation, scriptTests, config)=>{
|
|
8447
|
+
let { assets } = compilation;
|
|
8448
|
+
if (!(tag.attrs?.src && 'string' == typeof tag.attrs.src)) return tag;
|
|
8449
|
+
let { src, ...otherAttrs } = tag.attrs, scriptName = publicPath ? src.replace(publicPath, '') : src, asset = assets[scriptName];
|
|
8450
|
+
if (null == asset || !matchTests(scriptName, asset, scriptTests)) return tag;
|
|
8451
|
+
let ret = {
|
|
8452
|
+
tag: "script",
|
|
8453
|
+
children: updateSourceMappingURL({
|
|
8454
|
+
source: asset.source().toString(),
|
|
8455
|
+
compilation,
|
|
8456
|
+
publicPath,
|
|
8457
|
+
type: 'js',
|
|
8458
|
+
config
|
|
8459
|
+
}),
|
|
8460
|
+
attrs: {
|
|
8461
|
+
...otherAttrs
|
|
8462
|
+
}
|
|
8463
|
+
};
|
|
8464
|
+
return inlinedAssets.add(scriptName), ret;
|
|
8465
|
+
})(publicPath, tag, compilation, scriptTests, config);
|
|
8466
|
+
if ('link' === tag.tag && tag.attrs && 'stylesheet' === tag.attrs.rel) {
|
|
8467
|
+
let { assets } = compilation;
|
|
8468
|
+
if (!(tag.attrs?.href && 'string' == typeof tag.attrs.href)) return tag;
|
|
8469
|
+
let linkName = publicPath ? tag.attrs.href.replace(publicPath, '') : tag.attrs.href, asset = assets[linkName];
|
|
8470
|
+
if (null == asset || !matchTests(linkName, asset, styleTests)) return tag;
|
|
8471
|
+
let ret = {
|
|
8472
|
+
tag: 'style',
|
|
8473
|
+
children: updateSourceMappingURL({
|
|
8474
|
+
source: asset.source().toString(),
|
|
8475
|
+
compilation: compilation,
|
|
8476
|
+
publicPath: publicPath,
|
|
8477
|
+
type: 'css',
|
|
8478
|
+
config: config
|
|
8479
|
+
})
|
|
8480
|
+
};
|
|
8481
|
+
return inlinedAssets.add(linkName), ret;
|
|
8482
|
+
}
|
|
8483
|
+
return tag;
|
|
8484
|
+
})(publicPath, tag, compilation, scriptTests, styleTests, environment.config);
|
|
8114
8485
|
return {
|
|
8115
8486
|
headTags: headTags.map(updateTag),
|
|
8116
8487
|
bodyTags: bodyTags.map(updateTag)
|
|
@@ -8124,14 +8495,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8124
8495
|
api.onBeforeCreateCompiler(async ({ bundlerConfigs })=>{
|
|
8125
8496
|
let packagePath, module;
|
|
8126
8497
|
if ('true' !== process.env.RSDOCTOR) return;
|
|
8127
|
-
let isRspack = 'rspack' === api.context.bundlerType, pluginName = isRspack ? 'RsdoctorRspackPlugin' : 'RsdoctorWebpackPlugin', isRsdoctorPlugin = (plugin)=>
|
|
8128
|
-
|
|
8129
|
-
return (null == plugin ? void 0 : plugin.isRsdoctorPlugin) === !0 || (null == plugin || null == (_plugin_constructor = plugin.constructor) ? void 0 : _plugin_constructor.name) === pluginName;
|
|
8130
|
-
};
|
|
8131
|
-
for (let config of bundlerConfigs){
|
|
8132
|
-
var _config_plugins;
|
|
8133
|
-
if (null == (_config_plugins = config.plugins) ? void 0 : _config_plugins.some((plugin)=>isRsdoctorPlugin(plugin))) return;
|
|
8134
|
-
}
|
|
8498
|
+
let isRspack = 'rspack' === api.context.bundlerType, pluginName = isRspack ? 'RsdoctorRspackPlugin' : 'RsdoctorWebpackPlugin', isRsdoctorPlugin = (plugin)=>plugin?.isRsdoctorPlugin === !0 || plugin?.constructor?.name === pluginName;
|
|
8499
|
+
for (let config of bundlerConfigs)if (config.plugins?.some((plugin)=>isRsdoctorPlugin(plugin))) return;
|
|
8135
8500
|
let packageName = isRspack ? '@rsdoctor/rspack-plugin' : '@rsdoctor/webpack-plugin';
|
|
8136
8501
|
try {
|
|
8137
8502
|
packagePath = rsdoctor_require.resolve(packageName, {
|
|
@@ -8144,7 +8509,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8144
8509
|
return;
|
|
8145
8510
|
}
|
|
8146
8511
|
try {
|
|
8147
|
-
let moduleURL = 'win32' === process.platform ? pathToFileURL(packagePath).href : packagePath;
|
|
8512
|
+
let moduleURL = 'win32' === process.platform ? (0, external_node_url_.pathToFileURL)(packagePath).href : packagePath;
|
|
8148
8513
|
module = await import(moduleURL);
|
|
8149
8514
|
} catch {
|
|
8150
8515
|
logger.error(`\`process.env.RSDOCTOR\` enabled, but failed to load ${picocolors.bold(picocolors.yellow(packageName))} module.`);
|
|
@@ -8219,10 +8584,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8219
8584
|
api.modifyRsbuildConfig({
|
|
8220
8585
|
order: 'post',
|
|
8221
8586
|
handler: (rsbuildConfig)=>{
|
|
8222
|
-
var _rsbuildConfig_performance, _config_performance;
|
|
8223
8587
|
let applyBundleAnalyzeConfig = (config)=>{
|
|
8224
|
-
|
|
8225
|
-
(null == (_config_performance = config.performance) ? void 0 : _config_performance.bundleAnalyze) ? config.performance.bundleAnalyze = {
|
|
8588
|
+
config.performance?.bundleAnalyze ? config.performance.bundleAnalyze = {
|
|
8226
8589
|
generateStatsFile: !0,
|
|
8227
8590
|
...config.performance.bundleAnalyze || {}
|
|
8228
8591
|
} : (config.performance ??= {}, config.performance.bundleAnalyze = {
|
|
@@ -8230,8 +8593,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8230
8593
|
generateStatsFile: !0
|
|
8231
8594
|
});
|
|
8232
8595
|
};
|
|
8233
|
-
if (
|
|
8234
|
-
else if (rsbuildConfig.environments) for (let config of Object.values(rsbuildConfig.environments))
|
|
8596
|
+
if (rsbuildConfig.performance?.profile) applyBundleAnalyzeConfig(rsbuildConfig);
|
|
8597
|
+
else if (rsbuildConfig.environments) for (let config of Object.values(rsbuildConfig.environments))config.performance?.profile && applyBundleAnalyzeConfig(config);
|
|
8235
8598
|
}
|
|
8236
8599
|
}), api.modifyBundlerChain((chain, { environment })=>{
|
|
8237
8600
|
let { config } = environment, { profile } = config.performance;
|
|
@@ -8267,21 +8630,18 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8267
8630
|
setup (api) {
|
|
8268
8631
|
let onStartServer = ({ port, routes })=>{
|
|
8269
8632
|
let config = api.getNormalizedConfig();
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
config
|
|
8277
|
-
});
|
|
8278
|
-
}
|
|
8633
|
+
config.server.open && server_open_open({
|
|
8634
|
+
https: api.context.devServer?.https,
|
|
8635
|
+
port,
|
|
8636
|
+
routes,
|
|
8637
|
+
config
|
|
8638
|
+
});
|
|
8279
8639
|
};
|
|
8280
8640
|
api.onAfterStartDevServer(onStartServer), api.onAfterStartProdServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
|
|
8281
8641
|
if (isFirstCompile) for (let publicDir of normalizePublicDirs(api.getNormalizedConfig().server.publicDir)){
|
|
8282
8642
|
let { name, copyOnBuild } = publicDir;
|
|
8283
8643
|
if (!1 === copyOnBuild || !name) continue;
|
|
8284
|
-
let normalizedPath =
|
|
8644
|
+
let normalizedPath = (0, external_node_path_.isAbsolute)(name) ? name : (0, external_node_path_.join)(api.context.rootPath, name);
|
|
8285
8645
|
if (!node_fs.existsSync(normalizedPath)) continue;
|
|
8286
8646
|
let distPaths = dedupeNestedPaths(Object.values(environments).filter(({ config })=>!0 === copyOnBuild || 'auto' === copyOnBuild && 'node' !== config.output.target).map(({ distPath })=>distPath));
|
|
8287
8647
|
try {
|
|
@@ -8333,7 +8693,6 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8333
8693
|
return file.path;
|
|
8334
8694
|
}), entries = {};
|
|
8335
8695
|
for (let [name, chunkFiles] of chunkEntries){
|
|
8336
|
-
var _files_find;
|
|
8337
8696
|
let assets = new Set(), initialJS = [], asyncJS = [], initialCSS = [], asyncCSS = [];
|
|
8338
8697
|
for (let file of chunkFiles){
|
|
8339
8698
|
file.isInitial ? file.path.endsWith('.css') ? initialCSS.push(file.path) : initialJS.push(file.path) : file.path.endsWith('.css') ? asyncCSS.push(file.path) : asyncJS.push(file.path);
|
|
@@ -8342,7 +8701,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8342
8701
|
}
|
|
8343
8702
|
let entryManifest = {};
|
|
8344
8703
|
assets.size && (entryManifest.assets = Array.from(assets));
|
|
8345
|
-
let htmlPath =
|
|
8704
|
+
let htmlPath = files.find((f)=>f.name === htmlPaths[name])?.path;
|
|
8346
8705
|
htmlPath && (entryManifest.html = [
|
|
8347
8706
|
htmlPath
|
|
8348
8707
|
]), initialJS.length && (entryManifest.initial = {
|
|
@@ -8385,14 +8744,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8385
8744
|
setup (api) {
|
|
8386
8745
|
'webpack' !== api.context.bundlerType && (api.modifyRsbuildConfig((config)=>{
|
|
8387
8746
|
let { moduleFederation } = config;
|
|
8388
|
-
if (
|
|
8389
|
-
var _userConfig_server, _config_server, _config_dev_client, _userConfig_dev, _config_server1;
|
|
8747
|
+
if (moduleFederation?.options && moduleFederation.options.exposes) {
|
|
8390
8748
|
let userConfig = api.getRsbuildConfig('original');
|
|
8391
|
-
config.dev ||= {}, config.server ||= {},
|
|
8749
|
+
config.dev ||= {}, config.server ||= {}, userConfig.server?.cors === void 0 && (config.server.cors = !0), config.server?.port && !config.dev.client?.port && (config.dev.client ||= {}, config.dev.client.port = config.server.port), userConfig.dev?.assetPrefix === void 0 && config.dev.assetPrefix === config.server?.base && (config.dev.assetPrefix = !0);
|
|
8392
8750
|
}
|
|
8393
8751
|
}), api.modifyEnvironmentConfig((config)=>{
|
|
8394
|
-
|
|
8395
|
-
(null == (_config_moduleFederation = config.moduleFederation) ? void 0 : _config_moduleFederation.options) && ((null == (_config_performance = config.performance) || null == (_config_performance_chunkSplit = _config_performance.chunkSplit) ? void 0 : _config_performance_chunkSplit.strategy) === 'split-by-experience' && (config.performance.chunkSplit = {
|
|
8752
|
+
config.moduleFederation?.options && (config.performance?.chunkSplit?.strategy === 'split-by-experience' && (config.performance.chunkSplit = {
|
|
8396
8753
|
...config.performance.chunkSplit,
|
|
8397
8754
|
strategy: 'custom'
|
|
8398
8755
|
}), config.source.include = [
|
|
@@ -8400,9 +8757,8 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8400
8757
|
/@module-federation[\\/]/
|
|
8401
8758
|
]);
|
|
8402
8759
|
}), api.modifyBundlerChain((chain, { CHAIN_ID, target, environment })=>{
|
|
8403
|
-
var _config_moduleFederation;
|
|
8404
8760
|
let { config } = environment;
|
|
8405
|
-
if (!
|
|
8761
|
+
if (!config.moduleFederation?.options || 'web' !== target) return;
|
|
8406
8762
|
let { options } = config.moduleFederation;
|
|
8407
8763
|
chain.plugin(CHAIN_ID.PLUGIN.MODULE_FEDERATION).use(rspack_rspack.container.ModuleFederationPlugin, [
|
|
8408
8764
|
options
|
|
@@ -8434,28 +8790,18 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8434
8790
|
apply: 'serve',
|
|
8435
8791
|
setup (api) {
|
|
8436
8792
|
api.modifyBundlerChain((chain, { environment, target })=>{
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
let { config } = environment, options = null == (_config_dev = config.dev) ? void 0 : _config_dev.lazyCompilation;
|
|
8793
|
+
if ('web' !== target || 'webpack' === api.context.bundlerType) return;
|
|
8794
|
+
let { config } = environment, options = config.dev?.lazyCompilation;
|
|
8440
8795
|
if (options) {
|
|
8441
|
-
if (!0 === options && Object.keys(chain.entryPoints.entries() || {}).length <= 1) return void chain.
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
entries: !1,
|
|
8445
|
-
imports: !0
|
|
8446
|
-
}
|
|
8447
|
-
});
|
|
8448
|
-
if ('object' == typeof options && 'string' == typeof options.serverUrl && api.context.devServer) return void chain.experiments({
|
|
8449
|
-
...chain.get('experiments'),
|
|
8450
|
-
lazyCompilation: {
|
|
8451
|
-
...options,
|
|
8452
|
-
serverUrl: replacePortPlaceholder(options.serverUrl, api.context.devServer.port)
|
|
8453
|
-
}
|
|
8796
|
+
if (!0 === options && Object.keys(chain.entryPoints.entries() || {}).length <= 1) return void chain.lazyCompilation({
|
|
8797
|
+
entries: !1,
|
|
8798
|
+
imports: !0
|
|
8454
8799
|
});
|
|
8455
|
-
chain.
|
|
8456
|
-
...
|
|
8457
|
-
|
|
8800
|
+
if ('object' == typeof options && 'string' == typeof options.serverUrl && api.context.devServer) return void chain.lazyCompilation({
|
|
8801
|
+
...options,
|
|
8802
|
+
serverUrl: replacePortPlaceholder(options.serverUrl, api.context.devServer.port)
|
|
8458
8803
|
});
|
|
8804
|
+
chain.lazyCompilation(options);
|
|
8459
8805
|
}
|
|
8460
8806
|
});
|
|
8461
8807
|
}
|
|
@@ -8478,7 +8824,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8478
8824
|
hashFuncNames: [
|
|
8479
8825
|
algorithm
|
|
8480
8826
|
],
|
|
8481
|
-
htmlPlugin:
|
|
8827
|
+
htmlPlugin: external_node_path_.default.join(COMPILED_PATH, 'html-rspack-plugin/index.js')
|
|
8482
8828
|
}
|
|
8483
8829
|
]);
|
|
8484
8830
|
});
|
|
@@ -8496,7 +8842,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8496
8842
|
let environmentList = Object.values(environments);
|
|
8497
8843
|
applyToCompiler(compiler, (compiler, index)=>{
|
|
8498
8844
|
let nonce = nonces[index], environment = environmentList.find((item)=>item.index === index);
|
|
8499
|
-
if (!Object.keys(
|
|
8845
|
+
if (!Object.keys(environment?.htmlPaths ?? {}).length || !nonce) return;
|
|
8500
8846
|
let injectCode = createVirtualModule(`__webpack_nonce__ = "${nonce}";`);
|
|
8501
8847
|
new compiler.webpack.EntryPlugin(compiler.context, injectCode, {
|
|
8502
8848
|
name: void 0
|
|
@@ -8509,10 +8855,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8509
8855
|
...headTags,
|
|
8510
8856
|
...bodyTags
|
|
8511
8857
|
];
|
|
8512
|
-
if (nonce) for (let tag of allTags){
|
|
8513
|
-
var _tag_attrs, _tag_attrs1;
|
|
8514
|
-
("script" === tag.tag || 'style' === tag.tag || 'link' === tag.tag && (null == (_tag_attrs = tag.attrs) ? void 0 : _tag_attrs.rel) === 'preload' && (null == (_tag_attrs1 = tag.attrs) ? void 0 : _tag_attrs1.as) === "script") && (tag.attrs ??= {}, tag.attrs.nonce = nonce);
|
|
8515
|
-
}
|
|
8858
|
+
if (nonce) for (let tag of allTags)("script" === tag.tag || 'style' === tag.tag || 'link' === tag.tag && tag.attrs?.rel === 'preload' && tag.attrs?.as === "script") && (tag.attrs ??= {}, tag.attrs.nonce = nonce);
|
|
8516
8859
|
return {
|
|
8517
8860
|
headTags,
|
|
8518
8861
|
bodyTags
|
|
@@ -8574,6 +8917,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
8574
8917
|
'onAfterStartDevServer',
|
|
8575
8918
|
'onAfterStartProdServer',
|
|
8576
8919
|
'onCloseDevServer',
|
|
8920
|
+
'onBeforeDevCompile',
|
|
8577
8921
|
'onDevCompileDone',
|
|
8578
8922
|
'onExit',
|
|
8579
8923
|
'getRsbuildConfig',
|
|
@@ -8609,7 +8953,7 @@ function defineConfig(config) {
|
|
|
8609
8953
|
async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
|
|
8610
8954
|
let configExport, configFilePath = ((root, customConfig)=>{
|
|
8611
8955
|
if (customConfig) {
|
|
8612
|
-
let customConfigPath =
|
|
8956
|
+
let customConfigPath = (0, external_node_path_.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_.join)(root, customConfig);
|
|
8613
8957
|
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
8614
8958
|
logger.warn(`Cannot find config file: ${picocolors.dim(customConfigPath)}\n`);
|
|
8615
8959
|
}
|
|
@@ -8621,7 +8965,7 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
8621
8965
|
'rsbuild.config.mts',
|
|
8622
8966
|
'rsbuild.config.cts'
|
|
8623
8967
|
]){
|
|
8624
|
-
let configFile = join(root, file);
|
|
8968
|
+
let configFile = (0, external_node_path_.join)(root, file);
|
|
8625
8969
|
if (node_fs.existsSync(configFile)) return configFile;
|
|
8626
8970
|
}
|
|
8627
8971
|
return null;
|
|
@@ -8634,7 +8978,7 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
8634
8978
|
configFilePath
|
|
8635
8979
|
}, config);
|
|
8636
8980
|
if ('native' === loader || /\.(?:js|mjs|cjs)$/.test(configFilePath)) try {
|
|
8637
|
-
let configFileURL = pathToFileURL(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
|
|
8981
|
+
let configFileURL = (0, external_node_url_.pathToFileURL)(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
|
|
8638
8982
|
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
8639
8983
|
} catch (err) {
|
|
8640
8984
|
if ('native' === loader) throw logger.error(`Failed to load file with native loader: ${picocolors.dim(configFilePath)}`), err;
|
|
@@ -8677,14 +9021,13 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
8677
9021
|
};
|
|
8678
9022
|
}
|
|
8679
9023
|
let commonOpts = {}, init_loadConfig = async (root)=>{
|
|
8680
|
-
var _config_server;
|
|
8681
9024
|
let { content: config, filePath } = await loadConfig_loadConfig({
|
|
8682
9025
|
cwd: root,
|
|
8683
9026
|
path: commonOpts.config,
|
|
8684
9027
|
envMode: commonOpts.envMode,
|
|
8685
9028
|
loader: commonOpts.configLoader
|
|
8686
9029
|
});
|
|
8687
|
-
return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.logLevel && (config.logLevel = commonOpts.logLevel),
|
|
9030
|
+
return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), commonOpts.logLevel && (config.logLevel = commonOpts.logLevel), commonOpts.open && !config.server?.open && (config.server.open = commonOpts.open), commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
|
|
8688
9031
|
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
8689
9032
|
{
|
|
8690
9033
|
paths: filePath,
|
|
@@ -8693,15 +9036,15 @@ let commonOpts = {}, init_loadConfig = async (root)=>{
|
|
|
8693
9036
|
]), config;
|
|
8694
9037
|
};
|
|
8695
9038
|
async function init_init({ cliOptions, isRestart, isBuildWatch = !1 }) {
|
|
8696
|
-
|
|
8697
|
-
cliOptions && (commonOpts = cliOptions), commonOpts.environment = null == (_commonOpts_environment = commonOpts.environment) ? void 0 : _commonOpts_environment.flatMap((env)=>env.split(','));
|
|
9039
|
+
cliOptions && (commonOpts = cliOptions), commonOpts.environment = commonOpts.environment?.flatMap((env)=>env.split(','));
|
|
8698
9040
|
try {
|
|
9041
|
+
var envDir;
|
|
8699
9042
|
let cwd = process.cwd(), root = commonOpts.root ? ensureAbsolutePath(cwd, commonOpts.root) : cwd, rsbuild = await createRsbuild({
|
|
8700
9043
|
cwd: root,
|
|
8701
9044
|
rsbuildConfig: ()=>init_loadConfig(root),
|
|
8702
9045
|
environment: commonOpts.environment,
|
|
8703
9046
|
loadEnv: !1 !== commonOpts.env && {
|
|
8704
|
-
cwd: (envDir = commonOpts.envDir) ?
|
|
9047
|
+
cwd: (envDir = commonOpts.envDir) ? external_node_path_.default.isAbsolute(envDir) ? envDir : external_node_path_.default.join(root, envDir) : root,
|
|
8705
9048
|
mode: commonOpts.envMode
|
|
8706
9049
|
}
|
|
8707
9050
|
});
|
|
@@ -8733,7 +9076,7 @@ let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
|
8733
9076
|
cleaners.push(cleaner);
|
|
8734
9077
|
}, beforeRestart = async ({ filePath, clear = !0, id })=>{
|
|
8735
9078
|
if (clear && isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J'), filePath) {
|
|
8736
|
-
let filename =
|
|
9079
|
+
let filename = external_node_path_.default.basename(filePath);
|
|
8737
9080
|
logger.info(`restarting ${id} as ${picocolors.yellow(filename)} changed\n`);
|
|
8738
9081
|
} else logger.info(`restarting ${id}...\n`);
|
|
8739
9082
|
for (let cleaner of cleaners)await cleaner();
|
|
@@ -8778,17 +9121,16 @@ async function watchFilesForRestart({ files, rsbuild, isBuildWatch, watchOptions
|
|
|
8778
9121
|
watcher.on('add', onChange), watcher.on('change', onChange), watcher.on('unlink', onChange);
|
|
8779
9122
|
}
|
|
8780
9123
|
let applyServerOptions = (command)=>{
|
|
8781
|
-
command.option('-o, --open [url]', '
|
|
8782
|
-
};
|
|
9124
|
+
command.option('-o, --open [url]', 'Open the page in browser on startup').option('--port <port>', 'Set the port number for the server').option('--host <host>', 'Set the host that the server listens to');
|
|
9125
|
+
}, { argv: cli_argv } = process;
|
|
8783
9126
|
function runCLI() {
|
|
8784
|
-
if (!process.env.NODE_ENV) {
|
|
8785
|
-
let command =
|
|
9127
|
+
if (process.title = 'rsbuild-node', !process.env.NODE_ENV) {
|
|
9128
|
+
let command = cli_argv[2];
|
|
8786
9129
|
process.env.NODE_ENV = [
|
|
8787
9130
|
'build',
|
|
8788
9131
|
'preview'
|
|
8789
9132
|
].includes(command) ? 'production' : 'development';
|
|
8790
9133
|
}
|
|
8791
|
-
process.title = 'rsbuild-node';
|
|
8792
9134
|
let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
8793
9135
|
if (-1 !== logLevelIndex) {
|
|
8794
9136
|
let level = process.argv[logLevelIndex + 1];
|
|
@@ -8798,37 +9140,40 @@ function runCLI() {
|
|
|
8798
9140
|
'silent'
|
|
8799
9141
|
].includes(level) && (logger.level = level);
|
|
8800
9142
|
}
|
|
8801
|
-
|
|
8802
|
-
|
|
9143
|
+
!function() {
|
|
9144
|
+
if (cli_argv.some((item)=>'--help' === item || '-h' === item)) return;
|
|
9145
|
+
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
9146
|
+
logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''} Rsbuild v1.5.0-beta.1\n`);
|
|
9147
|
+
}();
|
|
8803
9148
|
try {
|
|
8804
9149
|
!function() {
|
|
8805
9150
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
8806
|
-
cli.help(), cli.version("1.
|
|
9151
|
+
cli.help(), cli.version("1.5.0-beta.1"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (jiti | native)', {
|
|
8807
9152
|
default: 'jiti'
|
|
8808
|
-
}).option('-
|
|
9153
|
+
}).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
8809
9154
|
type: [
|
|
8810
9155
|
String
|
|
8811
9156
|
],
|
|
8812
9157
|
default: []
|
|
8813
|
-
}).option('--
|
|
8814
|
-
let devCommand = cli.command('', '
|
|
9158
|
+
}).option('--log-level <level>', 'Set the log level (info | warn | error | silent)').option('-m, --mode <mode>', 'Set the build mode (development | production | none)').option('-r, --root <root>', 'Set the project root directory (absolute path or relative to cwd)').option('--no-env', 'Disable loading of `.env` files');
|
|
9159
|
+
let devCommand = cli.command('dev', 'Start the dev server').alias(''), buildCommand = cli.command('build', 'Build the app for production'), previewCommand = cli.command('preview', 'Preview the production build locally'), inspectCommand = cli.command('inspect', 'Inspect the Rspack and Rsbuild configs');
|
|
8815
9160
|
applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
|
|
8816
9161
|
try {
|
|
8817
9162
|
let rsbuild = await init_init({
|
|
8818
9163
|
cliOptions: options
|
|
8819
9164
|
});
|
|
8820
|
-
await
|
|
9165
|
+
await rsbuild?.startDevServer();
|
|
8821
9166
|
} catch (err) {
|
|
8822
9167
|
logger.error('Failed to start dev server.'), logger.error(err), process.exit(1);
|
|
8823
9168
|
}
|
|
8824
|
-
}), buildCommand.option('-w, --watch', '
|
|
9169
|
+
}), buildCommand.option('-w, --watch', 'Enable watch mode to automatically rebuild on file changes').action(async (options)=>{
|
|
8825
9170
|
try {
|
|
8826
9171
|
let rsbuild = await init_init({
|
|
8827
9172
|
cliOptions: options,
|
|
8828
9173
|
isBuildWatch: options.watch
|
|
8829
|
-
}), buildInstance = await
|
|
9174
|
+
}), buildInstance = await rsbuild?.build({
|
|
8830
9175
|
watch: options.watch
|
|
8831
|
-
})
|
|
9176
|
+
});
|
|
8832
9177
|
buildInstance && (options.watch ? onBeforeRestartServer(buildInstance.close) : await buildInstance.close());
|
|
8833
9178
|
} catch (err) {
|
|
8834
9179
|
err instanceof Error && err.message === RSPACK_BUILD_ERROR || logger.error('Failed to build.'), logger.error(err), process.exit(1);
|
|
@@ -8838,20 +9183,20 @@ function runCLI() {
|
|
|
8838
9183
|
let rsbuild = await init_init({
|
|
8839
9184
|
cliOptions: options
|
|
8840
9185
|
});
|
|
8841
|
-
await
|
|
9186
|
+
await rsbuild?.preview();
|
|
8842
9187
|
} catch (err) {
|
|
8843
9188
|
logger.error('Failed to start preview server.'), logger.error(err), process.exit(1);
|
|
8844
9189
|
}
|
|
8845
|
-
}), inspectCommand.option('--output <output>', '
|
|
9190
|
+
}), inspectCommand.option('--output <output>', 'Set the output path for inspection results').option('--verbose', 'Show complete function definitions in output').action(async (options)=>{
|
|
8846
9191
|
try {
|
|
8847
9192
|
let rsbuild = await init_init({
|
|
8848
9193
|
cliOptions: options
|
|
8849
9194
|
});
|
|
8850
|
-
await
|
|
9195
|
+
await rsbuild?.inspectConfig({
|
|
8851
9196
|
verbose: options.verbose,
|
|
8852
9197
|
outputPath: options.output,
|
|
8853
9198
|
writeToDisk: !0
|
|
8854
|
-
})
|
|
9199
|
+
});
|
|
8855
9200
|
} catch (err) {
|
|
8856
9201
|
logger.error('Failed to inspect config.'), logger.error(err), process.exit(1);
|
|
8857
9202
|
}
|
|
@@ -8861,5 +9206,5 @@ function runCLI() {
|
|
|
8861
9206
|
logger.error('Failed to start Rsbuild CLI.'), logger.error(err);
|
|
8862
9207
|
}
|
|
8863
9208
|
}
|
|
8864
|
-
let src_version = "1.
|
|
9209
|
+
let src_version = "1.5.0-beta.1";
|
|
8865
9210
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger, mergeRsbuildConfig, rspack_rspack as rspack, runCLI, src_version as version };
|