@rsbuild/core 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/css-loader/index.js +65 -45
- package/compiled/css-loader/package.json +1 -1
- package/compiled/postcss-load-config/index.js +102 -33
- package/compiled/postcss-load-config/package.json +1 -1
- package/compiled/postcss-loader/index.js +67 -60
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/client/hmr.js +2 -2
- package/dist/index.cjs +420 -220
- package/dist/index.js +428 -222
- package/dist-types/helpers.d.ts +1 -0
- package/dist-types/index.d.ts +1 -1
- package/dist-types/plugins/nonce.d.ts +2 -0
- package/dist-types/plugins/sri.d.ts +2 -0
- package/dist-types/server/devServer.d.ts +1 -1
- package/dist-types/server/httpServer.d.ts +1 -1
- package/dist-types/server/middlewares.d.ts +1 -1
- package/dist-types/server/prodServer.d.ts +1 -1
- package/dist-types/server/socketServer.d.ts +1 -1
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -23,12 +23,12 @@ var __publicField = (obj, key, value) => {
|
|
|
23
23
|
return value;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
26
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.51.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
|
|
27
27
|
import { fileURLToPath } from "url";
|
|
28
28
|
import path from "path";
|
|
29
29
|
var getFilename, getDirname, __dirname, __filename;
|
|
30
30
|
var init_esm = __esm({
|
|
31
|
-
"../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
31
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.51.0_eslint@9.4.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
32
32
|
"use strict";
|
|
33
33
|
getFilename = () => fileURLToPath(import.meta.url);
|
|
34
34
|
getDirname = () => path.dirname(getFilename());
|
|
@@ -37,24 +37,6 @@ var init_esm = __esm({
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
// src/constants.ts
|
|
41
|
-
import { join } from "path";
|
|
42
|
-
var PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HTML_REGEX, CSS_REGEX;
|
|
43
|
-
var init_constants = __esm({
|
|
44
|
-
"src/constants.ts"() {
|
|
45
|
-
"use strict";
|
|
46
|
-
init_esm();
|
|
47
|
-
PLUGIN_SWC_NAME = "rsbuild:swc";
|
|
48
|
-
PLUGIN_CSS_NAME = "rsbuild:css";
|
|
49
|
-
LOADER_PATH = join(__dirname);
|
|
50
|
-
STATIC_PATH = join(__dirname, "../static");
|
|
51
|
-
COMPILED_PATH = join(__dirname, "../compiled");
|
|
52
|
-
TS_CONFIG_FILE = "tsconfig.json";
|
|
53
|
-
HTML_REGEX = /\.html$/;
|
|
54
|
-
CSS_REGEX = /\.css$/;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
40
|
// src/client/format.ts
|
|
59
41
|
function resolveFileName(stats) {
|
|
60
42
|
if (stats.moduleIdentifier) {
|
|
@@ -68,8 +50,8 @@ function resolveFileName(stats) {
|
|
|
68
50
|
}
|
|
69
51
|
}
|
|
70
52
|
}
|
|
71
|
-
return `File: ${stats.moduleName}
|
|
72
|
-
|
|
53
|
+
return stats.moduleName ? `File: ${stats.moduleName}
|
|
54
|
+
` : "";
|
|
73
55
|
}
|
|
74
56
|
function hintUnknownFiles(message) {
|
|
75
57
|
const hint = "You may need an appropriate loader to handle this file type.";
|
|
@@ -134,6 +116,24 @@ var init_format = __esm({
|
|
|
134
116
|
}
|
|
135
117
|
});
|
|
136
118
|
|
|
119
|
+
// src/constants.ts
|
|
120
|
+
import { join } from "path";
|
|
121
|
+
var PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, LOADER_PATH, STATIC_PATH, COMPILED_PATH, TS_CONFIG_FILE, HTML_REGEX, CSS_REGEX;
|
|
122
|
+
var init_constants = __esm({
|
|
123
|
+
"src/constants.ts"() {
|
|
124
|
+
"use strict";
|
|
125
|
+
init_esm();
|
|
126
|
+
PLUGIN_SWC_NAME = "rsbuild:swc";
|
|
127
|
+
PLUGIN_CSS_NAME = "rsbuild:css";
|
|
128
|
+
LOADER_PATH = join(__dirname);
|
|
129
|
+
STATIC_PATH = join(__dirname, "../static");
|
|
130
|
+
COMPILED_PATH = join(__dirname, "../compiled");
|
|
131
|
+
TS_CONFIG_FILE = "tsconfig.json";
|
|
132
|
+
HTML_REGEX = /\.html$/;
|
|
133
|
+
CSS_REGEX = /\.css$/;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
137
|
// src/helpers.ts
|
|
138
138
|
import path2 from "path";
|
|
139
139
|
import {
|
|
@@ -201,6 +201,10 @@ function formatStats(stats, options = {}) {
|
|
|
201
201
|
}
|
|
202
202
|
return {};
|
|
203
203
|
}
|
|
204
|
+
function isEmptyDir(path14) {
|
|
205
|
+
const files = fse.readdirSync(path14);
|
|
206
|
+
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
207
|
+
}
|
|
204
208
|
async function isFileExists(file) {
|
|
205
209
|
return fse.promises.access(file, fse.constants.F_OK).then(() => true).catch(() => false);
|
|
206
210
|
}
|
|
@@ -632,7 +636,10 @@ var init_config = __esm({
|
|
|
632
636
|
scriptLoading: "defer"
|
|
633
637
|
});
|
|
634
638
|
getDefaultSecurityConfig = () => ({
|
|
635
|
-
nonce: ""
|
|
639
|
+
nonce: "",
|
|
640
|
+
sri: {
|
|
641
|
+
enable: false
|
|
642
|
+
}
|
|
636
643
|
});
|
|
637
644
|
getDefaultToolsConfig = () => ({
|
|
638
645
|
cssExtract: {
|
|
@@ -690,6 +697,7 @@ var init_config = __esm({
|
|
|
690
697
|
inlineStyles: false,
|
|
691
698
|
cssModules: {
|
|
692
699
|
auto: true,
|
|
700
|
+
namedExport: false,
|
|
693
701
|
exportGlobals: false,
|
|
694
702
|
exportLocalsConvention: "camelCase"
|
|
695
703
|
},
|
|
@@ -707,7 +715,7 @@ var init_config = __esm({
|
|
|
707
715
|
});
|
|
708
716
|
withDefaultConfig = async (rootPath, config) => {
|
|
709
717
|
const merged = mergeRsbuildConfig(createDefaultConfig(), config);
|
|
710
|
-
merged.source
|
|
718
|
+
merged.source ||= {};
|
|
711
719
|
if (!merged.source.entry) {
|
|
712
720
|
merged.source.entry = getDefaultEntry(rootPath);
|
|
713
721
|
}
|
|
@@ -752,8 +760,8 @@ var init_config = __esm({
|
|
|
752
760
|
import fs2 from "fs";
|
|
753
761
|
import { join as join3 } from "path";
|
|
754
762
|
import { getNodeEnv as getNodeEnv2 } from "@rsbuild/shared";
|
|
755
|
-
import { expand } from "../compiled/dotenv-expand/index.js";
|
|
756
763
|
import { parse } from "../compiled/dotenv/index.js";
|
|
764
|
+
import { expand } from "../compiled/dotenv-expand/index.js";
|
|
757
765
|
function loadEnv({
|
|
758
766
|
cwd = process.cwd(),
|
|
759
767
|
mode = getNodeEnv2(),
|
|
@@ -884,17 +892,16 @@ import {
|
|
|
884
892
|
castArray as castArray2,
|
|
885
893
|
color as color4,
|
|
886
894
|
createVirtualModule,
|
|
887
|
-
|
|
895
|
+
reduceConfigsMergeContext
|
|
888
896
|
} from "@rsbuild/shared";
|
|
889
897
|
function getEntryObject(config, target) {
|
|
890
898
|
if (!config.source?.entry) {
|
|
891
899
|
return {};
|
|
892
900
|
}
|
|
893
|
-
return
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
useObjectParam: true
|
|
901
|
+
return reduceConfigsMergeContext({
|
|
902
|
+
initial: {},
|
|
903
|
+
config: config.source?.entry,
|
|
904
|
+
ctx: { target }
|
|
898
905
|
});
|
|
899
906
|
}
|
|
900
907
|
var pluginEntry;
|
|
@@ -962,7 +969,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
|
|
|
962
969
|
return {
|
|
963
970
|
entry: getEntryObject(config, "web"),
|
|
964
971
|
targets: config.output?.targets || [],
|
|
965
|
-
version: "0.7.
|
|
972
|
+
version: "0.7.3",
|
|
966
973
|
rootPath,
|
|
967
974
|
distPath,
|
|
968
975
|
cachePath,
|
|
@@ -1438,8 +1445,8 @@ import {
|
|
|
1438
1445
|
chainToConfig,
|
|
1439
1446
|
debug as debug2,
|
|
1440
1447
|
getNodeEnv as getNodeEnv4,
|
|
1441
|
-
|
|
1442
|
-
|
|
1448
|
+
modifyBundlerChain,
|
|
1449
|
+
reduceConfigsAsyncWithContext
|
|
1443
1450
|
} from "@rsbuild/shared";
|
|
1444
1451
|
import { rspack as rspack2 } from "@rspack/core";
|
|
1445
1452
|
async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
@@ -1449,10 +1456,10 @@ async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
|
1449
1456
|
utils
|
|
1450
1457
|
);
|
|
1451
1458
|
if (context.config.tools?.rspack) {
|
|
1452
|
-
modifiedConfig =
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
utils,
|
|
1459
|
+
modifiedConfig = await reduceConfigsAsyncWithContext({
|
|
1460
|
+
initial: modifiedConfig,
|
|
1461
|
+
config: context.config.tools.rspack,
|
|
1462
|
+
ctx: utils,
|
|
1456
1463
|
mergeFn: utils.mergeConfig
|
|
1457
1464
|
});
|
|
1458
1465
|
}
|
|
@@ -1984,7 +1991,7 @@ function formatProxyOptions(proxyOptions) {
|
|
|
1984
1991
|
}
|
|
1985
1992
|
const handleError = (err) => logger7.error(err);
|
|
1986
1993
|
for (const opts of ret) {
|
|
1987
|
-
opts.onError
|
|
1994
|
+
opts.onError ??= handleError;
|
|
1988
1995
|
}
|
|
1989
1996
|
return ret;
|
|
1990
1997
|
}
|
|
@@ -3206,7 +3213,10 @@ var init_build = __esm({
|
|
|
3206
3213
|
const buildError = err || new Error("Rspack build failed!");
|
|
3207
3214
|
reject(buildError);
|
|
3208
3215
|
} else {
|
|
3209
|
-
compiler.close(() => {
|
|
3216
|
+
compiler.close((closeErr) => {
|
|
3217
|
+
if (closeErr) {
|
|
3218
|
+
logger10.error(closeErr);
|
|
3219
|
+
}
|
|
3210
3220
|
resolve({ stats });
|
|
3211
3221
|
});
|
|
3212
3222
|
}
|
|
@@ -3317,13 +3327,12 @@ var init_basic = __esm({
|
|
|
3317
3327
|
name: "rsbuild:basic",
|
|
3318
3328
|
setup(api) {
|
|
3319
3329
|
api.modifyBundlerChain(
|
|
3320
|
-
(chain, { env, isProd:
|
|
3321
|
-
var _a;
|
|
3330
|
+
(chain, { env, isProd: isProd5, target, bundler, CHAIN_ID: CHAIN_ID3 }) => {
|
|
3322
3331
|
const config = api.getNormalizedConfig();
|
|
3323
3332
|
chain.name(TARGET_ID_MAP2[target]);
|
|
3324
3333
|
chain.devtool(getJsSourceMap(config));
|
|
3325
3334
|
chain.context(api.context.rootPath);
|
|
3326
|
-
chain.mode(
|
|
3335
|
+
chain.mode(isProd5 ? "production" : "development");
|
|
3327
3336
|
chain.merge({
|
|
3328
3337
|
infrastructureLogging: {
|
|
3329
3338
|
// Using `error` level to avoid `cache.PackFileCacheStrategy` logs
|
|
@@ -3336,9 +3345,9 @@ var init_basic = __esm({
|
|
|
3336
3345
|
exportsPresence: "error"
|
|
3337
3346
|
}
|
|
3338
3347
|
});
|
|
3339
|
-
const isMinimize =
|
|
3348
|
+
const isMinimize = isProd5 && config.output.minify !== false;
|
|
3340
3349
|
chain.optimization.minimize(isMinimize);
|
|
3341
|
-
const usingHMR = isUsingHMR(config, { target, isProd:
|
|
3350
|
+
const usingHMR = isUsingHMR(config, { target, isProd: isProd5 });
|
|
3342
3351
|
if (usingHMR) {
|
|
3343
3352
|
chain.plugin(CHAIN_ID3.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
|
|
3344
3353
|
}
|
|
@@ -3348,7 +3357,7 @@ var init_basic = __esm({
|
|
|
3348
3357
|
);
|
|
3349
3358
|
}
|
|
3350
3359
|
process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
|
|
3351
|
-
|
|
3360
|
+
process.env.WATCHPACK_WATCHER_LIMIT ||= "20";
|
|
3352
3361
|
}
|
|
3353
3362
|
);
|
|
3354
3363
|
}
|
|
@@ -3509,7 +3518,8 @@ import {
|
|
|
3509
3518
|
getBrowserslistWithDefault as getBrowserslistWithDefault2,
|
|
3510
3519
|
isFunction as isFunction5,
|
|
3511
3520
|
isPlainObject as isPlainObject2,
|
|
3512
|
-
|
|
3521
|
+
reduceConfigs,
|
|
3522
|
+
reduceConfigsWithContext
|
|
3513
3523
|
} from "@rsbuild/shared";
|
|
3514
3524
|
async function loadUserPostcssrc(root) {
|
|
3515
3525
|
const cached = userPostcssrcCache.get(root);
|
|
@@ -3533,7 +3543,7 @@ async function applyCSSRule({
|
|
|
3533
3543
|
rule,
|
|
3534
3544
|
config,
|
|
3535
3545
|
context,
|
|
3536
|
-
utils: { target, isProd:
|
|
3546
|
+
utils: { target, isProd: isProd5, CHAIN_ID: CHAIN_ID3 },
|
|
3537
3547
|
importLoaders = 1
|
|
3538
3548
|
}) {
|
|
3539
3549
|
const browserslist = await getBrowserslistWithDefault2(
|
|
@@ -3542,7 +3552,7 @@ async function applyCSSRule({
|
|
|
3542
3552
|
target
|
|
3543
3553
|
);
|
|
3544
3554
|
const enableExtractCSS = isUseCssExtract(config, target);
|
|
3545
|
-
const localIdentName = getCSSModulesLocalIdentName(config,
|
|
3555
|
+
const localIdentName = getCSSModulesLocalIdentName(config, isProd5);
|
|
3546
3556
|
const cssLoaderOptions = getCSSLoaderOptions({
|
|
3547
3557
|
config,
|
|
3548
3558
|
importLoaders,
|
|
@@ -3553,9 +3563,9 @@ async function applyCSSRule({
|
|
|
3553
3563
|
if (enableExtractCSS) {
|
|
3554
3564
|
rule.use(CHAIN_ID3.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions).end();
|
|
3555
3565
|
} else {
|
|
3556
|
-
const styleLoaderOptions =
|
|
3557
|
-
|
|
3558
|
-
|
|
3566
|
+
const styleLoaderOptions = reduceConfigs({
|
|
3567
|
+
initial: {},
|
|
3568
|
+
config: config.tools.styleLoader
|
|
3559
3569
|
});
|
|
3560
3570
|
rule.use(CHAIN_ID3.USE.STYLE).loader(getCompiledPath("style-loader")).options(styleLoaderOptions).end();
|
|
3561
3571
|
}
|
|
@@ -3584,8 +3594,8 @@ var init_css = __esm({
|
|
|
3584
3594
|
init_pluginHelper();
|
|
3585
3595
|
enableNativeCss = (config) => !config.output.injectStyles;
|
|
3586
3596
|
isUseCssExtract = (config, target) => !config.output.injectStyles && target !== "node" && target !== "web-worker";
|
|
3587
|
-
getCSSModulesLocalIdentName = (config,
|
|
3588
|
-
(
|
|
3597
|
+
getCSSModulesLocalIdentName = (config, isProd5) => config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
|
|
3598
|
+
(isProd5 ? "[local]-[hash:base64:6]" : "[path][name]__[local]-[hash:base64:6]");
|
|
3589
3599
|
normalizeCssLoaderOptions = (options, exportOnlyLocals) => {
|
|
3590
3600
|
if (options.modules && exportOnlyLocals) {
|
|
3591
3601
|
let { modules } = options;
|
|
@@ -3622,12 +3632,12 @@ var init_css = __esm({
|
|
|
3622
3632
|
});
|
|
3623
3633
|
if (!hasAutoprefixer) {
|
|
3624
3634
|
const { default: autoprefixer } = await import("@rsbuild/shared/autoprefixer");
|
|
3625
|
-
const autoprefixerOptions =
|
|
3626
|
-
|
|
3635
|
+
const autoprefixerOptions = reduceConfigs({
|
|
3636
|
+
initial: {
|
|
3627
3637
|
flexbox: "no-2009",
|
|
3628
3638
|
overrideBrowserslist: browserslist
|
|
3629
3639
|
},
|
|
3630
|
-
|
|
3640
|
+
config: config.tools.autoprefixer
|
|
3631
3641
|
});
|
|
3632
3642
|
pluginObjects.push(autoprefixer(autoprefixerOptions));
|
|
3633
3643
|
}
|
|
@@ -3662,15 +3672,15 @@ var init_css = __esm({
|
|
|
3662
3672
|
},
|
|
3663
3673
|
sourceMap: config.output.sourceMap.css
|
|
3664
3674
|
};
|
|
3665
|
-
const mergedConfig =
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
utils
|
|
3675
|
+
const mergedConfig = reduceConfigsWithContext({
|
|
3676
|
+
initial: defaultPostcssConfig,
|
|
3677
|
+
config: config.tools.postcss,
|
|
3678
|
+
ctx: utils
|
|
3669
3679
|
});
|
|
3670
3680
|
if (extraPlugins.length) {
|
|
3671
3681
|
mergedConfig?.postcssOptions?.plugins.push(...extraPlugins);
|
|
3672
3682
|
}
|
|
3673
|
-
mergedConfig.postcssOptions
|
|
3683
|
+
mergedConfig.postcssOptions ||= {};
|
|
3674
3684
|
mergedConfig.postcssOptions.config = false;
|
|
3675
3685
|
return mergedConfig;
|
|
3676
3686
|
};
|
|
@@ -3684,17 +3694,14 @@ var init_css = __esm({
|
|
|
3684
3694
|
const defaultOptions2 = {
|
|
3685
3695
|
importLoaders,
|
|
3686
3696
|
modules: {
|
|
3687
|
-
|
|
3688
|
-
namedExport: false,
|
|
3689
|
-
exportGlobals: cssModules.exportGlobals,
|
|
3690
|
-
exportLocalsConvention: cssModules.exportLocalsConvention,
|
|
3697
|
+
...cssModules,
|
|
3691
3698
|
localIdentName
|
|
3692
3699
|
},
|
|
3693
3700
|
sourceMap: config.output.sourceMap.css
|
|
3694
3701
|
};
|
|
3695
|
-
const mergedCssLoaderOptions =
|
|
3696
|
-
|
|
3697
|
-
|
|
3702
|
+
const mergedCssLoaderOptions = reduceConfigs({
|
|
3703
|
+
initial: defaultOptions2,
|
|
3704
|
+
config: config.tools.cssLoader,
|
|
3698
3705
|
mergeFn: deepmerge2
|
|
3699
3706
|
});
|
|
3700
3707
|
const cssLoaderOptions = normalizeCssLoaderOptions(
|
|
@@ -3721,7 +3728,7 @@ var init_css = __esm({
|
|
|
3721
3728
|
}
|
|
3722
3729
|
});
|
|
3723
3730
|
api.modifyRspackConfig(async (rspackConfig) => {
|
|
3724
|
-
rspackConfig.experiments
|
|
3731
|
+
rspackConfig.experiments ||= {};
|
|
3725
3732
|
rspackConfig.experiments.css = false;
|
|
3726
3733
|
});
|
|
3727
3734
|
}
|
|
@@ -3744,13 +3751,13 @@ import {
|
|
|
3744
3751
|
} from "@rsbuild/shared";
|
|
3745
3752
|
import { rspack as rspack5 } from "@rspack/core";
|
|
3746
3753
|
function getPublicPath({
|
|
3747
|
-
isProd:
|
|
3754
|
+
isProd: isProd5,
|
|
3748
3755
|
config,
|
|
3749
3756
|
context
|
|
3750
3757
|
}) {
|
|
3751
3758
|
const { dev, output } = config;
|
|
3752
3759
|
let publicPath = DEFAULT_ASSET_PREFIX3;
|
|
3753
|
-
if (
|
|
3760
|
+
if (isProd5) {
|
|
3754
3761
|
if (typeof output.assetPrefix === "string") {
|
|
3755
3762
|
publicPath = output.assetPrefix;
|
|
3756
3763
|
}
|
|
@@ -3781,20 +3788,23 @@ var init_output = __esm({
|
|
|
3781
3788
|
name: "rsbuild:output",
|
|
3782
3789
|
setup(api) {
|
|
3783
3790
|
api.modifyBundlerChain(
|
|
3784
|
-
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd:
|
|
3791
|
+
async (chain, { CHAIN_ID: CHAIN_ID3, target, isProd: isProd5, isServer, isServiceWorker }) => {
|
|
3785
3792
|
const config = api.getNormalizedConfig();
|
|
3786
3793
|
const publicPath = getPublicPath({
|
|
3787
3794
|
config,
|
|
3788
|
-
isProd:
|
|
3795
|
+
isProd: isProd5,
|
|
3789
3796
|
context: api.context
|
|
3790
3797
|
});
|
|
3791
3798
|
const jsPath = getDistPath3(config, "js");
|
|
3792
3799
|
const jsAsyncPath = getDistPath3(config, "jsAsync");
|
|
3793
|
-
const jsFilename = getFilename2(config, "js",
|
|
3800
|
+
const jsFilename = getFilename2(config, "js", isProd5);
|
|
3794
3801
|
chain.output.path(api.context.distPath).filename(posix.join(jsPath, jsFilename)).chunkFilename(posix.join(jsAsyncPath, jsFilename)).publicPath(publicPath).pathinfo(false).hashFunction("xxhash64");
|
|
3795
3802
|
if (isServer) {
|
|
3796
3803
|
const serverPath = getDistPath3(config, "server");
|
|
3797
|
-
chain.output.path(posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").
|
|
3804
|
+
chain.output.path(posix.join(api.context.distPath, serverPath)).filename("[name].js").chunkFilename("[name].js").library({
|
|
3805
|
+
...chain.output.get("library") || {},
|
|
3806
|
+
type: "commonjs2"
|
|
3807
|
+
});
|
|
3798
3808
|
}
|
|
3799
3809
|
if (isServiceWorker) {
|
|
3800
3810
|
const workerPath = getDistPath3(config, "worker");
|
|
@@ -3809,7 +3819,7 @@ var init_output = __esm({
|
|
|
3809
3819
|
if (isUseCssExtract(config, target)) {
|
|
3810
3820
|
const extractPluginOptions = config.tools.cssExtract.pluginOptions;
|
|
3811
3821
|
const cssPath = getDistPath3(config, "css");
|
|
3812
|
-
const cssFilename = getFilename2(config, "css",
|
|
3822
|
+
const cssFilename = getFilename2(config, "css", isProd5);
|
|
3813
3823
|
const cssAsyncPath = getDistPath3(config, "cssAsync");
|
|
3814
3824
|
chain.plugin(CHAIN_ID3.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
|
|
3815
3825
|
{
|
|
@@ -3833,7 +3843,7 @@ __export(resolve_exports, {
|
|
|
3833
3843
|
});
|
|
3834
3844
|
import {
|
|
3835
3845
|
castArray as castArray4,
|
|
3836
|
-
|
|
3846
|
+
reduceConfigsWithContext as reduceConfigsWithContext2
|
|
3837
3847
|
} from "@rsbuild/shared";
|
|
3838
3848
|
function applyFullySpecified({
|
|
3839
3849
|
chain,
|
|
@@ -3863,10 +3873,10 @@ function applyAlias({
|
|
|
3863
3873
|
if (!alias) {
|
|
3864
3874
|
return;
|
|
3865
3875
|
}
|
|
3866
|
-
const mergedAlias =
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3876
|
+
const mergedAlias = reduceConfigsWithContext2({
|
|
3877
|
+
initial: {},
|
|
3878
|
+
config: alias,
|
|
3879
|
+
ctx: { target }
|
|
3870
3880
|
});
|
|
3871
3881
|
for (const name of Object.keys(mergedAlias)) {
|
|
3872
3882
|
const values = castArray4(mergedAlias[name]);
|
|
@@ -3908,7 +3918,7 @@ var init_resolve = __esm({
|
|
|
3908
3918
|
api.modifyRspackConfig(async (rspackConfig) => {
|
|
3909
3919
|
const isTsProject = Boolean(api.context.tsconfigPath);
|
|
3910
3920
|
const config = api.getNormalizedConfig();
|
|
3911
|
-
rspackConfig.resolve
|
|
3921
|
+
rspackConfig.resolve ||= {};
|
|
3912
3922
|
if (isTsProject && config.source.aliasStrategy === "prefer-tsconfig") {
|
|
3913
3923
|
rspackConfig.resolve.tsConfigPath = api.context.tsconfigPath;
|
|
3914
3924
|
}
|
|
@@ -4198,12 +4208,12 @@ var init_asset = __esm({
|
|
|
4198
4208
|
pluginAsset = () => ({
|
|
4199
4209
|
name: "rsbuild:asset",
|
|
4200
4210
|
setup(api) {
|
|
4201
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
4211
|
+
api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
|
|
4202
4212
|
const config = api.getNormalizedConfig();
|
|
4203
4213
|
const createAssetRule = (assetType, exts, emit2) => {
|
|
4204
4214
|
const regExp = getRegExpForExts(exts);
|
|
4205
4215
|
const distDir = getDistPath4(config, assetType);
|
|
4206
|
-
const filename = getFilename3(config, assetType,
|
|
4216
|
+
const filename = getFilename3(config, assetType, isProd5);
|
|
4207
4217
|
const { dataUriLimit } = config.output;
|
|
4208
4218
|
const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
|
|
4209
4219
|
const rule = chain.module.rule(assetType).test(regExp);
|
|
@@ -4263,7 +4273,7 @@ var init_minimize = __esm({
|
|
|
4263
4273
|
pure_funcs: pureFuncs
|
|
4264
4274
|
};
|
|
4265
4275
|
}
|
|
4266
|
-
options.format
|
|
4276
|
+
options.format ||= {};
|
|
4267
4277
|
switch (config.output.legalComments) {
|
|
4268
4278
|
case "inline":
|
|
4269
4279
|
options.format.comments = "some";
|
|
@@ -4286,9 +4296,9 @@ var init_minimize = __esm({
|
|
|
4286
4296
|
}
|
|
4287
4297
|
return options;
|
|
4288
4298
|
};
|
|
4289
|
-
parseMinifyOptions = (config,
|
|
4299
|
+
parseMinifyOptions = (config, isProd5 = true) => {
|
|
4290
4300
|
const minify = config.output.minify;
|
|
4291
|
-
if (minify === false || !
|
|
4301
|
+
if (minify === false || !isProd5) {
|
|
4292
4302
|
return {
|
|
4293
4303
|
minifyJs: false,
|
|
4294
4304
|
minifyCss: false,
|
|
@@ -4320,9 +4330,9 @@ var init_minimize = __esm({
|
|
|
4320
4330
|
if (api.context.bundlerType === "webpack") {
|
|
4321
4331
|
return;
|
|
4322
4332
|
}
|
|
4323
|
-
api.modifyBundlerChain(async (chain, { isProd:
|
|
4333
|
+
api.modifyBundlerChain(async (chain, { isProd: isProd5 }) => {
|
|
4324
4334
|
const config = api.getNormalizedConfig();
|
|
4325
|
-
const isMinimize =
|
|
4335
|
+
const isMinimize = isProd5 && config.output.minify !== false;
|
|
4326
4336
|
if (!isMinimize) {
|
|
4327
4337
|
return;
|
|
4328
4338
|
}
|
|
@@ -4530,10 +4540,17 @@ var init_HtmlBasicPlugin = __esm({
|
|
|
4530
4540
|
addTitleTag(headTags, data.plugin.options?.title);
|
|
4531
4541
|
}
|
|
4532
4542
|
addFavicon(headTags, favicon);
|
|
4533
|
-
const result = await this.modifyTagsFn(
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4543
|
+
const result = await this.modifyTagsFn(
|
|
4544
|
+
{
|
|
4545
|
+
headTags: headTags.map(formatBasicTag),
|
|
4546
|
+
bodyTags: bodyTags.map(formatBasicTag)
|
|
4547
|
+
},
|
|
4548
|
+
{
|
|
4549
|
+
compilation,
|
|
4550
|
+
assetPrefix: data.publicPath,
|
|
4551
|
+
filename: data.outputName
|
|
4552
|
+
}
|
|
4553
|
+
);
|
|
4537
4554
|
Object.assign(data, {
|
|
4538
4555
|
headTags: result.headTags.map(fromBasicTag),
|
|
4539
4556
|
bodyTags: result.bodyTags.map(fromBasicTag)
|
|
@@ -4632,18 +4649,16 @@ __export(html_exports, {
|
|
|
4632
4649
|
});
|
|
4633
4650
|
import path9, { isAbsolute as isAbsolute6 } from "path";
|
|
4634
4651
|
import {
|
|
4635
|
-
applyToCompiler as applyToCompiler2,
|
|
4636
4652
|
castArray as castArray5,
|
|
4637
4653
|
color as color11,
|
|
4638
|
-
createVirtualModule as createVirtualModule2,
|
|
4639
4654
|
deepmerge as deepmerge4,
|
|
4640
4655
|
fse as fse5,
|
|
4641
4656
|
getDistPath as getDistPath5,
|
|
4642
4657
|
isHtmlDisabled,
|
|
4643
|
-
isNil,
|
|
4644
4658
|
isPlainObject as isPlainObject3,
|
|
4645
4659
|
isURL,
|
|
4646
|
-
|
|
4660
|
+
reduceConfigsMergeContext as reduceConfigsMergeContext2,
|
|
4661
|
+
reduceConfigsWithContext as reduceConfigsWithContext3
|
|
4647
4662
|
} from "@rsbuild/shared";
|
|
4648
4663
|
function applyRemoveConsole(options, config) {
|
|
4649
4664
|
const { removeConsole } = config.performance;
|
|
@@ -4677,8 +4692,8 @@ function getTerserMinifyOptions(config) {
|
|
|
4677
4692
|
const finalOptions = applyRemoveConsole(options, config);
|
|
4678
4693
|
return finalOptions;
|
|
4679
4694
|
}
|
|
4680
|
-
async function getHtmlMinifyOptions(
|
|
4681
|
-
if (!
|
|
4695
|
+
async function getHtmlMinifyOptions(isProd5, config) {
|
|
4696
|
+
if (!isProd5 || !config.output.minify || !parseMinifyOptions(config).minifyHtml) {
|
|
4682
4697
|
return false;
|
|
4683
4698
|
}
|
|
4684
4699
|
const minifyJS = getTerserMinifyOptions(config);
|
|
@@ -4699,29 +4714,25 @@ async function getHtmlMinifyOptions(isProd4, config) {
|
|
|
4699
4714
|
return typeof htmlMinifyOptions === "object" ? deepmerge4(htmlMinifyDefaultOptions, htmlMinifyOptions) : htmlMinifyDefaultOptions;
|
|
4700
4715
|
}
|
|
4701
4716
|
function getTitle(entryName, config) {
|
|
4702
|
-
return
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
useObjectParam: true
|
|
4717
|
+
return reduceConfigsMergeContext2({
|
|
4718
|
+
initial: "",
|
|
4719
|
+
config: config.html.title,
|
|
4720
|
+
ctx: { entryName }
|
|
4707
4721
|
});
|
|
4708
4722
|
}
|
|
4709
4723
|
function getInject(entryName, config) {
|
|
4710
|
-
return
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
useObjectParam: true,
|
|
4715
|
-
isFalsy: isNil
|
|
4724
|
+
return reduceConfigsMergeContext2({
|
|
4725
|
+
initial: "head",
|
|
4726
|
+
config: config.html.inject,
|
|
4727
|
+
ctx: { entryName }
|
|
4716
4728
|
});
|
|
4717
4729
|
}
|
|
4718
4730
|
async function getTemplate(entryName, config, rootPath) {
|
|
4719
4731
|
const DEFAULT_TEMPLATE = path9.resolve(STATIC_PATH, "template.html");
|
|
4720
|
-
const templatePath =
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
useObjectParam: true
|
|
4732
|
+
const templatePath = reduceConfigsMergeContext2({
|
|
4733
|
+
initial: DEFAULT_TEMPLATE,
|
|
4734
|
+
config: config.html.template,
|
|
4735
|
+
ctx: { entryName }
|
|
4725
4736
|
});
|
|
4726
4737
|
if (templatePath === DEFAULT_TEMPLATE) {
|
|
4727
4738
|
return {
|
|
@@ -4746,19 +4757,17 @@ async function getTemplate(entryName, config, rootPath) {
|
|
|
4746
4757
|
};
|
|
4747
4758
|
}
|
|
4748
4759
|
function getFavicon(entryName, config) {
|
|
4749
|
-
return
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
useObjectParam: true
|
|
4760
|
+
return reduceConfigsMergeContext2({
|
|
4761
|
+
initial: "",
|
|
4762
|
+
config: config.html.favicon,
|
|
4763
|
+
ctx: { entryName }
|
|
4754
4764
|
});
|
|
4755
4765
|
}
|
|
4756
4766
|
function getMetaTags(entryName, config, templateContent) {
|
|
4757
|
-
const metaTags =
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
useObjectParam: true
|
|
4767
|
+
const metaTags = reduceConfigsMergeContext2({
|
|
4768
|
+
initial: {},
|
|
4769
|
+
config: config.html.meta,
|
|
4770
|
+
ctx: { entryName }
|
|
4762
4771
|
});
|
|
4763
4772
|
if (templateContent && metaTags.charset) {
|
|
4764
4773
|
const charsetRegExp = /<meta[^>]+charset=["'][^>]*>/i;
|
|
@@ -4783,10 +4792,10 @@ function getTemplateParameters(entryName, config, assetPrefix) {
|
|
|
4783
4792
|
options: pluginOptions
|
|
4784
4793
|
}
|
|
4785
4794
|
};
|
|
4786
|
-
return
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4795
|
+
return reduceConfigsWithContext3({
|
|
4796
|
+
initial: defaultOptions2,
|
|
4797
|
+
config: templateParameters,
|
|
4798
|
+
ctx: { entryName }
|
|
4790
4799
|
});
|
|
4791
4800
|
};
|
|
4792
4801
|
}
|
|
@@ -4834,12 +4843,12 @@ var init_html = __esm({
|
|
|
4834
4843
|
name: "rsbuild:html",
|
|
4835
4844
|
setup(api) {
|
|
4836
4845
|
api.modifyBundlerChain(
|
|
4837
|
-
async (chain, { HtmlPlugin, isProd:
|
|
4846
|
+
async (chain, { HtmlPlugin, isProd: isProd5, CHAIN_ID: CHAIN_ID3, target }) => {
|
|
4838
4847
|
const config = api.getNormalizedConfig();
|
|
4839
4848
|
if (isHtmlDisabled(config, target)) {
|
|
4840
4849
|
return;
|
|
4841
4850
|
}
|
|
4842
|
-
const minify = await getHtmlMinifyOptions(
|
|
4851
|
+
const minify = await getHtmlMinifyOptions(isProd5, config);
|
|
4843
4852
|
const assetPrefix = getPublicPathFromChain(chain, false);
|
|
4844
4853
|
const entries = chain.entryPoints.entries() || {};
|
|
4845
4854
|
const entryNames = Object.keys(entries);
|
|
@@ -4848,11 +4857,7 @@ var init_html = __esm({
|
|
|
4848
4857
|
const finalOptions = await Promise.all(
|
|
4849
4858
|
entryNames.map(async (entryName) => {
|
|
4850
4859
|
const entryValue = entries[entryName].values();
|
|
4851
|
-
const chunks = getChunks(
|
|
4852
|
-
entryName,
|
|
4853
|
-
// EntryDescription type is different between webpack and Rspack
|
|
4854
|
-
entryValue
|
|
4855
|
-
);
|
|
4860
|
+
const chunks = getChunks(entryName, entryValue);
|
|
4856
4861
|
const inject = getInject(entryName, config);
|
|
4857
4862
|
const filename = htmlPaths[entryName];
|
|
4858
4863
|
const { templatePath, templateContent } = await getTemplate(
|
|
@@ -4898,13 +4903,10 @@ var init_html = __esm({
|
|
|
4898
4903
|
pluginOptions.favicon = favicon;
|
|
4899
4904
|
}
|
|
4900
4905
|
}
|
|
4901
|
-
const finalOptions2 =
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
entryName,
|
|
4906
|
-
entryValue
|
|
4907
|
-
}
|
|
4906
|
+
const finalOptions2 = reduceConfigsWithContext3({
|
|
4907
|
+
initial: pluginOptions,
|
|
4908
|
+
config: typeof config.tools.htmlPlugin === "boolean" ? {} : config.tools.htmlPlugin,
|
|
4909
|
+
ctx: { entryName, entryValue }
|
|
4908
4910
|
});
|
|
4909
4911
|
return finalOptions2;
|
|
4910
4912
|
})
|
|
@@ -4929,50 +4931,18 @@ var init_html = __esm({
|
|
|
4929
4931
|
}
|
|
4930
4932
|
}
|
|
4931
4933
|
);
|
|
4932
|
-
api.onAfterCreateCompiler(({ compiler }) => {
|
|
4933
|
-
const { nonce } = api.getNormalizedConfig().security;
|
|
4934
|
-
if (!nonce) {
|
|
4935
|
-
return;
|
|
4936
|
-
}
|
|
4937
|
-
applyToCompiler2(compiler, (compiler2) => {
|
|
4938
|
-
const { plugins } = compiler2.options;
|
|
4939
|
-
const hasHTML = plugins.some(
|
|
4940
|
-
(plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
|
|
4941
|
-
);
|
|
4942
|
-
if (!hasHTML) {
|
|
4943
|
-
return;
|
|
4944
|
-
}
|
|
4945
|
-
const injectCode = createVirtualModule2(
|
|
4946
|
-
`__webpack_nonce__ = "${nonce}";`
|
|
4947
|
-
);
|
|
4948
|
-
new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
|
|
4949
|
-
name: void 0
|
|
4950
|
-
}).apply(compiler2);
|
|
4951
|
-
});
|
|
4952
|
-
});
|
|
4953
4934
|
api.modifyHTMLTags({
|
|
4954
4935
|
// ensure `crossorigin` and `nonce` can be applied to all tags
|
|
4955
4936
|
order: "post",
|
|
4956
4937
|
handler: ({ headTags, bodyTags }) => {
|
|
4957
|
-
var _a;
|
|
4958
4938
|
const config = api.getNormalizedConfig();
|
|
4959
4939
|
const { crossorigin } = config.html;
|
|
4960
|
-
const { nonce } = config.security;
|
|
4961
4940
|
const allTags = [...headTags, ...bodyTags];
|
|
4962
4941
|
if (crossorigin) {
|
|
4963
4942
|
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
4964
4943
|
for (const tag of allTags) {
|
|
4965
4944
|
if (tag.tag === "script" && tag.attrs?.src || tag.tag === "link" && tag.attrs?.rel === "stylesheet") {
|
|
4966
|
-
tag.attrs
|
|
4967
|
-
(_a = tag.attrs).crossorigin ?? (_a.crossorigin = formattedCrossorigin);
|
|
4968
|
-
}
|
|
4969
|
-
}
|
|
4970
|
-
}
|
|
4971
|
-
if (nonce) {
|
|
4972
|
-
for (const tag of allTags) {
|
|
4973
|
-
if (tag.tag === "script" || tag.tag === "style") {
|
|
4974
|
-
tag.attrs ?? (tag.attrs = {});
|
|
4975
|
-
tag.attrs.nonce = nonce;
|
|
4945
|
+
tag.attrs.crossorigin ??= formattedCrossorigin;
|
|
4976
4946
|
}
|
|
4977
4947
|
}
|
|
4978
4948
|
}
|
|
@@ -5185,7 +5155,7 @@ import {
|
|
|
5185
5155
|
getBrowserslistWithDefault as getBrowserslistWithDefault3,
|
|
5186
5156
|
getCoreJsVersion,
|
|
5187
5157
|
isWebTarget,
|
|
5188
|
-
|
|
5158
|
+
reduceConfigs as reduceConfigs2
|
|
5189
5159
|
} from "@rsbuild/shared";
|
|
5190
5160
|
async function getDefaultSwcConfig(config, rootPath, target) {
|
|
5191
5161
|
return {
|
|
@@ -5219,17 +5189,15 @@ async function applyCoreJs(swcConfig, chain, polyfillMode) {
|
|
|
5219
5189
|
});
|
|
5220
5190
|
}
|
|
5221
5191
|
function applyTransformImport(swcConfig, pluginImport) {
|
|
5222
|
-
var _a;
|
|
5223
5192
|
if (pluginImport !== false && pluginImport) {
|
|
5224
|
-
swcConfig.rspackExperiments
|
|
5225
|
-
|
|
5193
|
+
swcConfig.rspackExperiments ??= {};
|
|
5194
|
+
swcConfig.rspackExperiments.import ??= [];
|
|
5226
5195
|
swcConfig.rspackExperiments.import.push(...pluginImport);
|
|
5227
5196
|
}
|
|
5228
5197
|
}
|
|
5229
5198
|
function applySwcDecoratorConfig(swcConfig, config) {
|
|
5230
|
-
|
|
5231
|
-
swcConfig.jsc
|
|
5232
|
-
(_a = swcConfig.jsc).transform || (_a.transform = {});
|
|
5199
|
+
swcConfig.jsc ||= {};
|
|
5200
|
+
swcConfig.jsc.transform ||= {};
|
|
5233
5201
|
const { version: version2 } = config.source.decorators;
|
|
5234
5202
|
switch (version2) {
|
|
5235
5203
|
case "legacy":
|
|
@@ -5293,9 +5261,9 @@ var init_swc = __esm({
|
|
|
5293
5261
|
await applyCoreJs(swcConfig, chain, polyfillMode);
|
|
5294
5262
|
}
|
|
5295
5263
|
}
|
|
5296
|
-
const mergedSwcConfig =
|
|
5297
|
-
|
|
5298
|
-
|
|
5264
|
+
const mergedSwcConfig = reduceConfigs2({
|
|
5265
|
+
initial: swcConfig,
|
|
5266
|
+
config: config.tools.swc,
|
|
5299
5267
|
mergeFn: deepmerge5
|
|
5300
5268
|
});
|
|
5301
5269
|
rule.use(CHAIN_ID3.USE.SWC).loader(builtinSwcLoaderName).options(mergedSwcConfig);
|
|
@@ -5920,7 +5888,7 @@ function pluginBundleAnalyzer() {
|
|
|
5920
5888
|
if (isProd3() || !isUseAnalyzer(config)) {
|
|
5921
5889
|
return;
|
|
5922
5890
|
}
|
|
5923
|
-
config.dev
|
|
5891
|
+
config.dev ||= {};
|
|
5924
5892
|
config.dev.writeToDisk = true;
|
|
5925
5893
|
return config;
|
|
5926
5894
|
});
|
|
@@ -5995,7 +5963,7 @@ var init_rsdoctor = __esm({
|
|
|
5995
5963
|
if (registered) {
|
|
5996
5964
|
return;
|
|
5997
5965
|
}
|
|
5998
|
-
config.plugins
|
|
5966
|
+
config.plugins ||= [];
|
|
5999
5967
|
config.plugins.push(new module[pluginName]());
|
|
6000
5968
|
isAutoRegister = true;
|
|
6001
5969
|
}
|
|
@@ -6380,7 +6348,7 @@ var init_performance = __esm({
|
|
|
6380
6348
|
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
6381
6349
|
if (rsbuildConfig.performance?.profile) {
|
|
6382
6350
|
if (!rsbuildConfig.performance?.bundleAnalyze) {
|
|
6383
|
-
rsbuildConfig.performance
|
|
6351
|
+
rsbuildConfig.performance ??= {};
|
|
6384
6352
|
rsbuildConfig.performance.bundleAnalyze = {
|
|
6385
6353
|
analyzerMode: "disabled",
|
|
6386
6354
|
generateStatsFile: true
|
|
@@ -6781,8 +6749,8 @@ var init_lazyCompilation = __esm({
|
|
|
6781
6749
|
pluginLazyCompilation = () => ({
|
|
6782
6750
|
name: "rsbuild:lazy-compilation",
|
|
6783
6751
|
setup(api) {
|
|
6784
|
-
api.modifyBundlerChain((chain, { isProd:
|
|
6785
|
-
if (
|
|
6752
|
+
api.modifyBundlerChain((chain, { isProd: isProd5, target }) => {
|
|
6753
|
+
if (isProd5 || target !== "web") {
|
|
6786
6754
|
return;
|
|
6787
6755
|
}
|
|
6788
6756
|
const config = api.getNormalizedConfig();
|
|
@@ -6842,6 +6810,229 @@ var init_lazyCompilation = __esm({
|
|
|
6842
6810
|
}
|
|
6843
6811
|
});
|
|
6844
6812
|
|
|
6813
|
+
// src/plugins/sri.ts
|
|
6814
|
+
var sri_exports = {};
|
|
6815
|
+
__export(sri_exports, {
|
|
6816
|
+
pluginSri: () => pluginSri
|
|
6817
|
+
});
|
|
6818
|
+
import crypto2 from "crypto";
|
|
6819
|
+
import {
|
|
6820
|
+
isHtmlDisabled as isHtmlDisabled4,
|
|
6821
|
+
isProd as isProd4,
|
|
6822
|
+
logger as logger16,
|
|
6823
|
+
removeLeadingSlash as removeLeadingSlash2
|
|
6824
|
+
} from "@rsbuild/shared";
|
|
6825
|
+
var getAssetName, pluginSri;
|
|
6826
|
+
var init_sri = __esm({
|
|
6827
|
+
"src/plugins/sri.ts"() {
|
|
6828
|
+
"use strict";
|
|
6829
|
+
init_esm();
|
|
6830
|
+
init_constants();
|
|
6831
|
+
getAssetName = (url2, assetPrefix) => {
|
|
6832
|
+
if (url2.startsWith(assetPrefix)) {
|
|
6833
|
+
return removeLeadingSlash2(url2.replace(assetPrefix, ""));
|
|
6834
|
+
}
|
|
6835
|
+
return removeLeadingSlash2(url2);
|
|
6836
|
+
};
|
|
6837
|
+
pluginSri = () => ({
|
|
6838
|
+
name: "rsbuild:sri",
|
|
6839
|
+
setup(api) {
|
|
6840
|
+
const placeholder = "RSBUILD_INTEGRITY_PLACEHOLDER:";
|
|
6841
|
+
const getAlgorithm = () => {
|
|
6842
|
+
const config = api.getNormalizedConfig();
|
|
6843
|
+
const { sri } = config.security;
|
|
6844
|
+
const enable = sri.enable === "auto" ? isProd4() : sri.enable;
|
|
6845
|
+
if (!enable) {
|
|
6846
|
+
return null;
|
|
6847
|
+
}
|
|
6848
|
+
const { algorithm = "sha384" } = sri;
|
|
6849
|
+
return algorithm;
|
|
6850
|
+
};
|
|
6851
|
+
api.modifyHTMLTags({
|
|
6852
|
+
// ensure `sri` can be applied to all tags
|
|
6853
|
+
order: "post",
|
|
6854
|
+
handler(tags, { assetPrefix }) {
|
|
6855
|
+
const algorithm = getAlgorithm();
|
|
6856
|
+
if (!algorithm) {
|
|
6857
|
+
return tags;
|
|
6858
|
+
}
|
|
6859
|
+
const allTags = [...tags.headTags, ...tags.bodyTags];
|
|
6860
|
+
for (const tag of allTags) {
|
|
6861
|
+
let url2 = "";
|
|
6862
|
+
if (!tag.attrs) {
|
|
6863
|
+
continue;
|
|
6864
|
+
}
|
|
6865
|
+
if (tag.tag === "script" && typeof tag.attrs.src === "string") {
|
|
6866
|
+
url2 = tag.attrs.src;
|
|
6867
|
+
} else if (tag.tag === "link" && tag.attrs.rel === "stylesheet" && typeof tag.attrs.href === "string") {
|
|
6868
|
+
url2 = tag.attrs.href;
|
|
6869
|
+
}
|
|
6870
|
+
if (!url2) {
|
|
6871
|
+
continue;
|
|
6872
|
+
}
|
|
6873
|
+
const assetName = getAssetName(url2, assetPrefix);
|
|
6874
|
+
if (!assetName) {
|
|
6875
|
+
continue;
|
|
6876
|
+
}
|
|
6877
|
+
tag.attrs.integrity ??= `${placeholder}${assetName}`;
|
|
6878
|
+
}
|
|
6879
|
+
return tags;
|
|
6880
|
+
}
|
|
6881
|
+
});
|
|
6882
|
+
const replaceIntegrity = (htmlContent, assets, algorithm, integrityCache) => {
|
|
6883
|
+
const regex = /integrity="RSBUILD_INTEGRITY_PLACEHOLDER:([^"]+)"/g;
|
|
6884
|
+
const matches = htmlContent.matchAll(regex);
|
|
6885
|
+
let replacedHtml = htmlContent;
|
|
6886
|
+
const calcIntegrity = (algorithm2, assetName, data) => {
|
|
6887
|
+
if (integrityCache.has(assetName)) {
|
|
6888
|
+
return integrityCache.get(assetName);
|
|
6889
|
+
}
|
|
6890
|
+
const hash = crypto2.createHash(algorithm2).update(data).digest().toString("base64");
|
|
6891
|
+
const integrity = `${algorithm2}-${hash}`;
|
|
6892
|
+
integrityCache.set(assetName, integrity);
|
|
6893
|
+
return integrity;
|
|
6894
|
+
};
|
|
6895
|
+
for (const match of matches) {
|
|
6896
|
+
const assetName = match[1];
|
|
6897
|
+
if (!assetName) {
|
|
6898
|
+
continue;
|
|
6899
|
+
}
|
|
6900
|
+
if (assets[assetName]) {
|
|
6901
|
+
const integrity = calcIntegrity(
|
|
6902
|
+
algorithm,
|
|
6903
|
+
assetName,
|
|
6904
|
+
assets[assetName].buffer()
|
|
6905
|
+
);
|
|
6906
|
+
replacedHtml = replacedHtml.replaceAll(
|
|
6907
|
+
`integrity="${placeholder}${assetName}"`,
|
|
6908
|
+
`integrity="${integrity}"`
|
|
6909
|
+
);
|
|
6910
|
+
} else {
|
|
6911
|
+
logger16.debug(
|
|
6912
|
+
`[rsbuild:sri] failed to generate integrity for ${assetName}.`
|
|
6913
|
+
);
|
|
6914
|
+
replacedHtml = replacedHtml.replace(
|
|
6915
|
+
`integrity="${placeholder}${assetName}"`,
|
|
6916
|
+
""
|
|
6917
|
+
);
|
|
6918
|
+
}
|
|
6919
|
+
}
|
|
6920
|
+
return replacedHtml;
|
|
6921
|
+
};
|
|
6922
|
+
class SriReplaceIntegrityPlugin {
|
|
6923
|
+
constructor(algorithm) {
|
|
6924
|
+
__publicField(this, "algorithm");
|
|
6925
|
+
this.algorithm = algorithm;
|
|
6926
|
+
}
|
|
6927
|
+
apply(compiler) {
|
|
6928
|
+
compiler.hooks.compilation.tap(
|
|
6929
|
+
"SriReplaceIntegrityPlugin",
|
|
6930
|
+
(compilation) => {
|
|
6931
|
+
compilation.hooks.processAssets.tapPromise(
|
|
6932
|
+
{
|
|
6933
|
+
name: "SriReplaceIntegrityPlugin",
|
|
6934
|
+
// use to final stage to get the final asset content
|
|
6935
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
6936
|
+
},
|
|
6937
|
+
async (assets) => {
|
|
6938
|
+
const integrityCache = /* @__PURE__ */ new Map();
|
|
6939
|
+
for (const asset of Object.keys(assets)) {
|
|
6940
|
+
if (!HTML_REGEX.test(asset)) {
|
|
6941
|
+
continue;
|
|
6942
|
+
}
|
|
6943
|
+
const htmlContent = assets[asset].source();
|
|
6944
|
+
if (!htmlContent.includes(placeholder)) {
|
|
6945
|
+
continue;
|
|
6946
|
+
}
|
|
6947
|
+
assets[asset] = new compiler.webpack.sources.RawSource(
|
|
6948
|
+
replaceIntegrity(
|
|
6949
|
+
htmlContent,
|
|
6950
|
+
assets,
|
|
6951
|
+
this.algorithm,
|
|
6952
|
+
integrityCache
|
|
6953
|
+
)
|
|
6954
|
+
);
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
);
|
|
6958
|
+
}
|
|
6959
|
+
);
|
|
6960
|
+
}
|
|
6961
|
+
}
|
|
6962
|
+
api.modifyBundlerChain((chain, { target }) => {
|
|
6963
|
+
const config = api.getNormalizedConfig();
|
|
6964
|
+
if (isHtmlDisabled4(config, target)) {
|
|
6965
|
+
return;
|
|
6966
|
+
}
|
|
6967
|
+
const algorithm = getAlgorithm();
|
|
6968
|
+
if (!algorithm) {
|
|
6969
|
+
return;
|
|
6970
|
+
}
|
|
6971
|
+
chain.plugin("rsbuild-sri-replace").use(SriReplaceIntegrityPlugin, [algorithm]);
|
|
6972
|
+
});
|
|
6973
|
+
}
|
|
6974
|
+
});
|
|
6975
|
+
}
|
|
6976
|
+
});
|
|
6977
|
+
|
|
6978
|
+
// src/plugins/nonce.ts
|
|
6979
|
+
var nonce_exports = {};
|
|
6980
|
+
__export(nonce_exports, {
|
|
6981
|
+
pluginNonce: () => pluginNonce
|
|
6982
|
+
});
|
|
6983
|
+
import { applyToCompiler as applyToCompiler2, createVirtualModule as createVirtualModule2 } from "@rsbuild/shared";
|
|
6984
|
+
var pluginNonce;
|
|
6985
|
+
var init_nonce = __esm({
|
|
6986
|
+
"src/plugins/nonce.ts"() {
|
|
6987
|
+
"use strict";
|
|
6988
|
+
init_esm();
|
|
6989
|
+
pluginNonce = () => ({
|
|
6990
|
+
name: "rsbuild:nonce",
|
|
6991
|
+
setup(api) {
|
|
6992
|
+
api.onAfterCreateCompiler(({ compiler }) => {
|
|
6993
|
+
const { nonce } = api.getNormalizedConfig().security;
|
|
6994
|
+
if (!nonce) {
|
|
6995
|
+
return;
|
|
6996
|
+
}
|
|
6997
|
+
applyToCompiler2(compiler, (compiler2) => {
|
|
6998
|
+
const { plugins } = compiler2.options;
|
|
6999
|
+
const hasHTML = plugins.some(
|
|
7000
|
+
(plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
|
|
7001
|
+
);
|
|
7002
|
+
if (!hasHTML) {
|
|
7003
|
+
return;
|
|
7004
|
+
}
|
|
7005
|
+
const injectCode = createVirtualModule2(
|
|
7006
|
+
`__webpack_nonce__ = "${nonce}";`
|
|
7007
|
+
);
|
|
7008
|
+
new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
|
|
7009
|
+
name: void 0
|
|
7010
|
+
}).apply(compiler2);
|
|
7011
|
+
});
|
|
7012
|
+
});
|
|
7013
|
+
api.modifyHTMLTags({
|
|
7014
|
+
// ensure `nonce` can be applied to all tags
|
|
7015
|
+
order: "post",
|
|
7016
|
+
handler: ({ headTags, bodyTags }) => {
|
|
7017
|
+
const config = api.getNormalizedConfig();
|
|
7018
|
+
const { nonce } = config.security;
|
|
7019
|
+
const allTags = [...headTags, ...bodyTags];
|
|
7020
|
+
if (nonce) {
|
|
7021
|
+
for (const tag of allTags) {
|
|
7022
|
+
if (tag.tag === "script" || tag.tag === "style") {
|
|
7023
|
+
tag.attrs ??= {};
|
|
7024
|
+
tag.attrs.nonce = nonce;
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
return { headTags, bodyTags };
|
|
7029
|
+
}
|
|
7030
|
+
});
|
|
7031
|
+
}
|
|
7032
|
+
});
|
|
7033
|
+
}
|
|
7034
|
+
});
|
|
7035
|
+
|
|
6845
7036
|
// src/createRsbuild.ts
|
|
6846
7037
|
var createRsbuild_exports = {};
|
|
6847
7038
|
__export(createRsbuild_exports, {
|
|
@@ -6881,6 +7072,8 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
6881
7072
|
const { pluginModuleFederation: pluginModuleFederation2 } = await Promise.resolve().then(() => (init_moduleFederation(), moduleFederation_exports));
|
|
6882
7073
|
const { pluginRspackProfile: pluginRspackProfile2 } = await Promise.resolve().then(() => (init_rspackProfile(), rspackProfile_exports));
|
|
6883
7074
|
const { pluginLazyCompilation: pluginLazyCompilation2 } = await Promise.resolve().then(() => (init_lazyCompilation(), lazyCompilation_exports));
|
|
7075
|
+
const { pluginSri: pluginSri2 } = await Promise.resolve().then(() => (init_sri(), sri_exports));
|
|
7076
|
+
const { pluginNonce: pluginNonce2 } = await Promise.resolve().then(() => (init_nonce(), nonce_exports));
|
|
6884
7077
|
pluginManager.addPlugins([
|
|
6885
7078
|
pluginBasic2(),
|
|
6886
7079
|
pluginEntry2(),
|
|
@@ -6892,8 +7085,8 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
6892
7085
|
// cleanOutput plugin should before the html plugin
|
|
6893
7086
|
pluginCleanOutput2(),
|
|
6894
7087
|
pluginAsset2(),
|
|
6895
|
-
pluginHtml2(async (
|
|
6896
|
-
const result = await context.hooks.modifyHTMLTags.call(
|
|
7088
|
+
pluginHtml2(async (...args) => {
|
|
7089
|
+
const result = await context.hooks.modifyHTMLTags.call(...args);
|
|
6897
7090
|
return result[0];
|
|
6898
7091
|
}),
|
|
6899
7092
|
pluginWasm2(),
|
|
@@ -6916,7 +7109,9 @@ async function applyDefaultPlugins(pluginManager, context) {
|
|
|
6916
7109
|
pluginManifest2(),
|
|
6917
7110
|
pluginModuleFederation2(),
|
|
6918
7111
|
pluginRspackProfile2(),
|
|
6919
|
-
pluginLazyCompilation2()
|
|
7112
|
+
pluginLazyCompilation2(),
|
|
7113
|
+
pluginSri2(),
|
|
7114
|
+
pluginNonce2()
|
|
6920
7115
|
]);
|
|
6921
7116
|
}
|
|
6922
7117
|
async function createRsbuild(options = {}) {
|
|
@@ -7016,7 +7211,7 @@ var init_createRsbuild = __esm({
|
|
|
7016
7211
|
});
|
|
7017
7212
|
|
|
7018
7213
|
// src/cli/init.ts
|
|
7019
|
-
import { isDev as isDev2, logger as
|
|
7214
|
+
import { isDev as isDev2, logger as logger17 } from "@rsbuild/shared";
|
|
7020
7215
|
async function init({
|
|
7021
7216
|
cliOptions,
|
|
7022
7217
|
isRestart
|
|
@@ -7047,21 +7242,21 @@ async function init({
|
|
|
7047
7242
|
watchFiles(files);
|
|
7048
7243
|
}
|
|
7049
7244
|
const { createRsbuild: createRsbuild2 } = await Promise.resolve().then(() => (init_createRsbuild(), createRsbuild_exports));
|
|
7050
|
-
config.source
|
|
7245
|
+
config.source ||= {};
|
|
7051
7246
|
config.source.define = {
|
|
7052
7247
|
...envs.publicVars,
|
|
7053
7248
|
...config.source.define
|
|
7054
7249
|
};
|
|
7055
7250
|
if (commonOpts.open && !config.dev?.startUrl) {
|
|
7056
|
-
config.dev
|
|
7251
|
+
config.dev ||= {};
|
|
7057
7252
|
config.dev.startUrl = commonOpts.open;
|
|
7058
7253
|
}
|
|
7059
7254
|
if (commonOpts.host) {
|
|
7060
|
-
config.server
|
|
7255
|
+
config.server ||= {};
|
|
7061
7256
|
config.server.host = commonOpts.host;
|
|
7062
7257
|
}
|
|
7063
7258
|
if (commonOpts.port) {
|
|
7064
|
-
config.server
|
|
7259
|
+
config.server ||= {};
|
|
7065
7260
|
config.server.port = commonOpts.port;
|
|
7066
7261
|
}
|
|
7067
7262
|
return createRsbuild2({
|
|
@@ -7070,7 +7265,7 @@ async function init({
|
|
|
7070
7265
|
});
|
|
7071
7266
|
} catch (err) {
|
|
7072
7267
|
if (isRestart) {
|
|
7073
|
-
|
|
7268
|
+
logger17.error(err);
|
|
7074
7269
|
} else {
|
|
7075
7270
|
throw err;
|
|
7076
7271
|
}
|
|
@@ -7116,10 +7311,11 @@ init_esm();
|
|
|
7116
7311
|
|
|
7117
7312
|
// src/cli/commands.ts
|
|
7118
7313
|
init_esm();
|
|
7314
|
+
init_helpers();
|
|
7119
7315
|
init_init();
|
|
7120
7316
|
import { existsSync } from "fs";
|
|
7121
7317
|
import { join as join12 } from "path";
|
|
7122
|
-
import { color as color13, logger as
|
|
7318
|
+
import { color as color13, logger as logger18 } from "@rsbuild/shared";
|
|
7123
7319
|
import { program } from "../compiled/commander/index.js";
|
|
7124
7320
|
var applyCommonOptions = (command) => {
|
|
7125
7321
|
command.option(
|
|
@@ -7134,7 +7330,7 @@ var applyServerOptions = (command) => {
|
|
|
7134
7330
|
command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
|
|
7135
7331
|
};
|
|
7136
7332
|
function runCli() {
|
|
7137
|
-
program.name("rsbuild").usage("<command> [options]").version("0.7.
|
|
7333
|
+
program.name("rsbuild").usage("<command> [options]").version("0.7.3");
|
|
7138
7334
|
const devCommand = program.command("dev");
|
|
7139
7335
|
const buildCommand = program.command("build");
|
|
7140
7336
|
const previewCommand = program.command("preview");
|
|
@@ -7148,8 +7344,8 @@ function runCli() {
|
|
|
7148
7344
|
const rsbuild = await init({ cliOptions: options });
|
|
7149
7345
|
await rsbuild?.startDevServer();
|
|
7150
7346
|
} catch (err) {
|
|
7151
|
-
|
|
7152
|
-
|
|
7347
|
+
logger18.error("Failed to start dev server.");
|
|
7348
|
+
logger18.error(err);
|
|
7153
7349
|
process.exit(1);
|
|
7154
7350
|
}
|
|
7155
7351
|
});
|
|
@@ -7160,25 +7356,35 @@ function runCli() {
|
|
|
7160
7356
|
watch: options.watch
|
|
7161
7357
|
});
|
|
7162
7358
|
} catch (err) {
|
|
7163
|
-
|
|
7164
|
-
|
|
7359
|
+
logger18.error("Failed to build.");
|
|
7360
|
+
logger18.error(err);
|
|
7165
7361
|
process.exit(1);
|
|
7166
7362
|
}
|
|
7167
7363
|
});
|
|
7168
7364
|
previewCommand.description("preview the production build locally").action(async (options) => {
|
|
7169
7365
|
try {
|
|
7170
7366
|
const rsbuild = await init({ cliOptions: options });
|
|
7171
|
-
if (rsbuild
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7367
|
+
if (rsbuild) {
|
|
7368
|
+
const { distPath } = rsbuild.context;
|
|
7369
|
+
if (!existsSync(distPath)) {
|
|
7370
|
+
throw new Error(
|
|
7371
|
+
`The output directory ${color13.yellow(
|
|
7372
|
+
distPath
|
|
7373
|
+
)} does not exist, please build the project before previewing.`
|
|
7374
|
+
);
|
|
7375
|
+
}
|
|
7376
|
+
if (isEmptyDir(distPath)) {
|
|
7377
|
+
throw new Error(
|
|
7378
|
+
`The output directory ${color13.yellow(
|
|
7379
|
+
distPath
|
|
7380
|
+
)} is empty, please build the project before previewing.`
|
|
7381
|
+
);
|
|
7382
|
+
}
|
|
7177
7383
|
}
|
|
7178
7384
|
await rsbuild?.preview();
|
|
7179
7385
|
} catch (err) {
|
|
7180
|
-
|
|
7181
|
-
|
|
7386
|
+
logger18.error("Failed to start preview server.");
|
|
7387
|
+
logger18.error(err);
|
|
7182
7388
|
process.exit(1);
|
|
7183
7389
|
}
|
|
7184
7390
|
});
|
|
@@ -7192,8 +7398,8 @@ function runCli() {
|
|
|
7192
7398
|
writeToDisk: true
|
|
7193
7399
|
});
|
|
7194
7400
|
} catch (err) {
|
|
7195
|
-
|
|
7196
|
-
|
|
7401
|
+
logger18.error("Failed to inspect config.");
|
|
7402
|
+
logger18.error(err);
|
|
7197
7403
|
process.exit(1);
|
|
7198
7404
|
}
|
|
7199
7405
|
});
|
|
@@ -7202,7 +7408,7 @@ function runCli() {
|
|
|
7202
7408
|
|
|
7203
7409
|
// src/cli/prepare.ts
|
|
7204
7410
|
init_esm();
|
|
7205
|
-
import { logger as
|
|
7411
|
+
import { logger as logger19 } from "@rsbuild/shared";
|
|
7206
7412
|
function initNodeEnv() {
|
|
7207
7413
|
if (!process.env.NODE_ENV) {
|
|
7208
7414
|
const command = process.argv[2];
|
|
@@ -7215,7 +7421,7 @@ function prepareCli() {
|
|
|
7215
7421
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
7216
7422
|
console.log();
|
|
7217
7423
|
}
|
|
7218
|
-
|
|
7424
|
+
logger19.greet(` ${`Rsbuild v${"0.7.3"}`}
|
|
7219
7425
|
`);
|
|
7220
7426
|
}
|
|
7221
7427
|
|
|
@@ -7241,8 +7447,8 @@ init_createRsbuild();
|
|
|
7241
7447
|
init_config();
|
|
7242
7448
|
init_mergeConfig();
|
|
7243
7449
|
init_constants();
|
|
7244
|
-
import { logger as
|
|
7245
|
-
var version = "0.7.
|
|
7450
|
+
import { logger as logger20 } from "@rsbuild/shared";
|
|
7451
|
+
var version = "0.7.3";
|
|
7246
7452
|
export {
|
|
7247
7453
|
PLUGIN_CSS_NAME,
|
|
7248
7454
|
PLUGIN_SWC_NAME,
|
|
@@ -7251,7 +7457,7 @@ export {
|
|
|
7251
7457
|
defineConfig,
|
|
7252
7458
|
loadConfig,
|
|
7253
7459
|
loadEnv,
|
|
7254
|
-
|
|
7460
|
+
logger20 as logger,
|
|
7255
7461
|
mergeRsbuildConfig,
|
|
7256
7462
|
rspack10 as rspack,
|
|
7257
7463
|
version
|