@modern-js/builder 3.0.0-alpha.0 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createBuilder.js +96 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/plugins/devtools.js +47 -0
- package/dist/cjs/plugins/emitRouteFile.js +75 -0
- package/dist/cjs/plugins/environmentDefaults.js +100 -0
- package/dist/cjs/plugins/globalVars.js +55 -0
- package/dist/cjs/plugins/htmlMinify.js +115 -0
- package/dist/cjs/plugins/manifest.js +52 -0
- package/dist/cjs/plugins/postcss.js +118 -0
- package/dist/cjs/plugins/runtimeChunk.js +54 -0
- package/dist/cjs/rsc/common.js +157 -0
- package/dist/cjs/rsc/plugins/rsbuild-rsc-plugin.js +169 -0
- package/dist/cjs/rsc/plugins/rspack-rsc-client-plugin.js +187 -0
- package/dist/cjs/rsc/plugins/rspack-rsc-server-plugin.js +245 -0
- package/dist/cjs/rsc/rsc-client-loader.js +71 -0
- package/dist/cjs/rsc/rsc-css-loader.js +42 -0
- package/dist/cjs/rsc/rsc-server-loader.js +102 -0
- package/dist/cjs/rsc/rsc-ssr-loader.js +60 -0
- package/dist/cjs/shared/devServer.js +87 -0
- package/dist/cjs/shared/getCssSupport.js +121 -0
- package/dist/cjs/shared/manifest.js +46 -0
- package/dist/cjs/shared/parseCommonConfig.js +209 -0
- package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +64 -0
- package/dist/cjs/shared/rsc/rscEmptyModule.js +36 -0
- package/dist/cjs/shared/utils.js +115 -0
- package/dist/cjs/types.js +18 -0
- package/dist/compiled/postcss-load-config/index.d.ts +1 -0
- package/dist/compiled/postcss-load-config/index.js +608 -0
- package/dist/compiled/postcss-load-config/index.js.LICENSE.txt +13 -0
- package/dist/compiled/postcss-load-config/license +20 -0
- package/dist/compiled/postcss-load-config/package.json +1 -0
- package/dist/esm/createBuilder.mjs +59 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/plugins/devtools.mjs +13 -0
- package/dist/esm/plugins/emitRouteFile.mjs +28 -0
- package/dist/esm/plugins/environmentDefaults.mjs +66 -0
- package/dist/esm/plugins/globalVars.mjs +21 -0
- package/dist/esm/plugins/htmlMinify.mjs +81 -0
- package/dist/esm/plugins/manifest.mjs +18 -0
- package/dist/esm/plugins/postcss.mjs +81 -0
- package/dist/esm/plugins/runtimeChunk.mjs +20 -0
- package/dist/esm/rsc/common.mjs +87 -0
- package/dist/esm/rsc/plugins/rsbuild-rsc-plugin.mjs +124 -0
- package/dist/esm/rsc/plugins/rspack-rsc-client-plugin.mjs +143 -0
- package/dist/esm/rsc/plugins/rspack-rsc-server-plugin.mjs +211 -0
- package/dist/esm/rsc/rsc-client-loader.mjs +37 -0
- package/dist/esm/rsc/rsc-css-loader.mjs +8 -0
- package/dist/esm/rsc/rsc-server-loader.mjs +58 -0
- package/dist/esm/rsc/rsc-ssr-loader.mjs +26 -0
- package/dist/esm/shared/devServer.mjs +53 -0
- package/dist/esm/shared/getCssSupport.mjs +77 -0
- package/dist/esm/shared/manifest.mjs +12 -0
- package/dist/esm/shared/parseCommonConfig.mjs +172 -0
- package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
- package/dist/esm/shared/rsc/rscEmptyModule.mjs +2 -0
- package/dist/esm/shared/utils.mjs +53 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm-node/createBuilder.mjs +61 -0
- package/dist/esm-node/index.mjs +6 -0
- package/dist/esm-node/plugins/devtools.mjs +15 -0
- package/dist/esm-node/plugins/emitRouteFile.mjs +30 -0
- package/dist/esm-node/plugins/environmentDefaults.mjs +68 -0
- package/dist/esm-node/plugins/globalVars.mjs +23 -0
- package/dist/esm-node/plugins/htmlMinify.mjs +83 -0
- package/dist/esm-node/plugins/manifest.mjs +20 -0
- package/dist/esm-node/plugins/postcss.mjs +83 -0
- package/dist/esm-node/plugins/runtimeChunk.mjs +22 -0
- package/dist/esm-node/rsc/common.mjs +89 -0
- package/dist/esm-node/rsc/plugins/rsbuild-rsc-plugin.mjs +126 -0
- package/dist/esm-node/rsc/plugins/rspack-rsc-client-plugin.mjs +145 -0
- package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +213 -0
- package/dist/esm-node/rsc/rsc-client-loader.mjs +39 -0
- package/dist/esm-node/rsc/rsc-css-loader.mjs +10 -0
- package/dist/esm-node/rsc/rsc-server-loader.mjs +60 -0
- package/dist/esm-node/rsc/rsc-ssr-loader.mjs +28 -0
- package/dist/esm-node/shared/devServer.mjs +55 -0
- package/dist/esm-node/shared/getCssSupport.mjs +79 -0
- package/dist/esm-node/shared/manifest.mjs +14 -0
- package/dist/esm-node/shared/parseCommonConfig.mjs +174 -0
- package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
- package/dist/esm-node/shared/rsc/rscEmptyModule.mjs +4 -0
- package/dist/esm-node/shared/utils.mjs +55 -0
- package/dist/esm-node/types.mjs +2 -0
- package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
- package/dist/types/shared/rsc/rscEmptyModule.d.ts +2 -0
- package/dist/{types.d.ts → types/types.d.ts} +2 -16
- package/package.json +36 -31
- package/dist/createBuilder.js +0 -153
- package/dist/index.js +0 -45
- package/dist/plugins/babel-post.d.ts +0 -5
- package/dist/plugins/babel-post.js +0 -57
- package/dist/plugins/devtools.js +0 -42
- package/dist/plugins/emitRouteFile.js +0 -70
- package/dist/plugins/environmentDefaults.js +0 -99
- package/dist/plugins/globalVars.js +0 -50
- package/dist/plugins/htmlMinify.js +0 -126
- package/dist/plugins/manifest.js +0 -54
- package/dist/plugins/postcss.js +0 -133
- package/dist/plugins/runtimeChunk.js +0 -55
- package/dist/rsc/common.js +0 -174
- package/dist/rsc/plugins/rsbuild-rsc-plugin.js +0 -166
- package/dist/rsc/plugins/rspack-rsc-client-plugin.js +0 -233
- package/dist/rsc/plugins/rspack-rsc-server-plugin.js +0 -290
- package/dist/rsc/rsc-client-loader.js +0 -70
- package/dist/rsc/rsc-css-loader.js +0 -30
- package/dist/rsc/rsc-server-loader.js +0 -95
- package/dist/rsc/rsc-ssr-loader.js +0 -58
- package/dist/shared/devServer.js +0 -83
- package/dist/shared/getCssSupport.js +0 -113
- package/dist/shared/manifest.js +0 -38
- package/dist/shared/parseCommonConfig.js +0 -232
- package/dist/shared/utils.js +0 -109
- package/dist/types.js +0 -16
- /package/dist/{createBuilder.d.ts → types/createBuilder.d.ts} +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{plugins → types/plugins}/devtools.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/emitRouteFile.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/environmentDefaults.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/globalVars.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/htmlMinify.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/manifest.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/postcss.d.ts +0 -0
- /package/dist/{plugins → types/plugins}/runtimeChunk.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/common.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/plugins/rsbuild-rsc-plugin.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-client-plugin.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-server-plugin.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/rsc-client-loader.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/rsc-css-loader.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/rsc-server-loader.d.ts +0 -0
- /package/dist/{rsc → types/rsc}/rsc-ssr-loader.d.ts +0 -0
- /package/dist/{shared → types/shared}/devServer.d.ts +0 -0
- /package/dist/{shared → types/shared}/getCssSupport.d.ts +0 -0
- /package/dist/{shared → types/shared}/manifest.d.ts +0 -0
- /package/dist/{shared → types/shared}/parseCommonConfig.d.ts +0 -0
- /package/dist/{shared → types/shared}/utils.d.ts +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
2
|
+
import { pluginCssMinimizer } from "@rsbuild/plugin-css-minimizer";
|
|
3
|
+
import { pluginLess } from "@rsbuild/plugin-less";
|
|
4
|
+
import { pluginReact } from "@rsbuild/plugin-react";
|
|
5
|
+
import { pluginSass } from "@rsbuild/plugin-sass";
|
|
6
|
+
import { pluginDevtool } from "../plugins/devtools.mjs";
|
|
7
|
+
import { pluginEmitRouteFile } from "../plugins/emitRouteFile.mjs";
|
|
8
|
+
import { pluginEnvironmentDefaults } from "../plugins/environmentDefaults.mjs";
|
|
9
|
+
import { pluginGlobalVars } from "../plugins/globalVars.mjs";
|
|
10
|
+
import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
|
|
11
|
+
import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
|
|
12
|
+
import { transformToRsbuildServerOptions } from "./devServer.mjs";
|
|
13
|
+
import { NODE_MODULES_REGEX } from "./utils.mjs";
|
|
14
|
+
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
15
|
+
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
16
|
+
const isLooseCssModules = (path)=>{
|
|
17
|
+
if (NODE_MODULES_REGEX.test(path)) return CSS_MODULES_REGEX.test(path);
|
|
18
|
+
return !GLOBAL_CSS_REGEX.test(path);
|
|
19
|
+
};
|
|
20
|
+
function removeUndefinedKey(obj) {
|
|
21
|
+
Object.keys(obj).forEach((key)=>{
|
|
22
|
+
if (void 0 === obj[key]) delete obj[key];
|
|
23
|
+
});
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
async function parseCommonConfig(builderConfig, options) {
|
|
27
|
+
const frameworkConfigPath = options?.frameworkConfigPath;
|
|
28
|
+
const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
|
|
29
|
+
let combinedAlias;
|
|
30
|
+
if (alias || resolve.alias) combinedAlias = [].concat(alias ?? []).concat(resolve.alias ?? []);
|
|
31
|
+
const rsbuildConfig = {
|
|
32
|
+
plugins,
|
|
33
|
+
splitChunks,
|
|
34
|
+
output: {
|
|
35
|
+
polyfill: 'ua' === polyfill ? 'off' : polyfill,
|
|
36
|
+
dataUriLimit,
|
|
37
|
+
sourceMap,
|
|
38
|
+
module,
|
|
39
|
+
...outputConfig
|
|
40
|
+
},
|
|
41
|
+
resolve: {
|
|
42
|
+
...resolve,
|
|
43
|
+
alias: combinedAlias
|
|
44
|
+
},
|
|
45
|
+
source: sourceConfig,
|
|
46
|
+
performance: performanceConfig,
|
|
47
|
+
html: htmlConfig,
|
|
48
|
+
tools: toolsConfig,
|
|
49
|
+
security: securityConfig,
|
|
50
|
+
environments
|
|
51
|
+
};
|
|
52
|
+
rsbuildConfig.tools.htmlPlugin = htmlPlugin;
|
|
53
|
+
rsbuildConfig.tools.lightningcssLoader ??= false;
|
|
54
|
+
const { html = {}, output = {}, source = {} } = rsbuildConfig;
|
|
55
|
+
source.transformImport = false === transformImport ? ()=>[] : transformImport;
|
|
56
|
+
if (!source.decorators) source.decorators = {
|
|
57
|
+
version: 'legacy'
|
|
58
|
+
};
|
|
59
|
+
output.charset ??= 'ascii';
|
|
60
|
+
if ('boolean' != typeof output.sourceMap) {
|
|
61
|
+
output.sourceMap ||= {};
|
|
62
|
+
output.sourceMap.css ??= 'production' !== process.env.NODE_ENV;
|
|
63
|
+
}
|
|
64
|
+
const { server: _server, worker, ...rsbuildDistPath } = distPath;
|
|
65
|
+
output.distPath = rsbuildDistPath;
|
|
66
|
+
output.distPath.html ??= 'html';
|
|
67
|
+
output.polyfill ??= 'entry';
|
|
68
|
+
if (disableCssModuleExtension) {
|
|
69
|
+
output.cssModules ||= {};
|
|
70
|
+
output.cssModules.auto ??= isLooseCssModules;
|
|
71
|
+
}
|
|
72
|
+
const extraConfig = {};
|
|
73
|
+
extraConfig.html ||= {};
|
|
74
|
+
extraConfig.html.outputStructure = outputStructure ?? 'nested';
|
|
75
|
+
html.title ??= '';
|
|
76
|
+
html.appIcon = appIcon;
|
|
77
|
+
extraConfig.tools ??= {};
|
|
78
|
+
if (false !== htmlPlugin) extraConfig.tools.htmlPlugin = (config)=>{
|
|
79
|
+
if ('function' == typeof config.templateParameters) {
|
|
80
|
+
const originFn = config.templateParameters;
|
|
81
|
+
config.templateParameters = (...args)=>{
|
|
82
|
+
const res = originFn(...args);
|
|
83
|
+
return {
|
|
84
|
+
title: config.title,
|
|
85
|
+
meta: void 0,
|
|
86
|
+
...res
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
if (!dev.lazyCompilation) dev.lazyCompilation = false;
|
|
92
|
+
const { rsbuildDev, rsbuildServer } = transformToRsbuildServerOptions(dev || {}, devServer || {}, server || {});
|
|
93
|
+
rsbuildConfig.server = removeUndefinedKey(rsbuildServer);
|
|
94
|
+
rsbuildConfig.dev = removeUndefinedKey(rsbuildDev);
|
|
95
|
+
rsbuildConfig.html = html;
|
|
96
|
+
rsbuildConfig.output = output;
|
|
97
|
+
const rsbuildPlugins = [
|
|
98
|
+
pluginGlobalVars(globalVars),
|
|
99
|
+
pluginDevtool({
|
|
100
|
+
sourceMap
|
|
101
|
+
}),
|
|
102
|
+
pluginEmitRouteFile(),
|
|
103
|
+
pluginSass({
|
|
104
|
+
sassLoaderOptions: sass
|
|
105
|
+
}),
|
|
106
|
+
pluginLess({
|
|
107
|
+
lessLoaderOptions: less
|
|
108
|
+
}),
|
|
109
|
+
pluginEnvironmentDefaults(distPath),
|
|
110
|
+
pluginHtmlMinifierTerser()
|
|
111
|
+
];
|
|
112
|
+
if (checkSyntax) {
|
|
113
|
+
const { pluginCheckSyntax } = await import("@rsbuild/plugin-check-syntax");
|
|
114
|
+
rsbuildPlugins.push(pluginCheckSyntax('boolean' == typeof checkSyntax ? {} : checkSyntax));
|
|
115
|
+
}
|
|
116
|
+
if (!disableTsChecker) {
|
|
117
|
+
const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
|
|
118
|
+
rsbuildPlugins.push(pluginTypeCheck({
|
|
119
|
+
tsCheckerOptions: tsChecker
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
if (convertToRem) {
|
|
123
|
+
const { pluginRem } = await import("@rsbuild/plugin-rem");
|
|
124
|
+
rsbuildPlugins.push(pluginRem('boolean' == typeof convertToRem ? {} : convertToRem));
|
|
125
|
+
}
|
|
126
|
+
if (enableCssModuleTSDeclaration) {
|
|
127
|
+
const { pluginTypedCSSModules } = await import("@rsbuild/plugin-typed-css-modules");
|
|
128
|
+
rsbuildPlugins.push(pluginTypedCSSModules());
|
|
129
|
+
}
|
|
130
|
+
rsbuildPlugins.push(pluginRuntimeChunk(builderConfig.output?.disableInlineRuntimeChunk));
|
|
131
|
+
const { sourceBuild } = builderConfig.experiments || {};
|
|
132
|
+
if (sourceBuild) {
|
|
133
|
+
const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
|
|
134
|
+
rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
|
|
135
|
+
}
|
|
136
|
+
rsbuildPlugins.push(pluginReact());
|
|
137
|
+
if (!disableSvgr) {
|
|
138
|
+
const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
|
|
139
|
+
rsbuildPlugins.push(pluginSvgr({
|
|
140
|
+
mixedImport: true,
|
|
141
|
+
svgrOptions: {
|
|
142
|
+
exportType: 'component' === svgDefaultExport ? 'default' : 'named'
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
if (assetsRetry) {
|
|
147
|
+
const { pluginAssetsRetry } = await import("@rsbuild/plugin-assets-retry");
|
|
148
|
+
rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
|
|
149
|
+
}
|
|
150
|
+
if (frameworkConfigPath && false !== performanceConfig.buildCache) {
|
|
151
|
+
const buildCache = 'object' == typeof performanceConfig.buildCache ? performanceConfig.buildCache : {};
|
|
152
|
+
rsbuildConfig.performance.buildCache = {
|
|
153
|
+
...buildCache,
|
|
154
|
+
buildDependencies: [
|
|
155
|
+
frameworkConfigPath,
|
|
156
|
+
...buildCache.buildDependencies || []
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
rsbuildPlugins.push(pluginCssMinimizer({
|
|
161
|
+
pluginOptions: minifyCss
|
|
162
|
+
}));
|
|
163
|
+
if (enableAssetManifest) {
|
|
164
|
+
const { pluginManifest } = await import("../plugins/manifest.mjs");
|
|
165
|
+
rsbuildPlugins.push(pluginManifest());
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
rsbuildConfig: mergeRsbuildConfig(rsbuildConfig, extraConfig),
|
|
169
|
+
rsbuildPlugins
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export { isLooseCssModules, parseCommonConfig };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
function rscClientBrowserFallbackPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'builder:rsc-client-browser-fallback',
|
|
5
|
+
setup (api) {
|
|
6
|
+
let emptyModulePath;
|
|
7
|
+
try {
|
|
8
|
+
emptyModulePath = require.resolve('./rscEmptyModule');
|
|
9
|
+
} catch {
|
|
10
|
+
emptyModulePath = path.resolve(__dirname, 'rscEmptyModule');
|
|
11
|
+
}
|
|
12
|
+
api.modifyRspackConfig((config)=>{
|
|
13
|
+
config.resolve ??= {};
|
|
14
|
+
config.resolve.fallback ??= {};
|
|
15
|
+
config.resolve.fallback['react-server-dom-webpack/client.browser'] = emptyModulePath;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export { rscClientBrowserFallbackPlugin };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import browserslist from "browserslist";
|
|
2
|
+
const RUNTIME_CHUNK_NAME = 'builder-runtime';
|
|
3
|
+
const RUNTIME_CHUNK_REGEX = new RegExp(`${RUNTIME_CHUNK_NAME}([.].+)?\\.js$`);
|
|
4
|
+
const SERVICE_WORKER_ENVIRONMENT_NAME = 'workerSSR';
|
|
5
|
+
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
6
|
+
const castArray = (arr)=>{
|
|
7
|
+
if (void 0 === arr) return [];
|
|
8
|
+
return Array.isArray(arr) ? arr : [
|
|
9
|
+
arr
|
|
10
|
+
];
|
|
11
|
+
};
|
|
12
|
+
const browsersListCache = new Map();
|
|
13
|
+
async function getBrowserslist(path) {
|
|
14
|
+
const env = process.env.NODE_ENV;
|
|
15
|
+
const cacheKey = `${path}${env}`;
|
|
16
|
+
if (browsersListCache.has(cacheKey)) return browsersListCache.get(cacheKey);
|
|
17
|
+
const result = browserslist.loadConfig({
|
|
18
|
+
path,
|
|
19
|
+
env
|
|
20
|
+
});
|
|
21
|
+
if (result) {
|
|
22
|
+
browsersListCache.set(cacheKey, result);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const isHtmlDisabled = (config, target)=>{
|
|
28
|
+
const { htmlPlugin } = config.tools;
|
|
29
|
+
return false === htmlPlugin || Array.isArray(htmlPlugin) && htmlPlugin.includes(false) || 'web' !== target;
|
|
30
|
+
};
|
|
31
|
+
const DEFAULT_WEB_BROWSERSLIST = [
|
|
32
|
+
'chrome >= 87',
|
|
33
|
+
'edge >= 88',
|
|
34
|
+
'firefox >= 78',
|
|
35
|
+
'safari >= 14'
|
|
36
|
+
];
|
|
37
|
+
const DEFAULT_BROWSERSLIST = {
|
|
38
|
+
web: DEFAULT_WEB_BROWSERSLIST,
|
|
39
|
+
node: [
|
|
40
|
+
'node >= 16'
|
|
41
|
+
],
|
|
42
|
+
'web-worker': DEFAULT_WEB_BROWSERSLIST
|
|
43
|
+
};
|
|
44
|
+
async function getBrowserslistWithDefault(path, config, target) {
|
|
45
|
+
const { overrideBrowserslist: overrides } = config?.output || {};
|
|
46
|
+
if ('web' === target || 'web-worker' === target) {
|
|
47
|
+
if (overrides) return overrides;
|
|
48
|
+
const browserslistrc = await getBrowserslist(path);
|
|
49
|
+
if (browserslistrc) return browserslistrc;
|
|
50
|
+
}
|
|
51
|
+
return DEFAULT_BROWSERSLIST[target];
|
|
52
|
+
}
|
|
53
|
+
export { NODE_MODULES_REGEX, RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, getBrowserslistWithDefault, isHtmlDisabled };
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
4
|
+
import { rsbuildRscPlugin } from "./rsc/plugins/rsbuild-rsc-plugin.mjs";
|
|
5
|
+
import { parseCommonConfig } from "./shared/parseCommonConfig.mjs";
|
|
6
|
+
import { rscClientBrowserFallbackPlugin } from "./shared/rsc/rscClientBrowserFallback.mjs";
|
|
7
|
+
async function parseConfig(builderConfig, options) {
|
|
8
|
+
builderConfig.performance ??= {};
|
|
9
|
+
builderConfig.performance.buildCache ??= true;
|
|
10
|
+
const { rsbuildConfig, rsbuildPlugins } = await parseCommonConfig(builderConfig, options);
|
|
11
|
+
const { sri } = builderConfig.security || {};
|
|
12
|
+
if (sri) if (true === sri) rsbuildConfig.security.sri = {
|
|
13
|
+
enable: 'auto'
|
|
14
|
+
};
|
|
15
|
+
else {
|
|
16
|
+
const algorithm = Array.isArray(sri.hashFuncNames) ? sri.hashFuncNames[0] : void 0;
|
|
17
|
+
rsbuildConfig.security.sri = {
|
|
18
|
+
enable: sri.enabled,
|
|
19
|
+
algorithm
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (false === Boolean(rsbuildConfig.tools.lightningcssLoader)) {
|
|
23
|
+
const { pluginPostcss } = await import("./plugins/postcss.mjs");
|
|
24
|
+
rsbuildPlugins.push(pluginPostcss({
|
|
25
|
+
autoprefixer: builderConfig.tools?.autoprefixer
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const enableRsc = builderConfig.server?.rsc ?? false;
|
|
29
|
+
if (enableRsc) {
|
|
30
|
+
const { rscClientRuntimePath, rscServerRuntimePath, internalDirectory } = options;
|
|
31
|
+
rsbuildPlugins.push(rsbuildRscPlugin({
|
|
32
|
+
appDir: options.cwd,
|
|
33
|
+
rscClientRuntimePath,
|
|
34
|
+
rscServerRuntimePath,
|
|
35
|
+
internalDirectory
|
|
36
|
+
}));
|
|
37
|
+
} else rsbuildPlugins.push(rscClientBrowserFallbackPlugin());
|
|
38
|
+
return {
|
|
39
|
+
rsbuildConfig,
|
|
40
|
+
rsbuildPlugins
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function createRspackBuilder(options) {
|
|
44
|
+
const { cwd = process.cwd(), config, ...rest } = options;
|
|
45
|
+
const { rsbuildConfig, rsbuildPlugins } = await parseConfig(config, {
|
|
46
|
+
...rest,
|
|
47
|
+
cwd
|
|
48
|
+
});
|
|
49
|
+
rsbuildConfig.plugins = [
|
|
50
|
+
...rsbuildPlugins,
|
|
51
|
+
...rsbuildConfig.plugins || []
|
|
52
|
+
];
|
|
53
|
+
const rsbuild = await createRsbuild({
|
|
54
|
+
cwd,
|
|
55
|
+
rsbuildConfig
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
...rsbuild
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export { createRspackBuilder, parseConfig };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { createRspackBuilder, parseConfig } from "./createBuilder.mjs";
|
|
4
|
+
import { logger } from "@rsbuild/core";
|
|
5
|
+
import { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, isHtmlDisabled } from "./shared/utils.mjs";
|
|
6
|
+
export { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, createRspackBuilder as createBuilder, isHtmlDisabled, logger, parseConfig as parseRspackConfig };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
const pluginDevtool = (options)=>({
|
|
4
|
+
name: 'builder:devtool',
|
|
5
|
+
setup (api) {
|
|
6
|
+
const devtoolJs = 'boolean' == typeof options.sourceMap || options.sourceMap?.js !== void 0;
|
|
7
|
+
if (devtoolJs) return;
|
|
8
|
+
api.modifyBundlerChain((chain, { isProd, isServer })=>{
|
|
9
|
+
const prodDevTool = isServer ? 'source-map' : 'hidden-source-map';
|
|
10
|
+
const devtool = isProd ? prodDevTool : 'cheap-module-source-map';
|
|
11
|
+
chain.devtool(devtool);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export { pluginDevtool };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
async function isFileExists(file) {
|
|
6
|
+
return node_fs.promises.access(file, node_fs.constants.F_OK).then(()=>true).catch(()=>false);
|
|
7
|
+
}
|
|
8
|
+
const pluginEmitRouteFile = ()=>({
|
|
9
|
+
name: 'builder:emit-route-file',
|
|
10
|
+
setup (api) {
|
|
11
|
+
api.onBeforeStartDevServer(async ({ environments })=>{
|
|
12
|
+
const { fs, ROUTE_SPEC_FILE } = await import("@modern-js/utils");
|
|
13
|
+
const routeFilePath = join(api.context.distPath, ROUTE_SPEC_FILE);
|
|
14
|
+
const htmlPaths = Object.values(environments).reduce((prev, curr)=>({
|
|
15
|
+
...prev,
|
|
16
|
+
...curr.htmlPaths
|
|
17
|
+
}), {});
|
|
18
|
+
const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index)=>({
|
|
19
|
+
urlPath: 0 === index ? '/' : `/${entryName}`,
|
|
20
|
+
entryName,
|
|
21
|
+
entryPath: filename,
|
|
22
|
+
isSPA: true
|
|
23
|
+
}));
|
|
24
|
+
if (!await isFileExists(routeFilePath) && routesInfo.length) await fs.outputFile(routeFilePath, JSON.stringify({
|
|
25
|
+
routes: routesInfo
|
|
26
|
+
}, null, 2));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
export { isFileExists, pluginEmitRouteFile };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { SERVICE_WORKER_ENVIRONMENT_NAME, getBrowserslistWithDefault } from "../shared/utils.mjs";
|
|
5
|
+
const pluginEnvironmentDefaults = (distPath = {})=>({
|
|
6
|
+
name: 'builder:environment-defaults-plugin',
|
|
7
|
+
setup (api) {
|
|
8
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
|
|
9
|
+
const compatConfig = {};
|
|
10
|
+
if (config.environments?.[SERVICE_WORKER_ENVIRONMENT_NAME]) {
|
|
11
|
+
compatConfig.environments ??= {};
|
|
12
|
+
compatConfig.environments[SERVICE_WORKER_ENVIRONMENT_NAME] = {
|
|
13
|
+
output: {
|
|
14
|
+
polyfill: 'off',
|
|
15
|
+
distPath: {
|
|
16
|
+
root: join(distPath.root || 'dist', distPath.worker || 'worker'),
|
|
17
|
+
js: '',
|
|
18
|
+
css: '',
|
|
19
|
+
jsAsync: '',
|
|
20
|
+
cssAsync: ''
|
|
21
|
+
},
|
|
22
|
+
filename: {
|
|
23
|
+
js: '[name].js'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (config.environments?.node) {
|
|
29
|
+
compatConfig.environments ??= {};
|
|
30
|
+
compatConfig.environments.node = {
|
|
31
|
+
output: {
|
|
32
|
+
emitAssets: false,
|
|
33
|
+
distPath: {
|
|
34
|
+
root: join(distPath.root || 'dist', distPath.server || 'bundles'),
|
|
35
|
+
js: '',
|
|
36
|
+
css: '',
|
|
37
|
+
jsAsync: '',
|
|
38
|
+
cssAsync: ''
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return compatConfig.environments ? mergeRsbuildConfig(compatConfig, config) : config;
|
|
44
|
+
});
|
|
45
|
+
api.modifyRsbuildConfig({
|
|
46
|
+
handler: (config)=>{
|
|
47
|
+
const environmentNameOrder = [
|
|
48
|
+
'web',
|
|
49
|
+
'node',
|
|
50
|
+
'workerSSR'
|
|
51
|
+
];
|
|
52
|
+
config.environments = Object.fromEntries(Object.entries(config.environments).sort((a1, a2)=>environmentNameOrder.includes(a1[0]) ? environmentNameOrder.indexOf(a1[0]) - environmentNameOrder.indexOf(a2[0]) : 1));
|
|
53
|
+
},
|
|
54
|
+
order: 'post'
|
|
55
|
+
});
|
|
56
|
+
api.modifyEnvironmentConfig(async (config, { name })=>{
|
|
57
|
+
config.output.overrideBrowserslist ??= await getBrowserslistWithDefault(api.context.rootPath, config, name === SERVICE_WORKER_ENVIRONMENT_NAME ? 'node' : config.output.target);
|
|
58
|
+
});
|
|
59
|
+
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
60
|
+
const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
|
|
61
|
+
if (isServiceWorker) chain.output.library({
|
|
62
|
+
...chain.output.get('library') || {},
|
|
63
|
+
type: 'commonjs2'
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
export { pluginEnvironmentDefaults };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
4
|
+
const pluginGlobalVars = (options)=>({
|
|
5
|
+
name: 'builder:global-vars',
|
|
6
|
+
setup (api) {
|
|
7
|
+
api.modifyBundlerChain((chain, { env, target, bundler })=>{
|
|
8
|
+
if (!options) return;
|
|
9
|
+
const globalVars = applyOptionsChain({}, options, {
|
|
10
|
+
env,
|
|
11
|
+
target
|
|
12
|
+
});
|
|
13
|
+
const serializedVars = {};
|
|
14
|
+
Object.entries(globalVars).forEach(([key, value])=>{
|
|
15
|
+
serializedVars[key] = JSON.stringify(value) ?? 'undefined';
|
|
16
|
+
});
|
|
17
|
+
chain.plugin('globalVars').use(bundler.DefinePlugin, [
|
|
18
|
+
serializedVars
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
export { pluginGlobalVars };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { merge } from "ts-deepmerge";
|
|
4
|
+
function applyRemoveConsole(options, config) {
|
|
5
|
+
const { removeConsole } = config.performance;
|
|
6
|
+
const compressOptions = 'boolean' == typeof options.compress ? {} : options.compress || {};
|
|
7
|
+
if (true === removeConsole) options.compress = {
|
|
8
|
+
...compressOptions,
|
|
9
|
+
drop_console: true
|
|
10
|
+
};
|
|
11
|
+
else if (Array.isArray(removeConsole)) {
|
|
12
|
+
const pureFuncs = removeConsole.map((method)=>`console.${method}`);
|
|
13
|
+
options.compress = {
|
|
14
|
+
...compressOptions,
|
|
15
|
+
pure_funcs: pureFuncs
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return options;
|
|
19
|
+
}
|
|
20
|
+
function getTerserMinifyOptions(config) {
|
|
21
|
+
const options = {
|
|
22
|
+
mangle: {
|
|
23
|
+
safari10: true
|
|
24
|
+
},
|
|
25
|
+
format: {
|
|
26
|
+
ascii_only: 'ascii' === config.output.charset
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if ('none' === config.output.legalComments) {
|
|
30
|
+
options.format ||= {};
|
|
31
|
+
options.format.comments = false;
|
|
32
|
+
}
|
|
33
|
+
const finalOptions = applyRemoveConsole(options, config);
|
|
34
|
+
return finalOptions;
|
|
35
|
+
}
|
|
36
|
+
function getMinifyOptions(config) {
|
|
37
|
+
const minifyJS = getTerserMinifyOptions(config);
|
|
38
|
+
return {
|
|
39
|
+
removeComments: false,
|
|
40
|
+
useShortDoctype: true,
|
|
41
|
+
keepClosingSlash: true,
|
|
42
|
+
collapseWhitespace: true,
|
|
43
|
+
removeRedundantAttributes: true,
|
|
44
|
+
removeScriptTypeAttributes: true,
|
|
45
|
+
removeStyleLinkTypeAttributes: true,
|
|
46
|
+
removeEmptyAttributes: true,
|
|
47
|
+
minifyJS,
|
|
48
|
+
minifyCSS: true,
|
|
49
|
+
minifyURLs: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const pluginHtmlMinifierTerser = ()=>({
|
|
53
|
+
name: 'builder:plugin-html-minifier-terser',
|
|
54
|
+
setup (api) {
|
|
55
|
+
api.modifyBundlerChain(async (chain, { isProd, environment })=>{
|
|
56
|
+
const { output, tools: { htmlPlugin } } = environment.config;
|
|
57
|
+
const disableHtmlMinify = !isProd || false === output.minify || false === htmlPlugin;
|
|
58
|
+
const { minify } = await import("html-minifier-terser");
|
|
59
|
+
const pluginRecord = chain.plugins.entries();
|
|
60
|
+
const minifyOptions = getMinifyOptions(environment.config);
|
|
61
|
+
for (const id of Object.keys(pluginRecord)){
|
|
62
|
+
if (!id.startsWith('html-')) continue;
|
|
63
|
+
const values = pluginRecord[id].values();
|
|
64
|
+
const isHtmlRspackPlugin = values.some((item)=>{
|
|
65
|
+
const name = item?.name || item.constructor?.name;
|
|
66
|
+
return 'HtmlRspackPlugin' === name;
|
|
67
|
+
});
|
|
68
|
+
if (isHtmlRspackPlugin && !disableHtmlMinify) {
|
|
69
|
+
chain.plugin(id).tap((options)=>{
|
|
70
|
+
if (!options.length) return options;
|
|
71
|
+
const userMinifyOption = options[0].minify;
|
|
72
|
+
if (false === userMinifyOption) return options;
|
|
73
|
+
const minifyFn = (html)=>minify(html, userMinifyOption ? merge(minifyOptions, userMinifyOption) : minifyOptions);
|
|
74
|
+
options[0].minify = minifyFn;
|
|
75
|
+
return options;
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
export { pluginHtmlMinifierTerser };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { generateManifest } from "../shared/manifest.mjs";
|
|
4
|
+
const pluginManifest = ()=>({
|
|
5
|
+
name: 'builder:manifest',
|
|
6
|
+
setup (api) {
|
|
7
|
+
api.modifyBundlerChain(async (chain, { target, CHAIN_ID })=>{
|
|
8
|
+
const { RspackManifestPlugin } = await import("rspack-manifest-plugin");
|
|
9
|
+
const publicPath = chain.output.get('publicPath');
|
|
10
|
+
chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
|
|
11
|
+
{
|
|
12
|
+
fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
|
|
13
|
+
publicPath,
|
|
14
|
+
generate: generateManifest
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
export { pluginManifest };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { applyOptionsChain, isProd } from "@modern-js/utils";
|
|
6
|
+
import { getCssSupport } from "../shared/getCssSupport.mjs";
|
|
7
|
+
const postcss_require = createRequire(import.meta.url);
|
|
8
|
+
const importPostcssPlugin = (name)=>Promise.resolve(postcss_require(name));
|
|
9
|
+
const userPostcssrcCache = new Map();
|
|
10
|
+
const clonePostCSSConfig = (config)=>({
|
|
11
|
+
...config,
|
|
12
|
+
plugins: config.plugins ? [
|
|
13
|
+
...config.plugins
|
|
14
|
+
] : void 0
|
|
15
|
+
});
|
|
16
|
+
async function loadUserPostcssrc(root) {
|
|
17
|
+
const cached = userPostcssrcCache.get(root);
|
|
18
|
+
if (cached) return clonePostCSSConfig(await cached);
|
|
19
|
+
const compiledPath = postcss_require.resolve('../../compiled/postcss-load-config');
|
|
20
|
+
const { default: postcssrc } = await import(pathToFileURL(compiledPath).href);
|
|
21
|
+
const promise = postcssrc({}, root).catch((err)=>{
|
|
22
|
+
if (err.message?.includes('No PostCSS Config found')) return {};
|
|
23
|
+
throw err;
|
|
24
|
+
});
|
|
25
|
+
userPostcssrcCache.set(root, promise);
|
|
26
|
+
return promise.then((config)=>{
|
|
27
|
+
userPostcssrcCache.set(root, config);
|
|
28
|
+
return clonePostCSSConfig(config);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const pluginPostcss = (options = {})=>({
|
|
32
|
+
name: 'builder:postcss-plugins',
|
|
33
|
+
pre: [
|
|
34
|
+
'builder:environment-defaults-plugin'
|
|
35
|
+
],
|
|
36
|
+
setup (api) {
|
|
37
|
+
const { autoprefixer } = options;
|
|
38
|
+
api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig })=>{
|
|
39
|
+
if ('web' !== config.output.target) return config;
|
|
40
|
+
const cssSupport = getCssSupport(config.output.overrideBrowserslist);
|
|
41
|
+
const enableExtractCSS = !config.output?.injectStyles;
|
|
42
|
+
const enableCssMinify = !enableExtractCSS && isProd();
|
|
43
|
+
const cssnanoOptions = {
|
|
44
|
+
preset: [
|
|
45
|
+
'default',
|
|
46
|
+
{
|
|
47
|
+
mergeLonghand: false,
|
|
48
|
+
normalizeUrl: false
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const plugins = await Promise.all([
|
|
53
|
+
importPostcssPlugin('postcss-flexbugs-fixes'),
|
|
54
|
+
!cssSupport.customProperties && importPostcssPlugin('postcss-custom-properties'),
|
|
55
|
+
!cssSupport.initial && importPostcssPlugin('postcss-initial'),
|
|
56
|
+
!cssSupport.pageBreak && importPostcssPlugin('postcss-page-break'),
|
|
57
|
+
!cssSupport.fontVariant && importPostcssPlugin('postcss-font-variant'),
|
|
58
|
+
!cssSupport.mediaMinmax && importPostcssPlugin('postcss-media-minmax'),
|
|
59
|
+
importPostcssPlugin('postcss-nesting'),
|
|
60
|
+
enableCssMinify && importPostcssPlugin('cssnano').then((cssnano)=>cssnano(cssnanoOptions)),
|
|
61
|
+
importPostcssPlugin('autoprefixer').then((autoprefixerPlugin)=>autoprefixerPlugin(applyOptionsChain({
|
|
62
|
+
flexbox: 'no-2009',
|
|
63
|
+
overrideBrowserslist: config.output.overrideBrowserslist
|
|
64
|
+
}, autoprefixer)))
|
|
65
|
+
]).then((results)=>results.filter(Boolean));
|
|
66
|
+
const userOptions = await loadUserPostcssrc(api.context.rootPath);
|
|
67
|
+
return mergeEnvironmentConfig({
|
|
68
|
+
tools: {
|
|
69
|
+
postcss: {
|
|
70
|
+
postcssOptions: {
|
|
71
|
+
...userOptions,
|
|
72
|
+
plugins: [
|
|
73
|
+
...userOptions.plugins || [],
|
|
74
|
+
...plugins
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, config);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
export { pluginPostcss };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX } from "../shared/utils.mjs";
|
|
4
|
+
const pluginRuntimeChunk = (disableInlineRuntimeChunk)=>({
|
|
5
|
+
name: 'builder:runtime-chunk',
|
|
6
|
+
setup (api) {
|
|
7
|
+
api.modifyBundlerChain(async (chain, { target, environment })=>{
|
|
8
|
+
if ('web' !== target) return;
|
|
9
|
+
const { config } = environment;
|
|
10
|
+
const { chunkSplit } = config.performance;
|
|
11
|
+
if (chunkSplit?.strategy !== 'all-in-one' && false !== config.splitChunks) chain.optimization.runtimeChunk({
|
|
12
|
+
name: RUNTIME_CHUNK_NAME
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
api.modifyRsbuildConfig((config)=>{
|
|
16
|
+
config.output ||= {};
|
|
17
|
+
if (disableInlineRuntimeChunk) return;
|
|
18
|
+
if (!config.output.inlineScripts) config.output.inlineScripts = RUNTIME_CHUNK_REGEX;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export { pluginRuntimeChunk };
|