@rsbuild/core 1.3.0-beta.1 → 1.3.0-beta.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/cors/index.d.ts +56 -1
- package/compiled/css-loader/index.js +18 -18
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rspack-chain/index.d.ts +4 -0
- package/compiled/rspack-chain/index.js +67 -66
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/dist/index.cjs +528 -551
- package/dist/index.js +523 -546
- package/dist-types/configChain.d.ts +8 -0
- package/dist-types/helpers/index.d.ts +0 -2
- package/dist-types/plugins/css.d.ts +1 -1
- package/dist-types/provider/createCompiler.d.ts +1 -23
- package/dist-types/server/{compilerDevMiddleware.d.ts → compilationManager.d.ts} +9 -10
- package/dist-types/server/compilationMiddleware.d.ts +37 -0
- package/dist-types/server/devMiddlewares.d.ts +22 -0
- package/dist-types/server/middlewares.d.ts +4 -5
- package/dist-types/server/socketServer.d.ts +1 -1
- package/dist-types/server/watchFiles.d.ts +2 -2
- package/package.json +6 -5
- package/types.d.ts +71 -26
- package/dist-types/plugins/lazyCompilation.d.ts +0 -2
- package/dist-types/server/devMiddleware.d.ts +0 -27
- package/dist-types/server/getDevMiddlewares.d.ts +0 -30
package/dist/index.cjs
CHANGED
|
@@ -995,7 +995,7 @@ __webpack_require__.n = (module)=>{
|
|
|
995
995
|
enumerable: !0,
|
|
996
996
|
get: definition[key]
|
|
997
997
|
});
|
|
998
|
-
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r =
|
|
998
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
999
999
|
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
1000
1000
|
value: 'Module'
|
|
1001
1001
|
}), Object.defineProperty(exports1, '__esModule', {
|
|
@@ -1367,12 +1367,6 @@ var __webpack_exports__ = {};
|
|
|
1367
1367
|
} catch {
|
|
1368
1368
|
return !1;
|
|
1369
1369
|
}
|
|
1370
|
-
}, parseUrl = (url)=>{
|
|
1371
|
-
try {
|
|
1372
|
-
return new external_node_url_namespaceObject.URL(url);
|
|
1373
|
-
} catch {
|
|
1374
|
-
return null;
|
|
1375
|
-
}
|
|
1376
1370
|
}, 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_namespaceObject.posix.join(assetPrefix, url);
|
|
1377
1371
|
function getFilename(config, type, isProd, isServer) {
|
|
1378
1372
|
let { filename, filenameHash } = config.output, hash = 'string' == typeof filenameHash ? filenameHash ? `.[${filenameHash}]` : '' : filenameHash ? '.[contenthash:8]' : '';
|
|
@@ -2222,7 +2216,7 @@ var __webpack_exports__ = {};
|
|
|
2222
2216
|
async function createContext(options, userConfig) {
|
|
2223
2217
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
2224
2218
|
return {
|
|
2225
|
-
version: "1.3.0-beta.
|
|
2219
|
+
version: "1.3.0-beta.3",
|
|
2226
2220
|
rootPath,
|
|
2227
2221
|
distPath: '',
|
|
2228
2222
|
cachePath,
|
|
@@ -2389,12 +2383,16 @@ var __webpack_exports__ = {};
|
|
|
2389
2383
|
TS: 'ts',
|
|
2390
2384
|
CSS: 'css',
|
|
2391
2385
|
CSS_RAW: 'css-raw',
|
|
2386
|
+
CSS_INLINE: 'css-inline',
|
|
2392
2387
|
LESS: 'less',
|
|
2393
2388
|
LESS_RAW: 'less-raw',
|
|
2389
|
+
LESS_INLINE: 'less-inline',
|
|
2394
2390
|
SASS: 'sass',
|
|
2395
2391
|
SASS_RAW: 'sass-raw',
|
|
2392
|
+
SASS_INLINE: 'sass-inline',
|
|
2396
2393
|
STYLUS: 'stylus',
|
|
2397
2394
|
STYLUS_RAW: 'stylus-raw',
|
|
2395
|
+
STYLUS_INLINE: 'stylus-inline',
|
|
2398
2396
|
SVG: 'svg',
|
|
2399
2397
|
PUG: 'pug',
|
|
2400
2398
|
VUE: 'vue',
|
|
@@ -2457,7 +2455,7 @@ var __webpack_exports__ = {};
|
|
|
2457
2455
|
let generatorOptions = {
|
|
2458
2456
|
filename
|
|
2459
2457
|
};
|
|
2460
|
-
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/(__inline=false|url)/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(/inline/), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
2458
|
+
!1 === emit && (generatorOptions.emit = !1), rule.oneOf(`${assetType}-asset-url`).type('asset/resource').resourceQuery(/(__inline=false|url)/).set('generator', generatorOptions), rule.oneOf(`${assetType}-asset-inline`).type('asset/inline').resourceQuery(/inline/), rule.oneOf(`${assetType}-asset-raw`).type('asset/source').resourceQuery(/raw/), rule.oneOf(`${assetType}-asset`).type('asset').parser({
|
|
2461
2459
|
dataUrlCondition: {
|
|
2462
2460
|
maxSize
|
|
2463
2461
|
}
|
|
@@ -2527,10 +2525,8 @@ var __webpack_exports__ = {};
|
|
|
2527
2525
|
test: /\.css$/,
|
|
2528
2526
|
filename: '[file].map[query]'
|
|
2529
2527
|
}
|
|
2530
|
-
]), chain.context(api.context.rootPath), chain.mode(environment.config.mode), chain.
|
|
2531
|
-
|
|
2532
|
-
level: 'error'
|
|
2533
|
-
}
|
|
2528
|
+
]), chain.context(api.context.rootPath), chain.mode(environment.config.mode), chain.infrastructureLogging({
|
|
2529
|
+
level: 'error'
|
|
2534
2530
|
}), chain.watchOptions({
|
|
2535
2531
|
ignored: /[\\/](?:\.git|node_modules)[\\/]/,
|
|
2536
2532
|
aggregateTimeout: 0
|
|
@@ -2719,11 +2715,78 @@ var __webpack_exports__ = {};
|
|
|
2719
2715
|
plugin && (pluginHelper_htmlPlugin = plugin);
|
|
2720
2716
|
}, getHTMLPlugin = ()=>(pluginHelper_htmlPlugin || (pluginHelper_htmlPlugin = pluginHelper_require('../compiled/html-rspack-plugin/index.js')), pluginHelper_htmlPlugin), setCssExtractPlugin = (plugin)=>{
|
|
2721
2717
|
cssExtractPlugin = plugin;
|
|
2722
|
-
}, getCssExtractPlugin = ()=>cssExtractPlugin || core_default().CssExtractRspackPlugin,
|
|
2718
|
+
}, getCssExtractPlugin = ()=>cssExtractPlugin || core_default().CssExtractRspackPlugin, getSwcMinimizerOptions = (config, jsOptions)=>{
|
|
2719
|
+
let options = {};
|
|
2720
|
+
options.minimizerOptions ||= {}, options.minimizerOptions.format ||= {};
|
|
2721
|
+
let { removeConsole } = config.performance;
|
|
2722
|
+
if (!0 === removeConsole) options.minimizerOptions.compress = {
|
|
2723
|
+
drop_console: !0
|
|
2724
|
+
};
|
|
2725
|
+
else if (Array.isArray(removeConsole)) {
|
|
2726
|
+
let pureFuncs = removeConsole.map((method)=>`console.${method}`);
|
|
2727
|
+
options.minimizerOptions.compress = {
|
|
2728
|
+
pure_funcs: pureFuncs
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
switch(config.output.legalComments){
|
|
2732
|
+
case 'inline':
|
|
2733
|
+
options.minimizerOptions.format.comments = 'some', options.extractComments = !1;
|
|
2734
|
+
break;
|
|
2735
|
+
case 'linked':
|
|
2736
|
+
options.extractComments = !0;
|
|
2737
|
+
break;
|
|
2738
|
+
case 'none':
|
|
2739
|
+
options.minimizerOptions.format.comments = !1, options.extractComments = !1;
|
|
2740
|
+
}
|
|
2741
|
+
return (options.minimizerOptions.format.asciiOnly = 'ascii' === config.output.charset, jsOptions) ? cjs_default()(options, jsOptions) : options;
|
|
2742
|
+
}, parseMinifyOptions = (config, isProd)=>{
|
|
2743
|
+
let { minify } = config.output;
|
|
2744
|
+
return !1 !== minify && isProd ? !0 === minify ? {
|
|
2745
|
+
minifyJs: !0,
|
|
2746
|
+
minifyCss: !0
|
|
2747
|
+
} : {
|
|
2748
|
+
minifyJs: !1 !== minify.js,
|
|
2749
|
+
minifyCss: !1 !== minify.css,
|
|
2750
|
+
jsOptions: minify.jsOptions,
|
|
2751
|
+
cssOptions: minify.cssOptions
|
|
2752
|
+
} : {
|
|
2753
|
+
minifyJs: !1,
|
|
2754
|
+
minifyCss: !1
|
|
2755
|
+
};
|
|
2756
|
+
}, pluginMinimize = ()=>({
|
|
2757
|
+
name: 'rsbuild:minimize',
|
|
2758
|
+
setup (api) {
|
|
2759
|
+
let isRspack = 'rspack' === api.context.bundlerType;
|
|
2760
|
+
api.modifyBundlerChain(async (chain, { isProd, environment, CHAIN_ID })=>{
|
|
2761
|
+
let { config } = environment, { minifyJs, minifyCss, jsOptions, cssOptions } = parseMinifyOptions(config, isProd);
|
|
2762
|
+
if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs && isRspack && chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(core_namespaceObject.rspack.SwcJsMinimizerRspackPlugin, [
|
|
2763
|
+
getSwcMinimizerOptions(config, jsOptions)
|
|
2764
|
+
]).end(), minifyCss && isRspack) {
|
|
2765
|
+
let loaderOptions = getLightningCSSLoaderOptions(config, environment.browserslist, !0), defaultOptions = {
|
|
2766
|
+
minimizerOptions: {
|
|
2767
|
+
targets: isPlainObject(loaderOptions.targets) ? environment.browserslist : loaderOptions.targets,
|
|
2768
|
+
...pick(loaderOptions, [
|
|
2769
|
+
'draft',
|
|
2770
|
+
'include',
|
|
2771
|
+
'exclude',
|
|
2772
|
+
'nonStandard',
|
|
2773
|
+
'pseudoClasses',
|
|
2774
|
+
'unusedSymbols',
|
|
2775
|
+
'errorRecovery'
|
|
2776
|
+
])
|
|
2777
|
+
}
|
|
2778
|
+
}, mergedOptions = cssOptions ? cjs_default()(defaultOptions, cssOptions) : defaultOptions;
|
|
2779
|
+
chain.optimization.minimizer(CHAIN_ID.MINIMIZER.CSS).use(core_namespaceObject.rspack.LightningCssMinimizerRspackPlugin, [
|
|
2780
|
+
mergedOptions
|
|
2781
|
+
]).end();
|
|
2782
|
+
}
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
}), getCSSModulesLocalIdentName = (config, isProd)=>config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), getLightningCSSLoaderOptions = (config, targets, minify)=>{
|
|
2723
2786
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
2724
2787
|
targets
|
|
2725
2788
|
};
|
|
2726
|
-
return
|
|
2789
|
+
return minify && (initialOptions.minify = !0), reduceConfigs({
|
|
2727
2790
|
initial: initialOptions,
|
|
2728
2791
|
config: userOptions
|
|
2729
2792
|
});
|
|
@@ -2821,12 +2884,12 @@ var __webpack_exports__ = {};
|
|
|
2821
2884
|
api.modifyBundlerChain({
|
|
2822
2885
|
order: 'pre',
|
|
2823
2886
|
handler: async (chain, { target, isProd, CHAIN_ID, environment })=>{
|
|
2824
|
-
let rule = chain.module.rule(CHAIN_ID.RULE.CSS), { config } = environment;
|
|
2887
|
+
let rule = chain.module.rule(CHAIN_ID.RULE.CSS), inlineRule = chain.module.rule(CHAIN_ID.RULE.CSS_INLINE), { config } = environment;
|
|
2825
2888
|
rule.test(CSS_REGEX).type("javascript/auto").dependency({
|
|
2826
2889
|
not: 'url'
|
|
2827
2890
|
}).resourceQuery({
|
|
2828
|
-
not: /raw/
|
|
2829
|
-
}), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(/raw/);
|
|
2891
|
+
not: /raw|inline/
|
|
2892
|
+
}), inlineRule.test(CSS_REGEX).type("javascript/auto").resourceQuery(/inline/), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(/raw/);
|
|
2830
2893
|
let emitCss = config.output.emitCss ?? 'web' === target;
|
|
2831
2894
|
if (emitCss) {
|
|
2832
2895
|
if (config.output.injectStyles) {
|
|
@@ -2837,20 +2900,33 @@ var __webpack_exports__ = {};
|
|
|
2837
2900
|
rule.use(CHAIN_ID.USE.STYLE).loader(getCompiledPath('style-loader')).options(styleLoaderOptions);
|
|
2838
2901
|
} else rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(getCssExtractPlugin().loader).options(config.tools.cssExtract.loaderOptions);
|
|
2839
2902
|
} else rule.use(CHAIN_ID.USE.IGNORE_CSS).loader(external_node_path_default().join(LOADER_PATH, 'ignoreCssLoader.mjs'));
|
|
2840
|
-
let importLoaders = 0
|
|
2841
|
-
|
|
2903
|
+
let importLoaders = 0, updateRules = (callback)=>{
|
|
2904
|
+
callback(rule, 'normal'), callback(inlineRule, 'inline');
|
|
2905
|
+
}, cssLoaderPath = getCompiledPath('css-loader');
|
|
2906
|
+
if (updateRules((rule)=>{
|
|
2907
|
+
rule.use(CHAIN_ID.USE.CSS).loader(cssLoaderPath);
|
|
2908
|
+
}), emitCss) {
|
|
2842
2909
|
var _postcssLoaderOptions_postcssOptions_plugins, _postcssLoaderOptions_postcssOptions;
|
|
2843
2910
|
if ('rspack' === api.context.bundlerType && !1 !== config.tools.lightningcssLoader) {
|
|
2844
2911
|
importLoaders++;
|
|
2845
|
-
let
|
|
2846
|
-
|
|
2912
|
+
let { minifyCss } = parseMinifyOptions(config, isProd);
|
|
2913
|
+
updateRules((rule, type)=>{
|
|
2914
|
+
let minify = ('inline' === type || config.output.injectStyles) && isProd && minifyCss, lightningcssOptions = getLightningCSSLoaderOptions(config, environment.browserslist, minify);
|
|
2915
|
+
rule.use(CHAIN_ID.USE.LIGHTNINGCSS).loader('builtin:lightningcss-loader').options(lightningcssOptions);
|
|
2916
|
+
});
|
|
2847
2917
|
}
|
|
2848
2918
|
let postcssLoaderOptions = await getPostcssLoaderOptions({
|
|
2849
2919
|
config,
|
|
2850
2920
|
root: api.context.rootPath,
|
|
2851
2921
|
postcssrcCache
|
|
2852
2922
|
});
|
|
2853
|
-
('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length))
|
|
2923
|
+
if ('function' == typeof postcssLoaderOptions.postcssOptions || (null === (_postcssLoaderOptions_postcssOptions = postcssLoaderOptions.postcssOptions) || void 0 === _postcssLoaderOptions_postcssOptions ? void 0 : null === (_postcssLoaderOptions_postcssOptions_plugins = _postcssLoaderOptions_postcssOptions.plugins) || void 0 === _postcssLoaderOptions_postcssOptions_plugins ? void 0 : _postcssLoaderOptions_postcssOptions_plugins.length)) {
|
|
2924
|
+
importLoaders++;
|
|
2925
|
+
let postcssLoaderPath = getCompiledPath('postcss-loader');
|
|
2926
|
+
updateRules((rule)=>{
|
|
2927
|
+
rule.use(CHAIN_ID.USE.POSTCSS).loader(postcssLoaderPath).options(postcssLoaderOptions);
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2854
2930
|
}
|
|
2855
2931
|
let localIdentName = getCSSModulesLocalIdentName(config, isProd), cssLoaderOptions = getCSSLoaderOptions({
|
|
2856
2932
|
config,
|
|
@@ -2858,11 +2934,15 @@ var __webpack_exports__ = {};
|
|
|
2858
2934
|
localIdentName,
|
|
2859
2935
|
emitCss
|
|
2860
2936
|
});
|
|
2861
|
-
|
|
2937
|
+
updateRules((rule, type)=>{
|
|
2938
|
+
rule.use(CHAIN_ID.USE.CSS).options('inline' === type ? {
|
|
2939
|
+
...cssLoaderOptions,
|
|
2940
|
+
exportType: 'string',
|
|
2941
|
+
modules: !1
|
|
2942
|
+
} : cssLoaderOptions), rule.sideEffects(!0), rule.resolve.preferRelative(!0);
|
|
2943
|
+
});
|
|
2862
2944
|
let isStringExport = 'string' === cssLoaderOptions.exportType;
|
|
2863
|
-
if (isStringExport && rule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT) && rule.uses.delete(CHAIN_ID.USE.MINI_CSS_EXTRACT),
|
|
2864
|
-
sideEffects: !0
|
|
2865
|
-
}), rule.resolve.preferRelative(!0), emitCss && !config.output.injectStyles && !isStringExport) {
|
|
2945
|
+
if (isStringExport && rule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT) && rule.uses.delete(CHAIN_ID.USE.MINI_CSS_EXTRACT), emitCss && !config.output.injectStyles && !isStringExport) {
|
|
2866
2946
|
let extractPluginOptions = config.tools.cssExtract.pluginOptions, cssPath = config.output.distPath.css, cssFilename = getFilename(config, 'css', isProd), isCssFilenameFn = 'function' == typeof cssFilename, cssAsyncPath = config.output.distPath.cssAsync ?? (cssPath ? `${cssPath}/async` : 'async');
|
|
2867
2947
|
chain.plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT).use(getCssExtractPlugin(), [
|
|
2868
2948
|
{
|
|
@@ -3446,19 +3526,6 @@ var __webpack_exports__ = {};
|
|
|
3446
3526
|
};
|
|
3447
3527
|
});
|
|
3448
3528
|
}
|
|
3449
|
-
}), pluginLazyCompilation = ()=>({
|
|
3450
|
-
name: 'rsbuild:lazy-compilation',
|
|
3451
|
-
setup (api) {
|
|
3452
|
-
api.modifyBundlerChain((chain, { environment, isProd, target })=>{
|
|
3453
|
-
var _config_dev;
|
|
3454
|
-
if (isProd || 'web' !== target) return;
|
|
3455
|
-
let { config } = environment, options = null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.lazyCompilation;
|
|
3456
|
-
options && chain.experiments({
|
|
3457
|
-
...chain.get('experiments'),
|
|
3458
|
-
lazyCompilation: options
|
|
3459
|
-
});
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
3529
|
});
|
|
3463
3530
|
function isAsync(chunk) {
|
|
3464
3531
|
return 'canBeInitial' in chunk ? !chunk.canBeInitial() : 'isInitial' in chunk && !chunk.isInitial();
|
|
@@ -3552,73 +3619,6 @@ var __webpack_exports__ = {};
|
|
|
3552
3619
|
]);
|
|
3553
3620
|
});
|
|
3554
3621
|
}
|
|
3555
|
-
}), getSwcMinimizerOptions = (config, jsOptions)=>{
|
|
3556
|
-
let options = {};
|
|
3557
|
-
options.minimizerOptions ||= {}, options.minimizerOptions.format ||= {};
|
|
3558
|
-
let { removeConsole } = config.performance;
|
|
3559
|
-
if (!0 === removeConsole) options.minimizerOptions.compress = {
|
|
3560
|
-
drop_console: !0
|
|
3561
|
-
};
|
|
3562
|
-
else if (Array.isArray(removeConsole)) {
|
|
3563
|
-
let pureFuncs = removeConsole.map((method)=>`console.${method}`);
|
|
3564
|
-
options.minimizerOptions.compress = {
|
|
3565
|
-
pure_funcs: pureFuncs
|
|
3566
|
-
};
|
|
3567
|
-
}
|
|
3568
|
-
switch(config.output.legalComments){
|
|
3569
|
-
case 'inline':
|
|
3570
|
-
options.minimizerOptions.format.comments = 'some', options.extractComments = !1;
|
|
3571
|
-
break;
|
|
3572
|
-
case 'linked':
|
|
3573
|
-
options.extractComments = !0;
|
|
3574
|
-
break;
|
|
3575
|
-
case 'none':
|
|
3576
|
-
options.minimizerOptions.format.comments = !1, options.extractComments = !1;
|
|
3577
|
-
}
|
|
3578
|
-
return (options.minimizerOptions.format.asciiOnly = 'ascii' === config.output.charset, jsOptions) ? cjs_default()(options, jsOptions) : options;
|
|
3579
|
-
}, parseMinifyOptions = (config, isProd)=>{
|
|
3580
|
-
let { minify } = config.output;
|
|
3581
|
-
return !1 !== minify && isProd ? !0 === minify ? {
|
|
3582
|
-
minifyJs: !0,
|
|
3583
|
-
minifyCss: !0
|
|
3584
|
-
} : {
|
|
3585
|
-
minifyJs: !1 !== minify.js,
|
|
3586
|
-
minifyCss: !1 !== minify.css,
|
|
3587
|
-
jsOptions: minify.jsOptions,
|
|
3588
|
-
cssOptions: minify.cssOptions
|
|
3589
|
-
} : {
|
|
3590
|
-
minifyJs: !1,
|
|
3591
|
-
minifyCss: !1
|
|
3592
|
-
};
|
|
3593
|
-
}, pluginMinimize = ()=>({
|
|
3594
|
-
name: 'rsbuild:minimize',
|
|
3595
|
-
setup (api) {
|
|
3596
|
-
let isRspack = 'rspack' === api.context.bundlerType;
|
|
3597
|
-
api.modifyBundlerChain(async (chain, { isProd, environment, CHAIN_ID })=>{
|
|
3598
|
-
let { config } = environment, { minifyJs, minifyCss, jsOptions, cssOptions } = parseMinifyOptions(config, isProd);
|
|
3599
|
-
if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs && isRspack && chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(core_namespaceObject.rspack.SwcJsMinimizerRspackPlugin, [
|
|
3600
|
-
getSwcMinimizerOptions(config, jsOptions)
|
|
3601
|
-
]).end(), minifyCss && isRspack) {
|
|
3602
|
-
let loaderOptions = getLightningCSSLoaderOptions(config, environment.browserslist), defaultOptions = {
|
|
3603
|
-
minimizerOptions: {
|
|
3604
|
-
targets: isPlainObject(loaderOptions.targets) ? environment.browserslist : loaderOptions.targets,
|
|
3605
|
-
...pick(loaderOptions, [
|
|
3606
|
-
'draft',
|
|
3607
|
-
'include',
|
|
3608
|
-
'exclude',
|
|
3609
|
-
'nonStandard',
|
|
3610
|
-
'pseudoClasses',
|
|
3611
|
-
'unusedSymbols',
|
|
3612
|
-
'errorRecovery'
|
|
3613
|
-
])
|
|
3614
|
-
}
|
|
3615
|
-
}, mergedOptions = cssOptions ? cjs_default()(defaultOptions, cssOptions) : defaultOptions;
|
|
3616
|
-
chain.optimization.minimizer(CHAIN_ID.MINIMIZER.CSS).use(core_namespaceObject.rspack.LightningCssMinimizerRspackPlugin, [
|
|
3617
|
-
mergedOptions
|
|
3618
|
-
]).end();
|
|
3619
|
-
}
|
|
3620
|
-
});
|
|
3621
|
-
}
|
|
3622
3622
|
});
|
|
3623
3623
|
class PatchSplitChunksPlugin {
|
|
3624
3624
|
apply(compiler) {
|
|
@@ -4045,17 +4045,14 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4045
4045
|
let { config, tsconfigPath } = environment;
|
|
4046
4046
|
chain.resolve.extensions.merge([
|
|
4047
4047
|
...config.resolve.extensions
|
|
4048
|
-
]), tsconfigPath && !tsconfigPath.endsWith('jsconfig.json') && chain.resolve.extensionAlias.
|
|
4049
|
-
'.js'
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
'.
|
|
4055
|
-
|
|
4056
|
-
'.tsx'
|
|
4057
|
-
]
|
|
4058
|
-
}), function({ chain, config, rootPath }) {
|
|
4048
|
+
]), tsconfigPath && !tsconfigPath.endsWith('jsconfig.json') && chain.resolve.extensionAlias.set('.js', [
|
|
4049
|
+
'.js',
|
|
4050
|
+
'.ts',
|
|
4051
|
+
'.tsx'
|
|
4052
|
+
]).set('.jsx', [
|
|
4053
|
+
'.jsx',
|
|
4054
|
+
'.tsx'
|
|
4055
|
+
]), function({ chain, config, rootPath }) {
|
|
4059
4056
|
let mergedAlias = reduceConfigs({
|
|
4060
4057
|
initial: {},
|
|
4061
4058
|
config: config.resolve.alias
|
|
@@ -4679,11 +4676,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
4679
4676
|
asyncWebAssembly: !0
|
|
4680
4677
|
});
|
|
4681
4678
|
let wasmFilename = external_node_path_namespaceObject.posix.join(distPath, '[hash].module.wasm');
|
|
4682
|
-
chain.output.
|
|
4683
|
-
webassemblyModuleFilename: wasmFilename
|
|
4684
|
-
}), chain.module.rule(CHAIN_ID.RULE.WASM).test(/\.wasm$/).merge({
|
|
4685
|
-
dependency: 'url'
|
|
4686
|
-
}).type('asset/resource').set('generator', {
|
|
4679
|
+
chain.output.webassemblyModuleFilename(wasmFilename), chain.module.rule(CHAIN_ID.RULE.WASM).test(/\.wasm$/).dependency('url').type('asset/resource').set('generator', {
|
|
4687
4680
|
filename: wasmFilename
|
|
4688
4681
|
});
|
|
4689
4682
|
});
|
|
@@ -5004,14 +4997,14 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5004
4997
|
}
|
|
5005
4998
|
}
|
|
5006
4999
|
async function setupWatchFiles(options) {
|
|
5007
|
-
let { dev, server, root,
|
|
5008
|
-
if (!hmr && !liveReload || !
|
|
5009
|
-
let closeDevFilesWatcher = await watchDevFiles(dev,
|
|
5000
|
+
let { dev, server, root, compilationManager } = options, { hmr, liveReload } = dev;
|
|
5001
|
+
if (!hmr && !liveReload || !compilationManager) return;
|
|
5002
|
+
let closeDevFilesWatcher = await watchDevFiles(dev, compilationManager, root), serverFilesWatcher = await function(serverConfig, compilationManager, root) {
|
|
5010
5003
|
let publicDirs = normalizePublicDirs(serverConfig.publicDir);
|
|
5011
5004
|
if (!publicDirs.length) return;
|
|
5012
5005
|
let watchPaths = publicDirs.filter((item)=>item.watch).map((item)=>item.name);
|
|
5013
|
-
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths),
|
|
5014
|
-
}(server,
|
|
5006
|
+
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), compilationManager, root);
|
|
5007
|
+
}(server, compilationManager, root);
|
|
5015
5008
|
return {
|
|
5016
5009
|
async close () {
|
|
5017
5010
|
await Promise.all([
|
|
@@ -5021,12 +5014,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5021
5014
|
}
|
|
5022
5015
|
};
|
|
5023
5016
|
}
|
|
5024
|
-
async function watchDevFiles(devConfig,
|
|
5017
|
+
async function watchDevFiles(devConfig, compilationManager, root) {
|
|
5025
5018
|
let { watchFiles } = devConfig;
|
|
5026
5019
|
if (!watchFiles) return;
|
|
5027
5020
|
let watchers = [];
|
|
5028
5021
|
for (let { paths, options, type } of castArray(watchFiles)){
|
|
5029
|
-
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions,
|
|
5022
|
+
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, compilationManager, root);
|
|
5030
5023
|
watcher && watchers.push(watcher);
|
|
5031
5024
|
}
|
|
5032
5025
|
return async ()=>{
|
|
@@ -5054,11 +5047,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5054
5047
|
}
|
|
5055
5048
|
return chokidar.watch(Array.from(watchFiles), options);
|
|
5056
5049
|
}
|
|
5057
|
-
async function startWatchFiles({ paths, options, type = 'reload-page' },
|
|
5050
|
+
async function startWatchFiles({ paths, options, type = 'reload-page' }, compilationManager, root) {
|
|
5058
5051
|
if ('reload-page' !== type) return;
|
|
5059
5052
|
let watcher = await createChokidar(paths, root, options);
|
|
5060
5053
|
return watcher.on('change', ()=>{
|
|
5061
|
-
|
|
5054
|
+
compilationManager.socketServer.sockWrite({
|
|
5055
|
+
type: 'static-changed'
|
|
5056
|
+
});
|
|
5062
5057
|
}), watcher;
|
|
5063
5058
|
}
|
|
5064
5059
|
let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
@@ -5200,37 +5195,39 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5200
5195
|
}, isNodeCompiler = (compiler)=>{
|
|
5201
5196
|
let { target } = compiler.options;
|
|
5202
5197
|
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
5203
|
-
}, setupServerHooks = (compiler,
|
|
5198
|
+
}, setupServerHooks = (compiler, { onDone, onInvalid })=>{
|
|
5204
5199
|
if (isNodeCompiler(compiler)) return;
|
|
5205
5200
|
let { compile, invalid, done } = compiler.hooks;
|
|
5206
5201
|
compile.tap('rsbuild-dev-server', ()=>{
|
|
5207
|
-
|
|
5202
|
+
onInvalid(getCompilationId(compiler));
|
|
5208
5203
|
}), invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
5209
|
-
|
|
5210
|
-
}), done.tap('rsbuild-dev-server',
|
|
5211
|
-
},
|
|
5212
|
-
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js"));
|
|
5213
|
-
return
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5204
|
+
onInvalid(getCompilationId(compiler), fileName);
|
|
5205
|
+
}), done.tap('rsbuild-dev-server', onDone);
|
|
5206
|
+
}, getCompilationMiddleware = async (compiler, options)=>{
|
|
5207
|
+
let { default: rsbuildDevMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/rsbuild-dev-middleware/index.js")), { clientPaths, callbacks, devConfig, serverConfig } = options, resolvedClientConfig = await getResolvedClientConfig(devConfig.client, serverConfig);
|
|
5208
|
+
return applyToCompiler(compiler, (compiler)=>{
|
|
5209
|
+
clientPaths && function({ compiler, clientPaths, devConfig, resolvedClientConfig }) {
|
|
5210
|
+
if (isClientCompiler(compiler)) for (let clientPath of (new compiler.webpack.DefinePlugin({
|
|
5211
|
+
RSBUILD_COMPILATION_NAME: JSON.stringify(getCompilationId(compiler)),
|
|
5212
|
+
RSBUILD_CLIENT_CONFIG: JSON.stringify(devConfig.client),
|
|
5213
|
+
RSBUILD_RESOLVED_CLIENT_CONFIG: JSON.stringify(resolvedClientConfig),
|
|
5214
|
+
RSBUILD_DEV_LIVE_RELOAD: devConfig.liveReload
|
|
5215
|
+
}).apply(compiler), clientPaths))new compiler.webpack.EntryPlugin(compiler.context, clientPath, {
|
|
5216
|
+
name: void 0
|
|
5217
|
+
}).apply(compiler);
|
|
5218
|
+
}({
|
|
5219
|
+
compiler,
|
|
5220
|
+
clientPaths,
|
|
5221
|
+
devConfig,
|
|
5222
|
+
resolvedClientConfig
|
|
5223
|
+
}), setupServerHooks(compiler, callbacks);
|
|
5224
|
+
}), rsbuildDevMiddleware(compiler, {
|
|
5225
|
+
etag: 'weak',
|
|
5226
|
+
publicPath: '/',
|
|
5227
|
+
stats: !1,
|
|
5228
|
+
serverSideRender: !0,
|
|
5229
|
+
writeToDisk: devConfig.writeToDisk
|
|
5230
|
+
});
|
|
5234
5231
|
}, external_node_querystring_namespaceObject = require("node:querystring"), styles = {
|
|
5235
5232
|
1: 'font-weight:bold',
|
|
5236
5233
|
2: 'opacity:0.5',
|
|
@@ -5277,11 +5274,6 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5277
5274
|
}) : obj[key] = value, obj;
|
|
5278
5275
|
}
|
|
5279
5276
|
class SocketServer {
|
|
5280
|
-
upgrade(req, sock, head) {
|
|
5281
|
-
this.wsServer.shouldHandle(req) && this.wsServer.handleUpgrade(req, sock, head, (connection)=>{
|
|
5282
|
-
this.wsServer.emit('connection', connection, req);
|
|
5283
|
-
});
|
|
5284
|
-
}
|
|
5285
5277
|
clearHeartbeatTimer() {
|
|
5286
5278
|
this.heartbeatTimer && (clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
5287
5279
|
}
|
|
@@ -5551,13 +5543,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5551
5543
|
1 === connection.readyState && connection.send(message);
|
|
5552
5544
|
}
|
|
5553
5545
|
constructor(options){
|
|
5554
|
-
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), 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, "
|
|
5546
|
+
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), 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, "upgrade", (req, sock, head)=>{
|
|
5547
|
+
this.wsServer.shouldHandle(req) && this.wsServer.handleUpgrade(req, sock, head, (connection)=>{
|
|
5548
|
+
this.wsServer.emit('connection', connection, req);
|
|
5549
|
+
});
|
|
5550
|
+
}), socketServer_define_property(this, "checkSockets", ()=>{
|
|
5555
5551
|
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
5556
5552
|
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000).unref());
|
|
5557
5553
|
}), this.options = options, this.stats = {}, this.initialChunks = {};
|
|
5558
5554
|
}
|
|
5559
5555
|
}
|
|
5560
|
-
function
|
|
5556
|
+
function compilationManager_define_property(obj, key, value) {
|
|
5561
5557
|
return key in obj ? Object.defineProperty(obj, key, {
|
|
5562
5558
|
value: value,
|
|
5563
5559
|
enumerable: !0,
|
|
@@ -5565,7 +5561,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5565
5561
|
writable: !0
|
|
5566
5562
|
}) : obj[key] = value, obj;
|
|
5567
5563
|
}
|
|
5568
|
-
let
|
|
5564
|
+
let compilationManager_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), formatDevConfig = (config, environments)=>{
|
|
5569
5565
|
let writeToDiskValues = Object.values(environments).map((env)=>env.config.dev.writeToDisk);
|
|
5570
5566
|
return 1 === new Set(writeToDiskValues).size ? {
|
|
5571
5567
|
...config,
|
|
@@ -5578,13 +5574,11 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5578
5574
|
}
|
|
5579
5575
|
};
|
|
5580
5576
|
};
|
|
5581
|
-
class
|
|
5577
|
+
class CompilationManager {
|
|
5582
5578
|
async init() {
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
upgrade(req, sock, head) {
|
|
5587
|
-
this.socketServer.upgrade(req, sock, head);
|
|
5579
|
+
await this.setupCompilationMiddleware(), await this.socketServer.prepare();
|
|
5580
|
+
let { compiler } = this;
|
|
5581
|
+
this.outputFileSystem = (helpers_isMultiCompiler(compiler) ? compiler.compilers[0].outputFileSystem : compiler.outputFileSystem) || external_node_fs_default();
|
|
5588
5582
|
}
|
|
5589
5583
|
async close() {
|
|
5590
5584
|
await this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
|
|
@@ -5597,21 +5591,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5597
5591
|
});
|
|
5598
5592
|
});
|
|
5599
5593
|
}
|
|
5600
|
-
|
|
5601
|
-
this
|
|
5602
|
-
type,
|
|
5603
|
-
data
|
|
5604
|
-
});
|
|
5605
|
-
}
|
|
5606
|
-
async setupDevMiddleware(devMiddleware, publicPaths) {
|
|
5607
|
-
let { devConfig, serverConfig } = this, { headers, base } = serverConfig, clientPaths = function(devConfig) {
|
|
5594
|
+
async setupCompilationMiddleware() {
|
|
5595
|
+
let { devConfig, serverConfig, publicPaths } = this, clientPaths = function(devConfig) {
|
|
5608
5596
|
var _devConfig_client;
|
|
5609
5597
|
let clientPaths = [];
|
|
5610
|
-
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(
|
|
5611
|
-
}(devConfig), middleware = await
|
|
5612
|
-
headers,
|
|
5613
|
-
publicPath: '/',
|
|
5614
|
-
stats: !1,
|
|
5598
|
+
return (devConfig.hmr || devConfig.liveReload) && (clientPaths.push(compilationManager_require.resolve('@rsbuild/core/client/hmr')), (null === (_devConfig_client = devConfig.client) || void 0 === _devConfig_client ? void 0 : _devConfig_client.overlay) && clientPaths.push(`${compilationManager_require.resolve('@rsbuild/core/client/overlay')}`)), clientPaths;
|
|
5599
|
+
}(devConfig), middleware = await getCompilationMiddleware(this.compiler, {
|
|
5615
5600
|
callbacks: {
|
|
5616
5601
|
onInvalid: (compilationId, fileName)=>{
|
|
5617
5602
|
if ('string' == typeof fileName && HTML_REGEX.test(fileName)) {
|
|
@@ -5630,307 +5615,46 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5630
5615
|
this.socketServer.updateStats(stats);
|
|
5631
5616
|
}
|
|
5632
5617
|
},
|
|
5633
|
-
clientPaths
|
|
5634
|
-
|
|
5635
|
-
liveReload: devConfig.liveReload,
|
|
5636
|
-
writeToDisk: devConfig.writeToDisk,
|
|
5637
|
-
serverSideRender: !0,
|
|
5638
|
-
etag: 'weak',
|
|
5618
|
+
clientPaths,
|
|
5619
|
+
devConfig,
|
|
5639
5620
|
serverConfig
|
|
5640
|
-
}), assetPrefixes = publicPaths.map(pathnameParse).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
5621
|
+
}), { base } = serverConfig, assetPrefixes = publicPaths.map(pathnameParse).map((prefix)=>base && '/' !== base ? stripBase(prefix, base) : prefix), wrapper = async (req, res, next)=>{
|
|
5641
5622
|
let { url } = req, assetPrefix = url && assetPrefixes.find((prefix)=>url.startsWith(prefix));
|
|
5642
5623
|
assetPrefix && '/' !== assetPrefix ? (req.url = url.slice(assetPrefix.length - 1), middleware(req, res, (...args)=>{
|
|
5643
5624
|
req.url = url, next(...args);
|
|
5644
5625
|
})) : middleware(req, res, next);
|
|
5645
5626
|
};
|
|
5646
|
-
|
|
5627
|
+
wrapper.close = middleware.close, this.middleware = wrapper;
|
|
5647
5628
|
}
|
|
5648
5629
|
constructor({ dev, server, compiler, publicPaths, environments }){
|
|
5649
|
-
|
|
5630
|
+
compilationManager_define_property(this, "middleware", void 0), compilationManager_define_property(this, "outputFileSystem", void 0), compilationManager_define_property(this, "devConfig", void 0), compilationManager_define_property(this, "serverConfig", void 0), compilationManager_define_property(this, "compiler", void 0), compilationManager_define_property(this, "publicPaths", void 0), compilationManager_define_property(this, "socketServer", void 0), compilationManager_define_property(this, "readFileSync", (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : external_node_fs_default().readFileSync(fileName, 'utf-8')), this.devConfig = formatDevConfig(dev, environments), this.serverConfig = server, this.compiler = compiler, this.publicPaths = publicPaths, this.outputFileSystem = external_node_fs_default(), this.socketServer = new SocketServer(dev);
|
|
5650
5631
|
}
|
|
5651
5632
|
}
|
|
5652
|
-
let
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
if (
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
].map((name)=>`const _${name} = ${SYNTHETIC_MODULES_STORE}[${i}]${'default' === name ? '' : `[${JSON.stringify(name)}]`}; export { _${name} as ${name}};`).join('\n'), m = new (external_node_vm_default()).SourceTextModule(code, {
|
|
5665
|
-
context
|
|
5666
|
-
});
|
|
5667
|
-
return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
|
|
5668
|
-
};
|
|
5669
|
-
function basic_define_property(obj, key, value) {
|
|
5670
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
5671
|
-
value: value,
|
|
5672
|
-
enumerable: !0,
|
|
5673
|
-
configurable: !0,
|
|
5674
|
-
writable: !0
|
|
5675
|
-
}) : obj[key] = value, obj;
|
|
5676
|
-
}
|
|
5677
|
-
let isRelativePath = (p)=>/^\.\.?\//.test(p), getSubPath = (p)=>{
|
|
5678
|
-
let lastSlash = p.lastIndexOf('/'), firstSlash = p.indexOf('/');
|
|
5679
|
-
if (-1 !== lastSlash && firstSlash !== lastSlash) {
|
|
5680
|
-
if (-1 !== firstSlash) {
|
|
5681
|
-
let next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5682
|
-
for(; '.' === dir;)firstSlash = next, next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5633
|
+
let ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, shouldCompress = (res)=>{
|
|
5634
|
+
if (res.getHeader('Content-Encoding')) return !1;
|
|
5635
|
+
let contentType = String(res.getHeader('Content-Type'));
|
|
5636
|
+
if (contentType && !CONTENT_TYPE_REGEX.test(contentType)) return !1;
|
|
5637
|
+
let size = res.getHeader('Content-Length');
|
|
5638
|
+
return void 0 === size || Number(size) > 1024;
|
|
5639
|
+
}, gzipMiddleware = ({ level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
5640
|
+
let gzip, writeHeadStatus;
|
|
5641
|
+
let accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
|
|
5642
|
+
if ('HEAD' === req.method || !encoding) {
|
|
5643
|
+
next();
|
|
5644
|
+
return;
|
|
5683
5645
|
}
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
return (currentDirectory, modulePath, context = {})=>entryRequire(currentDirectory, Array.isArray(modulePath) ? modulePath : modulePath.split('?')[0], context);
|
|
5697
|
-
}
|
|
5698
|
-
getFile(modulePath, currentDirectory) {
|
|
5699
|
-
if (Array.isArray(modulePath)) return {
|
|
5700
|
-
path: external_node_path_default().join(currentDirectory, '.array-require.js'),
|
|
5701
|
-
content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
|
|
5702
|
-
subPath: ''
|
|
5703
|
-
};
|
|
5704
|
-
let joinedPath = isRelativePath(modulePath) ? external_node_path_default().join(currentDirectory, modulePath) : modulePath;
|
|
5705
|
-
return this._options.isBundleOutput(joinedPath) ? {
|
|
5706
|
-
path: joinedPath,
|
|
5707
|
-
content: this._options.readFileSync(joinedPath),
|
|
5708
|
-
subPath: getSubPath(modulePath)
|
|
5709
|
-
} : null;
|
|
5710
|
-
}
|
|
5711
|
-
preExecute(_code, _file) {}
|
|
5712
|
-
postExecute(_m, _file) {}
|
|
5713
|
-
createRunner() {
|
|
5714
|
-
this.requirers.set('entry', (_currentDirectory, _modulePath, _context = {})=>{
|
|
5715
|
-
throw Error('[rsbuild:runner] Not implement');
|
|
5716
|
-
});
|
|
5717
|
-
}
|
|
5718
|
-
constructor(_options){
|
|
5719
|
-
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();
|
|
5720
|
-
}
|
|
5721
|
-
}
|
|
5722
|
-
let cjs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), cjs_define = (...args)=>{
|
|
5723
|
-
args.pop()();
|
|
5724
|
-
};
|
|
5725
|
-
class CommonJsRunner extends BasicRunner {
|
|
5726
|
-
createGlobalContext() {
|
|
5727
|
-
return {
|
|
5728
|
-
console: console,
|
|
5729
|
-
setTimeout: (cb, ms, ...args)=>{
|
|
5730
|
-
let timeout = setTimeout(cb, ms, ...args);
|
|
5731
|
-
return timeout.unref(), timeout;
|
|
5732
|
-
},
|
|
5733
|
-
clearTimeout: clearTimeout,
|
|
5734
|
-
queueMicrotask
|
|
5735
|
-
};
|
|
5736
|
-
}
|
|
5737
|
-
createBaseModuleScope() {
|
|
5738
|
-
return {
|
|
5739
|
-
console: this.globalContext.console,
|
|
5740
|
-
setTimeout: this.globalContext.setTimeout,
|
|
5741
|
-
clearTimeout: this.globalContext.clearTimeout,
|
|
5742
|
-
nsObj: (m)=>(Object.defineProperty(m, Symbol.toStringTag, {
|
|
5743
|
-
value: 'Module'
|
|
5744
|
-
}), m),
|
|
5745
|
-
queueMicrotask
|
|
5746
|
-
};
|
|
5747
|
-
}
|
|
5748
|
-
createModuleScope(requireFn, m, file) {
|
|
5749
|
-
return {
|
|
5750
|
-
...this.baseModuleScope,
|
|
5751
|
-
require: requireFn.bind(null, external_node_path_default().dirname(file.path)),
|
|
5752
|
-
module: m,
|
|
5753
|
-
exports: m.exports,
|
|
5754
|
-
__dirname: external_node_path_default().dirname(file.path),
|
|
5755
|
-
__filename: file.path,
|
|
5756
|
-
define: cjs_define
|
|
5757
|
-
};
|
|
5758
|
-
}
|
|
5759
|
-
createRunner() {
|
|
5760
|
-
this.requirers.set('miss', this.createMissRequirer()), this.requirers.set('entry', this.createCjsRequirer());
|
|
5761
|
-
}
|
|
5762
|
-
createMissRequirer() {
|
|
5763
|
-
return (_currentDirectory, modulePath, _context = {})=>{
|
|
5764
|
-
let resolvedPath = cjs_require.resolve(modulePath, {
|
|
5765
|
-
paths: [
|
|
5766
|
-
_currentDirectory
|
|
5767
|
-
]
|
|
5768
|
-
});
|
|
5769
|
-
return cjs_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
|
|
5770
|
-
};
|
|
5771
|
-
}
|
|
5772
|
-
createCjsRequirer() {
|
|
5773
|
-
let requireCache = Object.create(null);
|
|
5774
|
-
return (currentDirectory, modulePath, context = {})=>{
|
|
5775
|
-
let file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5776
|
-
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5777
|
-
if (file.path in requireCache) return requireCache[file.path].exports;
|
|
5778
|
-
let m = {
|
|
5779
|
-
exports: {}
|
|
5780
|
-
};
|
|
5781
|
-
requireCache[file.path] = m;
|
|
5782
|
-
let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
|
|
5783
|
-
${file.content}
|
|
5784
|
-
})`;
|
|
5785
|
-
this.preExecute(code, file);
|
|
5786
|
-
let dynamicImport = Function('specifier', 'return import(specifier)');
|
|
5787
|
-
return external_node_vm_default().runInThisContext(code, {
|
|
5788
|
-
filename: file.path,
|
|
5789
|
-
importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
|
|
5790
|
-
}).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
|
|
5791
|
-
};
|
|
5792
|
-
}
|
|
5793
|
-
}
|
|
5794
|
-
var type_EsmMode = function(EsmMode) {
|
|
5795
|
-
return EsmMode[EsmMode.Unknown = 0] = "Unknown", EsmMode[EsmMode.Evaluated = 1] = "Evaluated", EsmMode[EsmMode.Unlinked = 2] = "Unlinked", EsmMode;
|
|
5796
|
-
}({});
|
|
5797
|
-
class EsmRunner extends CommonJsRunner {
|
|
5798
|
-
createRunner() {
|
|
5799
|
-
var _this__options_compilerOptions_experiments;
|
|
5800
|
-
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
5801
|
-
let outputModule = null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule;
|
|
5802
|
-
this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
|
|
5803
|
-
let file = this.getFile(modulePath, currentDirectory);
|
|
5804
|
-
return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
5805
|
-
...context,
|
|
5806
|
-
file
|
|
5807
|
-
}) : this.requirers.get('cjs')(currentDirectory, modulePath, {
|
|
5808
|
-
...context,
|
|
5809
|
-
file
|
|
5810
|
-
}) : this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5811
|
-
});
|
|
5812
|
-
}
|
|
5813
|
-
createEsmRequirer() {
|
|
5814
|
-
let esmContext = external_node_vm_default().createContext(this.baseModuleScope, {
|
|
5815
|
-
name: 'context for esm'
|
|
5816
|
-
}), esmCache = new Map(), esmIdentifier = this._options.name;
|
|
5817
|
-
return (currentDirectory, modulePath, context = {})=>{
|
|
5818
|
-
if (!external_node_vm_default().SourceTextModule) throw Error('[rsbuild:runner] Running ESM bundle needs add Node.js option "--experimental-vm-modules".');
|
|
5819
|
-
let _require = this.getRequire(), file = context.file || this.getFile(modulePath, currentDirectory);
|
|
5820
|
-
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
5821
|
-
let esm = esmCache.get(file.path);
|
|
5822
|
-
return (esm || (esm = new (external_node_vm_default()).SourceTextModule(file.content, {
|
|
5823
|
-
identifier: `${esmIdentifier}-${file.path}`,
|
|
5824
|
-
url: `${(0, external_node_url_namespaceObject.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
5825
|
-
context: esmContext,
|
|
5826
|
-
initializeImportMeta: (meta, _)=>{
|
|
5827
|
-
meta.url = (0, external_node_url_namespaceObject.pathToFileURL)(file.path).href;
|
|
5828
|
-
},
|
|
5829
|
-
importModuleDynamically: async (specifier, module)=>{
|
|
5830
|
-
let result = await _require(external_node_path_default().dirname(file.path), specifier, {
|
|
5831
|
-
esmMode: type_EsmMode.Evaluated
|
|
5832
|
-
});
|
|
5833
|
-
return await asModule(result, module.context);
|
|
5834
|
-
}
|
|
5835
|
-
}), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
|
|
5836
|
-
if (await esm.link(async (specifier, referencingModule)=>await asModule(await _require(external_node_path_default().dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, external_node_url_namespaceObject.fileURLToPath)(referencingModule.url)), specifier, {
|
|
5837
|
-
esmMode: type_EsmMode.Unlinked
|
|
5838
|
-
}), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
|
|
5839
|
-
let ns = esm.namespace;
|
|
5840
|
-
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
5841
|
-
})();
|
|
5842
|
-
};
|
|
5843
|
-
}
|
|
5844
|
-
}
|
|
5845
|
-
class BasicRunnerFactory {
|
|
5846
|
-
create(options) {
|
|
5847
|
-
return this.createRunner(options);
|
|
5848
|
-
}
|
|
5849
|
-
createRunner(options) {
|
|
5850
|
-
let runnerOptions = {
|
|
5851
|
-
name: this.name,
|
|
5852
|
-
...options
|
|
5853
|
-
}, { compilerOptions } = options;
|
|
5854
|
-
if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`[rsbuild:runner] Not support run "${compilerOptions.target}" resource in Rsbuild server`);
|
|
5855
|
-
return new EsmRunner(runnerOptions);
|
|
5856
|
-
}
|
|
5857
|
-
constructor(name){
|
|
5858
|
-
!function(obj, key, value) {
|
|
5859
|
-
key in obj ? Object.defineProperty(obj, key, {
|
|
5860
|
-
value: value,
|
|
5861
|
-
enumerable: !0,
|
|
5862
|
-
configurable: !0,
|
|
5863
|
-
writable: !0
|
|
5864
|
-
}) : obj[key] = value;
|
|
5865
|
-
}(this, "name", void 0), this.name = name;
|
|
5866
|
-
}
|
|
5867
|
-
}
|
|
5868
|
-
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
|
|
5869
|
-
let { chunks, entrypoints, outputPath } = stats.toJson({
|
|
5870
|
-
all: !1,
|
|
5871
|
-
chunks: !0,
|
|
5872
|
-
entrypoints: !0,
|
|
5873
|
-
outputPath: !0
|
|
5874
|
-
});
|
|
5875
|
-
if (!(null == entrypoints ? void 0 : entrypoints[entryName])) throw Error(`[rsbuild:loadBundle] Can't find entry: "${entryName}"`);
|
|
5876
|
-
let { chunks: entryChunks = [] } = entrypoints[entryName], files = entryChunks.reduce((prev, entryChunkName)=>{
|
|
5877
|
-
let chunk = null == chunks ? void 0 : chunks.find((chunk)=>{
|
|
5878
|
-
var _chunk_names;
|
|
5879
|
-
return chunk.entry && (null === (_chunk_names = chunk.names) || void 0 === _chunk_names ? void 0 : _chunk_names.includes(String(entryChunkName)));
|
|
5880
|
-
});
|
|
5881
|
-
return (null == chunk ? void 0 : chunk.files) ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
5882
|
-
}, []);
|
|
5883
|
-
if (0 === files.length) throw Error(`[rsbuild:loadBundle] Failed to get bundle by entryName: "${entryName}"`);
|
|
5884
|
-
if (files.length > 1) throw Error(`[rsbuild:loadBundle] Only support load single entry chunk, but got ${files.length}: ${files.join(',')}`);
|
|
5885
|
-
let allChunkFiles = (null == chunks ? void 0 : chunks.flatMap((c)=>c.files).map((file)=>(0, external_node_path_namespaceObject.join)(outputPath, file))) || [];
|
|
5886
|
-
return await runner_run({
|
|
5887
|
-
bundlePath: files[0],
|
|
5888
|
-
dist: outputPath,
|
|
5889
|
-
compilerOptions: stats.compilation.options,
|
|
5890
|
-
readFileSync: utils.readFileSync,
|
|
5891
|
-
isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
|
|
5892
|
-
});
|
|
5893
|
-
}, getTransformedHtml = async (entryName, utils)=>{
|
|
5894
|
-
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
5895
|
-
if (!htmlPath) throw Error(`[rsbuild:getTransformedHtml] Failed to get HTML file by entryName: "${entryName}"`);
|
|
5896
|
-
let fileName = (0, external_node_path_namespaceObject.join)(distPath, htmlPath);
|
|
5897
|
-
return utils.readFileSync(fileName);
|
|
5898
|
-
}, createCacheableFunction = (getter)=>{
|
|
5899
|
-
let cache = new WeakMap();
|
|
5900
|
-
return async (stats, entryName, utils)=>{
|
|
5901
|
-
let cachedEntries = cache.get(stats);
|
|
5902
|
-
if (null == cachedEntries ? void 0 : cachedEntries[entryName]) return cachedEntries[entryName];
|
|
5903
|
-
let res = await getter(stats, entryName, utils);
|
|
5904
|
-
return cache.set(stats, {
|
|
5905
|
-
...cachedEntries || {},
|
|
5906
|
-
[entryName]: res
|
|
5907
|
-
}), res;
|
|
5908
|
-
};
|
|
5909
|
-
}, ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i, shouldCompress = (res)=>{
|
|
5910
|
-
if (res.getHeader('Content-Encoding')) return !1;
|
|
5911
|
-
let contentType = String(res.getHeader('Content-Type'));
|
|
5912
|
-
if (contentType && !CONTENT_TYPE_REGEX.test(contentType)) return !1;
|
|
5913
|
-
let size = res.getHeader('Content-Length');
|
|
5914
|
-
return void 0 === size || Number(size) > 1024;
|
|
5915
|
-
}, gzipMiddleware = ({ level = external_node_zlib_default().constants.Z_BEST_SPEED } = {})=>(req, res, next)=>{
|
|
5916
|
-
let gzip, writeHeadStatus;
|
|
5917
|
-
let accept = req.headers['accept-encoding'], encoding = 'string' == typeof accept && ENCODING_REGEX.test(accept);
|
|
5918
|
-
if ('HEAD' === req.method || !encoding) {
|
|
5919
|
-
next();
|
|
5920
|
-
return;
|
|
5921
|
-
}
|
|
5922
|
-
let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
|
|
5923
|
-
if (!started) {
|
|
5924
|
-
if (started = !0, shouldCompress(res)) for (let listener of (res.setHeader('Content-Encoding', 'gzip'), res.removeHeader('Content-Length'), (gzip = external_node_zlib_default().createGzip({
|
|
5925
|
-
level
|
|
5926
|
-
})).on('data', (chunk)=>{
|
|
5927
|
-
!1 === write.call(res, chunk) && gzip.pause();
|
|
5928
|
-
}), on.call(res, 'drain', ()=>gzip.resume()), gzip.on('end', ()=>{
|
|
5929
|
-
end.call(res);
|
|
5930
|
-
}), listeners))gzip.on.apply(gzip, listener);
|
|
5931
|
-
else for (let listener of listeners)on.apply(res, listener);
|
|
5932
|
-
writeHead.call(res, writeHeadStatus ?? res.statusCode);
|
|
5933
|
-
}
|
|
5646
|
+
let started = !1, { end, write, on, writeHead } = res, listeners = [], start = ()=>{
|
|
5647
|
+
if (!started) {
|
|
5648
|
+
if (started = !0, shouldCompress(res)) for (let listener of (res.setHeader('Content-Encoding', 'gzip'), res.removeHeader('Content-Length'), (gzip = external_node_zlib_default().createGzip({
|
|
5649
|
+
level
|
|
5650
|
+
})).on('data', (chunk)=>{
|
|
5651
|
+
!1 === write.call(res, chunk) && gzip.pause();
|
|
5652
|
+
}), on.call(res, 'drain', ()=>gzip.resume()), gzip.on('end', ()=>{
|
|
5653
|
+
end.call(res);
|
|
5654
|
+
}), listeners))gzip.on.apply(gzip, listener);
|
|
5655
|
+
else for (let listener of listeners)on.apply(res, listener);
|
|
5656
|
+
writeHead.call(res, writeHeadStatus ?? res.statusCode);
|
|
5657
|
+
}
|
|
5934
5658
|
};
|
|
5935
5659
|
res.writeHead = (status, reason, headers)=>{
|
|
5936
5660
|
if (reason) for (let [key, value] of Object.entries(headers || reason))res.setHeader(key, value);
|
|
@@ -5966,17 +5690,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5966
5690
|
if (!req.url || !req.headers || 'GET' !== req.method && 'HEAD' !== req.method) return !1;
|
|
5967
5691
|
let { accept } = req.headers;
|
|
5968
5692
|
return 'string' == typeof accept && (accept.includes('text/html') || accept.includes('*/*'));
|
|
5969
|
-
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getHtmlCompletionMiddleware = ({ distPath,
|
|
5693
|
+
}, postfixRE = /[?#].*$/, getUrlPathname = (url)=>url.replace(postfixRE, ''), getHtmlCompletionMiddleware = ({ distPath, compilationManager })=>async (req, res, next)=>{
|
|
5970
5694
|
if (!maybeHTMLRequest(req)) return next();
|
|
5971
|
-
let pathname = getUrlPathname(req.url), rewrite = (newUrl)=>(req.url = newUrl,
|
|
5695
|
+
let pathname = getUrlPathname(req.url), rewrite = (newUrl)=>(req.url = newUrl, compilationManager.middleware(req, res, (...args)=>{
|
|
5972
5696
|
next(...args);
|
|
5973
5697
|
}));
|
|
5974
5698
|
if (pathname.endsWith('/')) {
|
|
5975
5699
|
let newUrl = `${pathname}index.html`, filePath = external_node_path_default().join(distPath, newUrl);
|
|
5976
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) return rewrite(newUrl);
|
|
5700
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return rewrite(newUrl);
|
|
5977
5701
|
} else if (!external_node_path_default().extname(pathname)) {
|
|
5978
5702
|
let newUrl = `${pathname}.html`, filePath = external_node_path_default().join(distPath, newUrl);
|
|
5979
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) return rewrite(newUrl);
|
|
5703
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) return rewrite(newUrl);
|
|
5980
5704
|
}
|
|
5981
5705
|
next();
|
|
5982
5706
|
}, getBaseMiddleware = ({ base })=>async (req, res, next)=>{
|
|
@@ -5999,12 +5723,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
5999
5723
|
res.writeHead(404, {
|
|
6000
5724
|
'Content-Type': 'text/plain'
|
|
6001
5725
|
}), res.end(`The server is configured with a base URL of ${base} - did you mean to visit ${redirectPath} instead?`);
|
|
6002
|
-
}, getHtmlFallbackMiddleware = ({ htmlFallback, distPath,
|
|
5726
|
+
}, getHtmlFallbackMiddleware = ({ htmlFallback, distPath, compilationManager })=>async (req, res, next)=>{
|
|
6003
5727
|
if (!maybeHTMLRequest(req) || '/favicon.ico' === req.url || 'index' !== htmlFallback) return next();
|
|
6004
5728
|
let filePath = external_node_path_default().join(distPath, 'index.html');
|
|
6005
|
-
if (await middlewares_isFileExists(filePath, outputFileSystem)) {
|
|
5729
|
+
if (await middlewares_isFileExists(filePath, compilationManager.outputFileSystem)) {
|
|
6006
5730
|
let newUrl = '/index.html';
|
|
6007
|
-
return 'verbose' === rslog_index_js_namespaceObject.logger.level && rslog_index_js_namespaceObject.logger.debug(`${req.method} ${index_js_default().gray(`${req.url} ${index_js_default().yellow('fallback')} to ${newUrl}`)}`), req.url = newUrl,
|
|
5731
|
+
return 'verbose' === rslog_index_js_namespaceObject.logger.level && rslog_index_js_namespaceObject.logger.debug(`${req.method} ${index_js_default().gray(`${req.url} ${index_js_default().yellow('fallback')} to ${newUrl}`)}`), req.url = newUrl, compilationManager.middleware(req, res, (...args)=>next(...args));
|
|
6008
5732
|
}
|
|
6009
5733
|
next();
|
|
6010
5734
|
}, viewingServedFilesMiddleware = ({ environments })=>async (req, res, next)=>{
|
|
@@ -6096,9 +5820,12 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6096
5820
|
for (let middleware of proxyMiddlewares)'function' == typeof middleware.upgrade && middleware.upgrade(req, socket, head);
|
|
6097
5821
|
}
|
|
6098
5822
|
};
|
|
6099
|
-
}, applySetupMiddlewares = (dev, environments,
|
|
5823
|
+
}, applySetupMiddlewares = (dev, environments, compilationManager)=>{
|
|
6100
5824
|
let setupMiddlewares = dev.setupMiddlewares || [], serverOptions = {
|
|
6101
|
-
sockWrite: (type, data)=>null ==
|
|
5825
|
+
sockWrite: (type, data)=>null == compilationManager ? void 0 : compilationManager.socketServer.sockWrite({
|
|
5826
|
+
type,
|
|
5827
|
+
data
|
|
5828
|
+
}),
|
|
6102
5829
|
environments
|
|
6103
5830
|
}, before = [], after = [];
|
|
6104
5831
|
for (let handler of setupMiddlewares)handler({
|
|
@@ -6109,13 +5836,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6109
5836
|
before,
|
|
6110
5837
|
after
|
|
6111
5838
|
};
|
|
6112
|
-
}, applyDefaultMiddlewares = async ({ middlewares, server,
|
|
5839
|
+
}, applyDefaultMiddlewares = async ({ dev, middlewares, server, compilationManager, context, pwd, environments, postCallbacks })=>{
|
|
6113
5840
|
let upgradeEvents = [];
|
|
6114
|
-
if (server.compress && middlewares.push(gzipMiddleware()), middlewares.push((
|
|
6115
|
-
var _parseUrl;
|
|
6116
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
6117
|
-
let path = req.url ? null === (_parseUrl = parseUrl(req.url)) || void 0 === _parseUrl ? void 0 : _parseUrl.pathname : '';
|
|
6118
|
-
(null == path ? void 0 : path.includes('hot-update')) && res.setHeader('Access-Control-Allow-Credentials', 'false');
|
|
5841
|
+
if (server.compress && middlewares.push(gzipMiddleware()), middlewares.push((_req, res, next)=>{
|
|
6119
5842
|
let confHeaders = server.headers;
|
|
6120
5843
|
if (confHeaders) for (let [key, value] of Object.entries(confHeaders))res.setHeader(key, value);
|
|
6121
5844
|
next();
|
|
@@ -6123,6 +5846,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6123
5846
|
let { default: corsMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/cors/index.js"));
|
|
6124
5847
|
middlewares.push(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
6125
5848
|
}
|
|
5849
|
+
if ('dev' === context.action && 'rspack' === context.bundlerType && dev.lazyCompilation && compilationManager) {
|
|
5850
|
+
let { compiler } = compilationManager;
|
|
5851
|
+
middlewares.push(core_default().experiments.lazyCompilationMiddleware(helpers_isMultiCompiler(compiler) ? compiler.compilers[0] : compiler, dev.lazyCompilation));
|
|
5852
|
+
}
|
|
6126
5853
|
if (server.proxy) {
|
|
6127
5854
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy);
|
|
6128
5855
|
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.push(middleware);
|
|
@@ -6131,20 +5858,17 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6131
5858
|
base: server.base
|
|
6132
5859
|
}));
|
|
6133
5860
|
let { default: launchEditorMiddleware } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/launch-editor-middleware/index.js"));
|
|
6134
|
-
middlewares.push([
|
|
5861
|
+
for (let publicDir of (middlewares.push([
|
|
6135
5862
|
'/__open-in-editor',
|
|
6136
5863
|
launchEditorMiddleware()
|
|
6137
5864
|
]), middlewares.push(viewingServedFilesMiddleware({
|
|
6138
5865
|
environments
|
|
6139
|
-
})),
|
|
5866
|
+
})), compilationManager && (middlewares.push(compilationManager.middleware), upgradeEvents.push(compilationManager.socketServer.upgrade), middlewares.push((req, res, next)=>{
|
|
6140
5867
|
var _req_url;
|
|
6141
5868
|
(null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.endsWith('.hot-update.json')) && 'OPTIONS' !== req.method ? (res.statusCode = 404, res.end()) : next();
|
|
6142
|
-
}))
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
distPath,
|
|
6146
|
-
callback: compileMiddlewareAPI.middleware,
|
|
6147
|
-
outputFileSystem
|
|
5869
|
+
})), compilationManager && middlewares.push(getHtmlCompletionMiddleware({
|
|
5870
|
+
compilationManager,
|
|
5871
|
+
distPath: context.distPath
|
|
6148
5872
|
})), normalizePublicDirs(null == server ? void 0 : server.publicDir))){
|
|
6149
5873
|
let { default: sirv } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/sirv/index.js")), { name } = publicDir, assetMiddleware = sirv((0, external_node_path_namespaceObject.isAbsolute)(name) ? name : (0, external_node_path_namespaceObject.join)(pwd, name), {
|
|
6150
5874
|
etag: !0,
|
|
@@ -6153,24 +5877,23 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6153
5877
|
middlewares.push(assetMiddleware);
|
|
6154
5878
|
}
|
|
6155
5879
|
for (let callback of postCallbacks)callback();
|
|
6156
|
-
if (
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
htmlFallback: server.htmlFallback
|
|
6160
|
-
outputFileSystem
|
|
5880
|
+
if (compilationManager && middlewares.push(getHtmlFallbackMiddleware({
|
|
5881
|
+
compilationManager,
|
|
5882
|
+
distPath: context.distPath,
|
|
5883
|
+
htmlFallback: server.htmlFallback
|
|
6161
5884
|
})), server.historyApiFallback) {
|
|
6162
5885
|
let { default: connectHistoryApiFallback } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect-history-api-fallback/index.js")), historyApiFallbackMiddleware = connectHistoryApiFallback(!0 === server.historyApiFallback ? {} : server.historyApiFallback);
|
|
6163
|
-
middlewares.push(historyApiFallbackMiddleware), (null ==
|
|
5886
|
+
middlewares.push(historyApiFallbackMiddleware), (null == compilationManager ? void 0 : compilationManager.middleware) && middlewares.push(compilationManager.middleware);
|
|
6164
5887
|
}
|
|
6165
5888
|
return middlewares.push(faviconFallbackMiddleware), {
|
|
6166
5889
|
onUpgrade: (...args)=>{
|
|
6167
5890
|
for (let cb of upgradeEvents)cb(...args);
|
|
6168
5891
|
}
|
|
6169
5892
|
};
|
|
6170
|
-
},
|
|
6171
|
-
let middlewares = [], { environments,
|
|
5893
|
+
}, getDevMiddlewares = async (options)=>{
|
|
5894
|
+
let middlewares = [], { environments, compilationManager } = options;
|
|
6172
5895
|
'verbose' === rslog_index_js_namespaceObject.logger.level && middlewares.push(await getRequestLoggerMiddleware());
|
|
6173
|
-
let { before, after } = applySetupMiddlewares(options.dev, environments,
|
|
5896
|
+
let { before, after } = applySetupMiddlewares(options.dev, environments, compilationManager);
|
|
6174
5897
|
middlewares.push(...before);
|
|
6175
5898
|
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
6176
5899
|
...options,
|
|
@@ -6178,11 +5901,268 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6178
5901
|
});
|
|
6179
5902
|
return middlewares.push(...after), {
|
|
6180
5903
|
close: async ()=>{
|
|
6181
|
-
await (null ==
|
|
5904
|
+
await (null == compilationManager ? void 0 : compilationManager.close());
|
|
6182
5905
|
},
|
|
6183
5906
|
onUpgrade,
|
|
6184
5907
|
middlewares
|
|
6185
5908
|
};
|
|
5909
|
+
}, external_node_vm_namespaceObject = require("node:vm");
|
|
5910
|
+
var external_node_vm_default = __webpack_require__.n(external_node_vm_namespaceObject);
|
|
5911
|
+
let SYNTHETIC_MODULES_STORE = '__SYNTHETIC_MODULES_STORE', asModule = async (something, context, unlinked)=>{
|
|
5912
|
+
if (something instanceof external_node_vm_default().Module) return something;
|
|
5913
|
+
context[SYNTHETIC_MODULES_STORE] = context[SYNTHETIC_MODULES_STORE] || [];
|
|
5914
|
+
let i = context[SYNTHETIC_MODULES_STORE].length;
|
|
5915
|
+
context[SYNTHETIC_MODULES_STORE].push(something);
|
|
5916
|
+
let code = [
|
|
5917
|
+
...new Set([
|
|
5918
|
+
'default',
|
|
5919
|
+
...Object.keys(something)
|
|
5920
|
+
])
|
|
5921
|
+
].map((name)=>`const _${name} = ${SYNTHETIC_MODULES_STORE}[${i}]${'default' === name ? '' : `[${JSON.stringify(name)}]`}; export { _${name} as ${name}};`).join('\n'), m = new (external_node_vm_default()).SourceTextModule(code, {
|
|
5922
|
+
context
|
|
5923
|
+
});
|
|
5924
|
+
return unlinked || (await m.link(()=>{}), m.instantiate && m.instantiate(), await m.evaluate()), m;
|
|
5925
|
+
};
|
|
5926
|
+
function basic_define_property(obj, key, value) {
|
|
5927
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
5928
|
+
value: value,
|
|
5929
|
+
enumerable: !0,
|
|
5930
|
+
configurable: !0,
|
|
5931
|
+
writable: !0
|
|
5932
|
+
}) : obj[key] = value, obj;
|
|
5933
|
+
}
|
|
5934
|
+
let isRelativePath = (p)=>/^\.\.?\//.test(p), getSubPath = (p)=>{
|
|
5935
|
+
let lastSlash = p.lastIndexOf('/'), firstSlash = p.indexOf('/');
|
|
5936
|
+
if (-1 !== lastSlash && firstSlash !== lastSlash) {
|
|
5937
|
+
if (-1 !== firstSlash) {
|
|
5938
|
+
let next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5939
|
+
for(; '.' === dir;)firstSlash = next, next = p.indexOf('/', firstSlash + 1), dir = p.slice(firstSlash + 1, next);
|
|
5940
|
+
}
|
|
5941
|
+
return p.slice(firstSlash + 1, lastSlash + 1);
|
|
5942
|
+
}
|
|
5943
|
+
return '';
|
|
5944
|
+
};
|
|
5945
|
+
class BasicRunner {
|
|
5946
|
+
run(file) {
|
|
5947
|
+
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
5948
|
+
let res = this.getRequire()(this._options.dist, file.startsWith('./') ? file : `./${file}`);
|
|
5949
|
+
return 'object' == typeof res && 'then' in res ? res : Promise.resolve(res);
|
|
5950
|
+
}
|
|
5951
|
+
getRequire() {
|
|
5952
|
+
let entryRequire = this.requirers.get('entry');
|
|
5953
|
+
return (currentDirectory, modulePath, context = {})=>entryRequire(currentDirectory, Array.isArray(modulePath) ? modulePath : modulePath.split('?')[0], context);
|
|
5954
|
+
}
|
|
5955
|
+
getFile(modulePath, currentDirectory) {
|
|
5956
|
+
if (Array.isArray(modulePath)) return {
|
|
5957
|
+
path: external_node_path_default().join(currentDirectory, '.array-require.js'),
|
|
5958
|
+
content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
|
|
5959
|
+
subPath: ''
|
|
5960
|
+
};
|
|
5961
|
+
let joinedPath = isRelativePath(modulePath) ? external_node_path_default().join(currentDirectory, modulePath) : modulePath;
|
|
5962
|
+
return this._options.isBundleOutput(joinedPath) ? {
|
|
5963
|
+
path: joinedPath,
|
|
5964
|
+
content: this._options.readFileSync(joinedPath),
|
|
5965
|
+
subPath: getSubPath(modulePath)
|
|
5966
|
+
} : null;
|
|
5967
|
+
}
|
|
5968
|
+
preExecute(_code, _file) {}
|
|
5969
|
+
postExecute(_m, _file) {}
|
|
5970
|
+
createRunner() {
|
|
5971
|
+
this.requirers.set('entry', (_currentDirectory, _modulePath, _context = {})=>{
|
|
5972
|
+
throw Error('[rsbuild:runner] Not implement');
|
|
5973
|
+
});
|
|
5974
|
+
}
|
|
5975
|
+
constructor(_options){
|
|
5976
|
+
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();
|
|
5977
|
+
}
|
|
5978
|
+
}
|
|
5979
|
+
let cjs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), cjs_define = (...args)=>{
|
|
5980
|
+
args.pop()();
|
|
5981
|
+
};
|
|
5982
|
+
class CommonJsRunner extends BasicRunner {
|
|
5983
|
+
createGlobalContext() {
|
|
5984
|
+
return {
|
|
5985
|
+
console: console,
|
|
5986
|
+
setTimeout: (cb, ms, ...args)=>{
|
|
5987
|
+
let timeout = setTimeout(cb, ms, ...args);
|
|
5988
|
+
return timeout.unref(), timeout;
|
|
5989
|
+
},
|
|
5990
|
+
clearTimeout: clearTimeout,
|
|
5991
|
+
queueMicrotask
|
|
5992
|
+
};
|
|
5993
|
+
}
|
|
5994
|
+
createBaseModuleScope() {
|
|
5995
|
+
return {
|
|
5996
|
+
console: this.globalContext.console,
|
|
5997
|
+
setTimeout: this.globalContext.setTimeout,
|
|
5998
|
+
clearTimeout: this.globalContext.clearTimeout,
|
|
5999
|
+
nsObj: (m)=>(Object.defineProperty(m, Symbol.toStringTag, {
|
|
6000
|
+
value: 'Module'
|
|
6001
|
+
}), m),
|
|
6002
|
+
queueMicrotask
|
|
6003
|
+
};
|
|
6004
|
+
}
|
|
6005
|
+
createModuleScope(requireFn, m, file) {
|
|
6006
|
+
return {
|
|
6007
|
+
...this.baseModuleScope,
|
|
6008
|
+
require: requireFn.bind(null, external_node_path_default().dirname(file.path)),
|
|
6009
|
+
module: m,
|
|
6010
|
+
exports: m.exports,
|
|
6011
|
+
__dirname: external_node_path_default().dirname(file.path),
|
|
6012
|
+
__filename: file.path,
|
|
6013
|
+
define: cjs_define
|
|
6014
|
+
};
|
|
6015
|
+
}
|
|
6016
|
+
createRunner() {
|
|
6017
|
+
this.requirers.set('miss', this.createMissRequirer()), this.requirers.set('entry', this.createCjsRequirer());
|
|
6018
|
+
}
|
|
6019
|
+
createMissRequirer() {
|
|
6020
|
+
return (_currentDirectory, modulePath, _context = {})=>{
|
|
6021
|
+
let resolvedPath = cjs_require.resolve(modulePath, {
|
|
6022
|
+
paths: [
|
|
6023
|
+
_currentDirectory
|
|
6024
|
+
]
|
|
6025
|
+
});
|
|
6026
|
+
return cjs_require(resolvedPath.startsWith('node:') ? resolvedPath.slice(5) : resolvedPath);
|
|
6027
|
+
};
|
|
6028
|
+
}
|
|
6029
|
+
createCjsRequirer() {
|
|
6030
|
+
let requireCache = Object.create(null);
|
|
6031
|
+
return (currentDirectory, modulePath, context = {})=>{
|
|
6032
|
+
let file = context.file || this.getFile(modulePath, currentDirectory);
|
|
6033
|
+
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
6034
|
+
if (file.path in requireCache) return requireCache[file.path].exports;
|
|
6035
|
+
let m = {
|
|
6036
|
+
exports: {}
|
|
6037
|
+
};
|
|
6038
|
+
requireCache[file.path] = m;
|
|
6039
|
+
let currentModuleScope = this.createModuleScope(this.getRequire(), m, file), args = Object.keys(currentModuleScope), argValues = args.map((arg)=>currentModuleScope[arg]), code = `(function(${args.join(', ')}) {
|
|
6040
|
+
${file.content}
|
|
6041
|
+
})`;
|
|
6042
|
+
this.preExecute(code, file);
|
|
6043
|
+
let dynamicImport = Function('specifier', 'return import(specifier)');
|
|
6044
|
+
return external_node_vm_default().runInThisContext(code, {
|
|
6045
|
+
filename: file.path,
|
|
6046
|
+
importModuleDynamically: async (specifier)=>await dynamicImport(specifier)
|
|
6047
|
+
}).call(m.exports, ...argValues), this.postExecute(m, file), m.exports;
|
|
6048
|
+
};
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
6051
|
+
var type_EsmMode = function(EsmMode) {
|
|
6052
|
+
return EsmMode[EsmMode.Unknown = 0] = "Unknown", EsmMode[EsmMode.Evaluated = 1] = "Evaluated", EsmMode[EsmMode.Unlinked = 2] = "Unlinked", EsmMode;
|
|
6053
|
+
}({});
|
|
6054
|
+
class EsmRunner extends CommonJsRunner {
|
|
6055
|
+
createRunner() {
|
|
6056
|
+
var _this__options_compilerOptions_experiments;
|
|
6057
|
+
super.createRunner(), this.requirers.set('cjs', this.getRequire()), this.requirers.set('esm', this.createEsmRequirer());
|
|
6058
|
+
let outputModule = null === (_this__options_compilerOptions_experiments = this._options.compilerOptions.experiments) || void 0 === _this__options_compilerOptions_experiments ? void 0 : _this__options_compilerOptions_experiments.outputModule;
|
|
6059
|
+
this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
|
|
6060
|
+
let file = this.getFile(modulePath, currentDirectory);
|
|
6061
|
+
return file ? outputModule && !file.path.endsWith('.cjs') ? this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
6062
|
+
...context,
|
|
6063
|
+
file
|
|
6064
|
+
}) : this.requirers.get('cjs')(currentDirectory, modulePath, {
|
|
6065
|
+
...context,
|
|
6066
|
+
file
|
|
6067
|
+
}) : this.requirers.get('miss')(currentDirectory, modulePath);
|
|
6068
|
+
});
|
|
6069
|
+
}
|
|
6070
|
+
createEsmRequirer() {
|
|
6071
|
+
let esmContext = external_node_vm_default().createContext(this.baseModuleScope, {
|
|
6072
|
+
name: 'context for esm'
|
|
6073
|
+
}), esmCache = new Map(), esmIdentifier = this._options.name;
|
|
6074
|
+
return (currentDirectory, modulePath, context = {})=>{
|
|
6075
|
+
if (!external_node_vm_default().SourceTextModule) throw Error('[rsbuild:runner] Running ESM bundle needs add Node.js option "--experimental-vm-modules".');
|
|
6076
|
+
let _require = this.getRequire(), file = context.file || this.getFile(modulePath, currentDirectory);
|
|
6077
|
+
if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
6078
|
+
let esm = esmCache.get(file.path);
|
|
6079
|
+
return (esm || (esm = new (external_node_vm_default()).SourceTextModule(file.content, {
|
|
6080
|
+
identifier: `${esmIdentifier}-${file.path}`,
|
|
6081
|
+
url: `${(0, external_node_url_namespaceObject.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
6082
|
+
context: esmContext,
|
|
6083
|
+
initializeImportMeta: (meta, _)=>{
|
|
6084
|
+
meta.url = (0, external_node_url_namespaceObject.pathToFileURL)(file.path).href;
|
|
6085
|
+
},
|
|
6086
|
+
importModuleDynamically: async (specifier, module)=>{
|
|
6087
|
+
let result = await _require(external_node_path_default().dirname(file.path), specifier, {
|
|
6088
|
+
esmMode: type_EsmMode.Evaluated
|
|
6089
|
+
});
|
|
6090
|
+
return await asModule(result, module.context);
|
|
6091
|
+
}
|
|
6092
|
+
}), esmCache.set(file.path, esm)), context.esmMode === type_EsmMode.Unlinked) ? esm : (async ()=>{
|
|
6093
|
+
if (await esm.link(async (specifier, referencingModule)=>await asModule(await _require(external_node_path_default().dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, external_node_url_namespaceObject.fileURLToPath)(referencingModule.url)), specifier, {
|
|
6094
|
+
esmMode: type_EsmMode.Unlinked
|
|
6095
|
+
}), referencingModule.context, !0)), esm.instantiate && esm.instantiate(), await esm.evaluate(), context.esmMode === type_EsmMode.Evaluated) return esm;
|
|
6096
|
+
let ns = esm.namespace;
|
|
6097
|
+
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
6098
|
+
})();
|
|
6099
|
+
};
|
|
6100
|
+
}
|
|
6101
|
+
}
|
|
6102
|
+
class BasicRunnerFactory {
|
|
6103
|
+
create(options) {
|
|
6104
|
+
return this.createRunner(options);
|
|
6105
|
+
}
|
|
6106
|
+
createRunner(options) {
|
|
6107
|
+
let runnerOptions = {
|
|
6108
|
+
name: this.name,
|
|
6109
|
+
...options
|
|
6110
|
+
}, { compilerOptions } = options;
|
|
6111
|
+
if ('web' === compilerOptions.target || 'webworker' === compilerOptions.target) throw Error(`[rsbuild:runner] Not support run "${compilerOptions.target}" resource in Rsbuild server`);
|
|
6112
|
+
return new EsmRunner(runnerOptions);
|
|
6113
|
+
}
|
|
6114
|
+
constructor(name){
|
|
6115
|
+
!function(obj, key, value) {
|
|
6116
|
+
key in obj ? Object.defineProperty(obj, key, {
|
|
6117
|
+
value: value,
|
|
6118
|
+
enumerable: !0,
|
|
6119
|
+
configurable: !0,
|
|
6120
|
+
writable: !0
|
|
6121
|
+
}) : obj[key] = value;
|
|
6122
|
+
}(this, "name", void 0), this.name = name;
|
|
6123
|
+
}
|
|
6124
|
+
}
|
|
6125
|
+
let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions).run(bundlePath), loadBundle = async (stats, entryName, utils)=>{
|
|
6126
|
+
let { chunks, entrypoints, outputPath } = stats.toJson({
|
|
6127
|
+
all: !1,
|
|
6128
|
+
chunks: !0,
|
|
6129
|
+
entrypoints: !0,
|
|
6130
|
+
outputPath: !0
|
|
6131
|
+
});
|
|
6132
|
+
if (!(null == entrypoints ? void 0 : entrypoints[entryName])) throw Error(`[rsbuild:loadBundle] Can't find entry: "${entryName}"`);
|
|
6133
|
+
let { chunks: entryChunks = [] } = entrypoints[entryName], files = entryChunks.reduce((prev, entryChunkName)=>{
|
|
6134
|
+
let chunk = null == chunks ? void 0 : chunks.find((chunk)=>{
|
|
6135
|
+
var _chunk_names;
|
|
6136
|
+
return chunk.entry && (null === (_chunk_names = chunk.names) || void 0 === _chunk_names ? void 0 : _chunk_names.includes(String(entryChunkName)));
|
|
6137
|
+
});
|
|
6138
|
+
return (null == chunk ? void 0 : chunk.files) ? prev.concat(chunk.files.filter((file)=>!file.endsWith('.css'))) : prev;
|
|
6139
|
+
}, []);
|
|
6140
|
+
if (0 === files.length) throw Error(`[rsbuild:loadBundle] Failed to get bundle by entryName: "${entryName}"`);
|
|
6141
|
+
if (files.length > 1) throw Error(`[rsbuild:loadBundle] Only support load single entry chunk, but got ${files.length}: ${files.join(',')}`);
|
|
6142
|
+
let allChunkFiles = (null == chunks ? void 0 : chunks.flatMap((c)=>c.files).map((file)=>(0, external_node_path_namespaceObject.join)(outputPath, file))) || [];
|
|
6143
|
+
return await runner_run({
|
|
6144
|
+
bundlePath: files[0],
|
|
6145
|
+
dist: outputPath,
|
|
6146
|
+
compilerOptions: stats.compilation.options,
|
|
6147
|
+
readFileSync: utils.readFileSync,
|
|
6148
|
+
isBundleOutput: (modulePath)=>allChunkFiles.includes(modulePath)
|
|
6149
|
+
});
|
|
6150
|
+
}, getTransformedHtml = async (entryName, utils)=>{
|
|
6151
|
+
let { htmlPaths, distPath } = utils.environment, htmlPath = htmlPaths[entryName];
|
|
6152
|
+
if (!htmlPath) throw Error(`[rsbuild:getTransformedHtml] Failed to get HTML file by entryName: "${entryName}"`);
|
|
6153
|
+
let fileName = (0, external_node_path_namespaceObject.join)(distPath, htmlPath);
|
|
6154
|
+
return utils.readFileSync(fileName);
|
|
6155
|
+
}, createCacheableFunction = (getter)=>{
|
|
6156
|
+
let cache = new WeakMap();
|
|
6157
|
+
return async (stats, entryName, utils)=>{
|
|
6158
|
+
let cachedEntries = cache.get(stats);
|
|
6159
|
+
if (null == cachedEntries ? void 0 : cachedEntries[entryName]) return cachedEntries[entryName];
|
|
6160
|
+
let res = await getter(stats, entryName, utils);
|
|
6161
|
+
return cache.set(stats, {
|
|
6162
|
+
...cachedEntries || {},
|
|
6163
|
+
[entryName]: res
|
|
6164
|
+
}), res;
|
|
6165
|
+
};
|
|
6186
6166
|
}, cleanupCallbacks = new Set(), handleTermination = async (_, exitCode)=>{
|
|
6187
6167
|
try {
|
|
6188
6168
|
await Promise.all([
|
|
@@ -6222,14 +6202,14 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6222
6202
|
rslog_index_js_namespaceObject.logger.debug('create dev server');
|
|
6223
6203
|
let { port, host, https, portTip } = await getServerConfig({
|
|
6224
6204
|
config
|
|
6225
|
-
}), { middlewareMode } = config.server, devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(
|
|
6226
|
-
|
|
6205
|
+
}), { middlewareMode } = config.server, { context } = options, devConfig = devServer_formatDevConfig(config.dev, port), routes = getRoutes(context), root = context.rootPath;
|
|
6206
|
+
context.devServer = {
|
|
6227
6207
|
hostname: host,
|
|
6228
6208
|
port,
|
|
6229
6209
|
https
|
|
6230
6210
|
};
|
|
6231
|
-
let
|
|
6232
|
-
|
|
6211
|
+
let waitFirstCompileDone = runCompile ? new Promise((resolve)=>{
|
|
6212
|
+
context.hooks.onDevCompileDone.tap(({ stats, isFirstCompile })=>{
|
|
6233
6213
|
lastStats = 'stats' in stats ? stats.stats : [
|
|
6234
6214
|
stats
|
|
6235
6215
|
], isFirstCompile && resolve();
|
|
@@ -6239,7 +6219,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6239
6219
|
if (!compiler) throw Error('[rsbuild:server] Failed to get compiler instance.');
|
|
6240
6220
|
let publicPaths = helpers_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
6241
6221
|
getPublicPathFromCompiler(compiler)
|
|
6242
|
-
],
|
|
6222
|
+
], compilationManager = new CompilationManager({
|
|
6243
6223
|
dev: devConfig,
|
|
6244
6224
|
server: {
|
|
6245
6225
|
...config.server,
|
|
@@ -6247,14 +6227,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6247
6227
|
},
|
|
6248
6228
|
publicPaths: publicPaths,
|
|
6249
6229
|
compiler,
|
|
6250
|
-
environments:
|
|
6230
|
+
environments: context.environments
|
|
6251
6231
|
});
|
|
6252
|
-
return await
|
|
6253
|
-
middleware: compilerDevMiddleware.middleware,
|
|
6254
|
-
sockWrite: (...args)=>compilerDevMiddleware.sockWrite(...args),
|
|
6255
|
-
onUpgrade: (...args)=>compilerDevMiddleware.upgrade(...args),
|
|
6256
|
-
close: ()=>null == compilerDevMiddleware ? void 0 : compilerDevMiddleware.close()
|
|
6257
|
-
};
|
|
6232
|
+
return await compilationManager.init(), compilationManager;
|
|
6258
6233
|
}, protocol = https ? 'https' : 'http', urls = getAddressUrls({
|
|
6259
6234
|
protocol,
|
|
6260
6235
|
port,
|
|
@@ -6273,7 +6248,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6273
6248
|
config,
|
|
6274
6249
|
clearCache: !0
|
|
6275
6250
|
}), cleanupGracefulShutdown = middlewareMode ? null : setupGracefulShutdown(), closeServer = async ()=>{
|
|
6276
|
-
removeCleanup(closeServer), null == cleanupGracefulShutdown || cleanupGracefulShutdown(), await
|
|
6251
|
+
removeCleanup(closeServer), null == cleanupGracefulShutdown || cleanupGracefulShutdown(), await context.hooks.onCloseDevServer.callBatch(), await Promise.all([
|
|
6277
6252
|
null == devMiddlewares ? void 0 : devMiddlewares.close(),
|
|
6278
6253
|
null == fileWatcher ? void 0 : fileWatcher.close()
|
|
6279
6254
|
]);
|
|
@@ -6291,24 +6266,30 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6291
6266
|
help: shortcutsOptions.help,
|
|
6292
6267
|
customShortcuts: shortcutsOptions.custom
|
|
6293
6268
|
});
|
|
6294
|
-
|
|
6269
|
+
context.hooks.onCloseDevServer.tap(cleanup);
|
|
6295
6270
|
}
|
|
6296
6271
|
!getPortSilently && portTip && rslog_index_js_namespaceObject.logger.info(portTip);
|
|
6297
|
-
},
|
|
6272
|
+
}, cacheableLoadBundle = createCacheableFunction(loadBundle), cacheableTransformedHtml = createCacheableFunction((_stats, entryName, utils)=>getTransformedHtml(entryName, utils)), environmentAPI = Object.fromEntries(Object.entries(context.environments).map(([name, environment])=>[
|
|
6298
6273
|
name,
|
|
6299
6274
|
{
|
|
6300
6275
|
getStats: async ()=>{
|
|
6301
|
-
if (!
|
|
6276
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `getStats` when `runCompile` is false');
|
|
6302
6277
|
return await waitFirstCompileDone, lastStats[environment.index];
|
|
6303
6278
|
},
|
|
6304
|
-
loadBundle: async (entryName)=>
|
|
6305
|
-
|
|
6279
|
+
loadBundle: async (entryName)=>{
|
|
6280
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `loadBundle` when `runCompile` is false');
|
|
6281
|
+
return await waitFirstCompileDone, cacheableLoadBundle(lastStats[environment.index], entryName, {
|
|
6282
|
+
readFileSync: compilationManager.readFileSync,
|
|
6306
6283
|
environment
|
|
6307
|
-
})
|
|
6308
|
-
|
|
6309
|
-
|
|
6284
|
+
});
|
|
6285
|
+
},
|
|
6286
|
+
getTransformedHtml: async (entryName)=>{
|
|
6287
|
+
if (!compilationManager) throw Error('[rsbuild:server] Can not call `getTransformedHtml` when `runCompile` is false');
|
|
6288
|
+
return await waitFirstCompileDone, cacheableTransformedHtml(lastStats[environment.index], entryName, {
|
|
6289
|
+
readFileSync: compilationManager.readFileSync,
|
|
6310
6290
|
environment
|
|
6311
|
-
})
|
|
6291
|
+
});
|
|
6292
|
+
}
|
|
6312
6293
|
}
|
|
6313
6294
|
])), { default: connect } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/connect/index.js")), middlewares = connect(), httpServer = middlewareMode ? null : await createHttpServer({
|
|
6314
6295
|
serverConfig: config.server,
|
|
@@ -6321,7 +6302,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6321
6302
|
listen: async ()=>{
|
|
6322
6303
|
if (!httpServer) throw Error('[rsbuild:server] Can not listen dev server as `server.middlewareMode` is enabled.');
|
|
6323
6304
|
let serverTerminator = getServerTerminator(httpServer);
|
|
6324
|
-
return rslog_index_js_namespaceObject.logger.debug('listen dev server'),
|
|
6305
|
+
return rslog_index_js_namespaceObject.logger.debug('listen dev server'), context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
|
|
6325
6306
|
httpServer.listen({
|
|
6326
6307
|
host,
|
|
6327
6308
|
port
|
|
@@ -6338,10 +6319,10 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6338
6319
|
});
|
|
6339
6320
|
},
|
|
6340
6321
|
afterListen: async ()=>{
|
|
6341
|
-
await
|
|
6322
|
+
await context.hooks.onAfterStartDevServer.callBatch({
|
|
6342
6323
|
port,
|
|
6343
6324
|
routes,
|
|
6344
|
-
environments:
|
|
6325
|
+
environments: context.environments
|
|
6345
6326
|
});
|
|
6346
6327
|
},
|
|
6347
6328
|
connectWebSocket: ({ server })=>{
|
|
@@ -6350,27 +6331,24 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6350
6331
|
close: closeServer,
|
|
6351
6332
|
printUrls,
|
|
6352
6333
|
open: openPage
|
|
6353
|
-
}, postCallbacks = (await
|
|
6334
|
+
}, postCallbacks = (await context.hooks.onBeforeStartDevServer.callBatch({
|
|
6354
6335
|
server: devServerAPI,
|
|
6355
|
-
environments:
|
|
6336
|
+
environments: context.environments
|
|
6356
6337
|
})).filter((item)=>'function' == typeof item);
|
|
6357
|
-
runCompile ?
|
|
6358
|
-
let
|
|
6338
|
+
runCompile ? context.hooks.onBeforeCreateCompiler.tap(beforeCreateCompiler) : beforeCreateCompiler();
|
|
6339
|
+
let compilationManager = runCompile ? await startCompile() : void 0;
|
|
6359
6340
|
for (let item of (fileWatcher = await setupWatchFiles({
|
|
6360
6341
|
dev: devConfig,
|
|
6361
6342
|
server: config.server,
|
|
6362
|
-
|
|
6343
|
+
compilationManager,
|
|
6363
6344
|
root
|
|
6364
|
-
}), (devMiddlewares = await
|
|
6345
|
+
}), (devMiddlewares = await getDevMiddlewares({
|
|
6365
6346
|
pwd: root,
|
|
6366
|
-
|
|
6347
|
+
compilationManager,
|
|
6367
6348
|
dev: devConfig,
|
|
6349
|
+
context,
|
|
6368
6350
|
server: config.server,
|
|
6369
6351
|
environments: environmentAPI,
|
|
6370
|
-
output: {
|
|
6371
|
-
distPath: options.context.distPath || ROOT_DIST_DIR
|
|
6372
|
-
},
|
|
6373
|
-
outputFileSystem,
|
|
6374
6352
|
postCallbacks
|
|
6375
6353
|
})).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
|
|
6376
6354
|
return rslog_index_js_namespaceObject.logger.debug('create dev server done'), devServerAPI;
|
|
@@ -6742,9 +6720,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6742
6720
|
setup (api) {
|
|
6743
6721
|
'webpack' !== api.context.bundlerType && (api.modifyRsbuildConfig((config)=>{
|
|
6744
6722
|
let { moduleFederation } = config;
|
|
6745
|
-
if ((null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
|
|
6723
|
+
if (api.isPluginExists('rsbuild:module-federation-enhanced') && (config.server ||= {}, config.server.cors ||= !0), (null == moduleFederation ? void 0 : moduleFederation.options) && moduleFederation.options.exposes) {
|
|
6746
6724
|
var _config_server, _config_dev_client, _originalConfig_dev, _config_server1;
|
|
6747
|
-
config.dev ||= {}, (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.port) && !(null === (_config_dev_client = config.dev.client) || void 0 === _config_dev_client ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null === (_originalConfig_dev = api.getRsbuildConfig('original').dev) || void 0 === _originalConfig_dev ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null === (_config_server1 = config.server) || void 0 === _config_server1 ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
|
|
6725
|
+
config.dev ||= {}, config.server ||= {}, config.server.cors ||= !0, (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.port) && !(null === (_config_dev_client = config.dev.client) || void 0 === _config_dev_client ? void 0 : _config_dev_client.port) && (config.dev.client ||= {}, config.dev.client.port = config.server.port), (null === (_originalConfig_dev = api.getRsbuildConfig('original').dev) || void 0 === _originalConfig_dev ? void 0 : _originalConfig_dev.assetPrefix) === void 0 && config.dev.assetPrefix === (null === (_config_server1 = config.server) || void 0 === _config_server1 ? void 0 : _config_server1.base) && (config.dev.assetPrefix = !0);
|
|
6748
6726
|
}
|
|
6749
6727
|
}), api.modifyEnvironmentConfig((config)=>{
|
|
6750
6728
|
var _config_moduleFederation, _config_performance_chunkSplit, _config_performance;
|
|
@@ -6769,7 +6747,6 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
|
|
|
6769
6747
|
}
|
|
6770
6748
|
},
|
|
6771
6749
|
pluginRspackProfile(),
|
|
6772
|
-
pluginLazyCompilation(),
|
|
6773
6750
|
pluginSri(),
|
|
6774
6751
|
pluginNonce()
|
|
6775
6752
|
]);
|
|
@@ -7445,11 +7422,11 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
7445
7422
|
}
|
|
7446
7423
|
}(), process.title = 'rsbuild-node';
|
|
7447
7424
|
let { npm_execpath } = process.env;
|
|
7448
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.0-beta.
|
|
7425
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.0-beta.3\n`);
|
|
7449
7426
|
try {
|
|
7450
7427
|
!function() {
|
|
7451
7428
|
let cli = cac_dist('rsbuild');
|
|
7452
|
-
cli.help(), cli.version("1.3.0-beta.
|
|
7429
|
+
cli.help(), cli.version("1.3.0-beta.3"), applyCommonOptions(cli);
|
|
7453
7430
|
let devCommand = cli.command('', 'starting the dev server').alias('dev'), 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');
|
|
7454
7431
|
applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
|
|
7455
7432
|
try {
|
|
@@ -7500,7 +7477,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
7500
7477
|
rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
|
|
7501
7478
|
}
|
|
7502
7479
|
}
|
|
7503
|
-
let src_rslib_entry_version = "1.3.0-beta.
|
|
7480
|
+
let src_rslib_entry_version = "1.3.0-beta.3";
|
|
7504
7481
|
})();
|
|
7505
7482
|
var __webpack_export_target__ = exports;
|
|
7506
7483
|
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|