@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,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
8
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: definition[key]
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
16
|
+
})();
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.r = (exports1)=>{
|
|
19
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
20
|
+
value: 'Module'
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
var __webpack_exports__ = {};
|
|
28
|
+
__webpack_require__.r(__webpack_exports__);
|
|
29
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
30
|
+
pluginPostcss: ()=>pluginPostcss
|
|
31
|
+
});
|
|
32
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
33
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
34
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
35
|
+
const getCssSupport_js_namespaceObject = require("../shared/getCssSupport.js");
|
|
36
|
+
const postcss_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
37
|
+
const importPostcssPlugin = (name)=>Promise.resolve(postcss_require(name));
|
|
38
|
+
const userPostcssrcCache = new Map();
|
|
39
|
+
const clonePostCSSConfig = (config)=>({
|
|
40
|
+
...config,
|
|
41
|
+
plugins: config.plugins ? [
|
|
42
|
+
...config.plugins
|
|
43
|
+
] : void 0
|
|
44
|
+
});
|
|
45
|
+
async function loadUserPostcssrc(root) {
|
|
46
|
+
const cached = userPostcssrcCache.get(root);
|
|
47
|
+
if (cached) return clonePostCSSConfig(await cached);
|
|
48
|
+
const compiledPath = postcss_require.resolve('../../compiled/postcss-load-config');
|
|
49
|
+
const { default: postcssrc } = await import((0, external_node_url_namespaceObject.pathToFileURL)(compiledPath).href);
|
|
50
|
+
const promise = postcssrc({}, root).catch((err)=>{
|
|
51
|
+
if (err.message?.includes('No PostCSS Config found')) return {};
|
|
52
|
+
throw err;
|
|
53
|
+
});
|
|
54
|
+
userPostcssrcCache.set(root, promise);
|
|
55
|
+
return promise.then((config)=>{
|
|
56
|
+
userPostcssrcCache.set(root, config);
|
|
57
|
+
return clonePostCSSConfig(config);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const pluginPostcss = (options = {})=>({
|
|
61
|
+
name: 'builder:postcss-plugins',
|
|
62
|
+
pre: [
|
|
63
|
+
'builder:environment-defaults-plugin'
|
|
64
|
+
],
|
|
65
|
+
setup (api) {
|
|
66
|
+
const { autoprefixer } = options;
|
|
67
|
+
api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig })=>{
|
|
68
|
+
if ('web' !== config.output.target) return config;
|
|
69
|
+
const cssSupport = (0, getCssSupport_js_namespaceObject.getCssSupport)(config.output.overrideBrowserslist);
|
|
70
|
+
const enableExtractCSS = !config.output?.injectStyles;
|
|
71
|
+
const enableCssMinify = !enableExtractCSS && (0, utils_namespaceObject.isProd)();
|
|
72
|
+
const cssnanoOptions = {
|
|
73
|
+
preset: [
|
|
74
|
+
'default',
|
|
75
|
+
{
|
|
76
|
+
mergeLonghand: false,
|
|
77
|
+
normalizeUrl: false
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
const plugins = await Promise.all([
|
|
82
|
+
importPostcssPlugin('postcss-flexbugs-fixes'),
|
|
83
|
+
!cssSupport.customProperties && importPostcssPlugin('postcss-custom-properties'),
|
|
84
|
+
!cssSupport.initial && importPostcssPlugin('postcss-initial'),
|
|
85
|
+
!cssSupport.pageBreak && importPostcssPlugin('postcss-page-break'),
|
|
86
|
+
!cssSupport.fontVariant && importPostcssPlugin('postcss-font-variant'),
|
|
87
|
+
!cssSupport.mediaMinmax && importPostcssPlugin('postcss-media-minmax'),
|
|
88
|
+
importPostcssPlugin('postcss-nesting'),
|
|
89
|
+
enableCssMinify && importPostcssPlugin('cssnano').then((cssnano)=>cssnano(cssnanoOptions)),
|
|
90
|
+
importPostcssPlugin('autoprefixer').then((autoprefixerPlugin)=>autoprefixerPlugin((0, utils_namespaceObject.applyOptionsChain)({
|
|
91
|
+
flexbox: 'no-2009',
|
|
92
|
+
overrideBrowserslist: config.output.overrideBrowserslist
|
|
93
|
+
}, autoprefixer)))
|
|
94
|
+
]).then((results)=>results.filter(Boolean));
|
|
95
|
+
const userOptions = await loadUserPostcssrc(api.context.rootPath);
|
|
96
|
+
return mergeEnvironmentConfig({
|
|
97
|
+
tools: {
|
|
98
|
+
postcss: {
|
|
99
|
+
postcssOptions: {
|
|
100
|
+
...userOptions,
|
|
101
|
+
plugins: [
|
|
102
|
+
...userOptions.plugins || [],
|
|
103
|
+
...plugins
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, config);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
exports.pluginPostcss = __webpack_exports__.pluginPostcss;
|
|
113
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
114
|
+
"pluginPostcss"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
pluginRuntimeChunk: ()=>pluginRuntimeChunk
|
|
28
|
+
});
|
|
29
|
+
const utils_js_namespaceObject = require("../shared/utils.js");
|
|
30
|
+
const pluginRuntimeChunk = (disableInlineRuntimeChunk)=>({
|
|
31
|
+
name: 'builder:runtime-chunk',
|
|
32
|
+
setup (api) {
|
|
33
|
+
api.modifyBundlerChain(async (chain, { target, environment })=>{
|
|
34
|
+
if ('web' !== target) return;
|
|
35
|
+
const { config } = environment;
|
|
36
|
+
const { chunkSplit } = config.performance;
|
|
37
|
+
if (chunkSplit?.strategy !== 'all-in-one' && false !== config.splitChunks) chain.optimization.runtimeChunk({
|
|
38
|
+
name: utils_js_namespaceObject.RUNTIME_CHUNK_NAME
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
api.modifyRsbuildConfig((config)=>{
|
|
42
|
+
config.output ||= {};
|
|
43
|
+
if (disableInlineRuntimeChunk) return;
|
|
44
|
+
if (!config.output.inlineScripts) config.output.inlineScripts = utils_js_namespaceObject.RUNTIME_CHUNK_REGEX;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
exports.pluginRuntimeChunk = __webpack_exports__.pluginRuntimeChunk;
|
|
49
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
50
|
+
"pluginRuntimeChunk"
|
|
51
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
52
|
+
Object.defineProperty(exports, '__esModule', {
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
rspackRscLayerName: ()=>rspackRscLayerName,
|
|
28
|
+
getExportNames: ()=>getExportNames,
|
|
29
|
+
MODERN_RSC_INFO: ()=>MODERN_RSC_INFO,
|
|
30
|
+
isCssModule: ()=>isCssModule,
|
|
31
|
+
findRootIssuer: ()=>findRootIssuer,
|
|
32
|
+
getRscBuildInfo: ()=>getRscBuildInfo,
|
|
33
|
+
parseSource: ()=>parseSource,
|
|
34
|
+
sharedData: ()=>sharedData,
|
|
35
|
+
setBuildInfo: ()=>setBuildInfo,
|
|
36
|
+
isServerModule: ()=>isServerModule,
|
|
37
|
+
isClientModule: ()=>isClientModule,
|
|
38
|
+
removeRscBuildInfo: ()=>removeRscBuildInfo,
|
|
39
|
+
setRscBuildInfo: ()=>setRscBuildInfo
|
|
40
|
+
});
|
|
41
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
42
|
+
const core_namespaceObject = require("@swc/core");
|
|
43
|
+
const rspackRscLayerName = "react-server";
|
|
44
|
+
const MODERN_RSC_INFO = 'modernRscInfo';
|
|
45
|
+
const sharedData = {
|
|
46
|
+
store: new Map(),
|
|
47
|
+
get (key) {
|
|
48
|
+
return this.store.get(key);
|
|
49
|
+
},
|
|
50
|
+
set (key, value) {
|
|
51
|
+
this.store.set(key, value);
|
|
52
|
+
},
|
|
53
|
+
clear () {
|
|
54
|
+
this.store.clear();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function setBuildInfo(mod, property) {
|
|
58
|
+
if (!mod.buildInfo) mod.buildInfo = {};
|
|
59
|
+
Object.assign(mod.buildInfo, property);
|
|
60
|
+
}
|
|
61
|
+
function setRscBuildInfo(mod, property) {
|
|
62
|
+
if (!mod.buildInfo) mod.buildInfo = {};
|
|
63
|
+
const rscBuildInfo = mod.buildInfo[MODERN_RSC_INFO] || {};
|
|
64
|
+
Object.assign(rscBuildInfo, property);
|
|
65
|
+
setBuildInfo(mod, {
|
|
66
|
+
[MODERN_RSC_INFO]: rscBuildInfo
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function removeRscBuildInfo(mod) {
|
|
70
|
+
delete mod.buildInfo?.[MODERN_RSC_INFO];
|
|
71
|
+
}
|
|
72
|
+
function getRscBuildInfo(mod) {
|
|
73
|
+
return mod.buildInfo?.[MODERN_RSC_INFO];
|
|
74
|
+
}
|
|
75
|
+
function isCssModule(mod) {
|
|
76
|
+
if (!mod) return false;
|
|
77
|
+
return getRscBuildInfo(mod)?.isCssModule;
|
|
78
|
+
}
|
|
79
|
+
const parseSource = async (source)=>await (0, core_namespaceObject.parse)(source, {
|
|
80
|
+
syntax: "typescript",
|
|
81
|
+
tsx: true,
|
|
82
|
+
dynamicImport: true
|
|
83
|
+
});
|
|
84
|
+
const getExportNames = async (ast, collectFuncOnly = false)=>{
|
|
85
|
+
const exportNames = [];
|
|
86
|
+
ast.body.forEach((node)=>{
|
|
87
|
+
if ('ExportNamedDeclaration' === node.type) {
|
|
88
|
+
const namedExport = node;
|
|
89
|
+
namedExport.specifiers.forEach((specifier)=>{
|
|
90
|
+
if ('ExportSpecifier' === specifier.type) exportNames.push(specifier.exported?.value || specifier.orig.value);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if ('ExportDeclaration' === node.type) {
|
|
94
|
+
if ('VariableDeclaration' === node.declaration.type) node.declaration.declarations.forEach((decl)=>{
|
|
95
|
+
if ('Identifier' === decl.id.type) if (collectFuncOnly) {
|
|
96
|
+
if (decl.init?.type === 'FunctionExpression' || decl.init?.type === 'ArrowFunctionExpression') exportNames.push(decl.id.value);
|
|
97
|
+
} else exportNames.push(decl.id.value);
|
|
98
|
+
});
|
|
99
|
+
if ('ClassDeclaration' === node.declaration.type || 'FunctionDeclaration' === node.declaration.type) {
|
|
100
|
+
if (node.declaration.identifier) exportNames.push(node.declaration.identifier.value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if ('ExportDefaultExpression' === node.type || 'ExportDefaultDeclaration' === node.type) exportNames.push('default');
|
|
104
|
+
});
|
|
105
|
+
return exportNames;
|
|
106
|
+
};
|
|
107
|
+
const checkDirective = async (ast, directive)=>{
|
|
108
|
+
try {
|
|
109
|
+
for(let i = 0; i < ast.body.length; i++){
|
|
110
|
+
const node = ast.body[i];
|
|
111
|
+
if ('ExpressionStatement' !== node.type) break;
|
|
112
|
+
if ('StringLiteral' === node.expression.type && node.expression.value === directive) return true;
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
utils_namespaceObject.logger.error(e);
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
const isServerModule = async (ast)=>checkDirective(ast, 'use server');
|
|
120
|
+
const isClientModule = async (ast)=>checkDirective(ast, 'use client');
|
|
121
|
+
function findRootIssuer(modulegraph, module) {
|
|
122
|
+
const currentModule = module;
|
|
123
|
+
const issuer = modulegraph.getIssuer(currentModule);
|
|
124
|
+
if (!issuer) return currentModule;
|
|
125
|
+
return findRootIssuer(modulegraph, issuer);
|
|
126
|
+
}
|
|
127
|
+
exports.MODERN_RSC_INFO = __webpack_exports__.MODERN_RSC_INFO;
|
|
128
|
+
exports.findRootIssuer = __webpack_exports__.findRootIssuer;
|
|
129
|
+
exports.getExportNames = __webpack_exports__.getExportNames;
|
|
130
|
+
exports.getRscBuildInfo = __webpack_exports__.getRscBuildInfo;
|
|
131
|
+
exports.isClientModule = __webpack_exports__.isClientModule;
|
|
132
|
+
exports.isCssModule = __webpack_exports__.isCssModule;
|
|
133
|
+
exports.isServerModule = __webpack_exports__.isServerModule;
|
|
134
|
+
exports.parseSource = __webpack_exports__.parseSource;
|
|
135
|
+
exports.removeRscBuildInfo = __webpack_exports__.removeRscBuildInfo;
|
|
136
|
+
exports.rspackRscLayerName = __webpack_exports__.rspackRscLayerName;
|
|
137
|
+
exports.setBuildInfo = __webpack_exports__.setBuildInfo;
|
|
138
|
+
exports.setRscBuildInfo = __webpack_exports__.setRscBuildInfo;
|
|
139
|
+
exports.sharedData = __webpack_exports__.sharedData;
|
|
140
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
141
|
+
"MODERN_RSC_INFO",
|
|
142
|
+
"findRootIssuer",
|
|
143
|
+
"getExportNames",
|
|
144
|
+
"getRscBuildInfo",
|
|
145
|
+
"isClientModule",
|
|
146
|
+
"isCssModule",
|
|
147
|
+
"isServerModule",
|
|
148
|
+
"parseSource",
|
|
149
|
+
"removeRscBuildInfo",
|
|
150
|
+
"rspackRscLayerName",
|
|
151
|
+
"setBuildInfo",
|
|
152
|
+
"setRscBuildInfo",
|
|
153
|
+
"sharedData"
|
|
154
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
155
|
+
Object.defineProperty(exports, '__esModule', {
|
|
156
|
+
value: true
|
|
157
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
rsbuildRscPlugin: ()=>rsbuildRscPlugin
|
|
37
|
+
});
|
|
38
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
39
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
40
|
+
const fs_extra_namespaceObject = require("@modern-js/utils/fs-extra");
|
|
41
|
+
var fs_extra_default = /*#__PURE__*/ __webpack_require__.n(fs_extra_namespaceObject);
|
|
42
|
+
const core_namespaceObject = require("@rsbuild/core");
|
|
43
|
+
const external_common_js_namespaceObject = require("../common.js");
|
|
44
|
+
const external_rspack_rsc_client_plugin_js_namespaceObject = require("./rspack-rsc-client-plugin.js");
|
|
45
|
+
const external_rspack_rsc_server_plugin_js_namespaceObject = require("./rspack-rsc-server-plugin.js");
|
|
46
|
+
const CSS_RULE_NAMES = [
|
|
47
|
+
'less',
|
|
48
|
+
'css',
|
|
49
|
+
'scss',
|
|
50
|
+
'sass'
|
|
51
|
+
];
|
|
52
|
+
const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
|
|
53
|
+
const checkReactVersionAtLeast19 = async (appDir)=>{
|
|
54
|
+
const packageJsonPath = external_node_path_default().resolve(appDir, 'package.json');
|
|
55
|
+
const packageJson = await fs_extra_default().readJSON(packageJsonPath);
|
|
56
|
+
if (!packageJson.dependencies) return false;
|
|
57
|
+
const { dependencies } = packageJson;
|
|
58
|
+
const reactVersion = dependencies.react;
|
|
59
|
+
const reactDomVersion = dependencies['react-dom'];
|
|
60
|
+
if (!reactVersion || !reactDomVersion) return false;
|
|
61
|
+
const cleanVersion = (version)=>version.replace(/[\^~]/g, '');
|
|
62
|
+
const reactVersionParts = cleanVersion(reactVersion).split('.');
|
|
63
|
+
const reactDomVersionParts = cleanVersion(reactDomVersion).split('.');
|
|
64
|
+
const reactMajor = parseInt(reactVersionParts[0], 10);
|
|
65
|
+
const reactDomMajor = parseInt(reactDomVersionParts[0], 10);
|
|
66
|
+
if (Number.isNaN(reactMajor) || Number.isNaN(reactDomMajor)) return false;
|
|
67
|
+
return reactMajor >= 19 && reactDomMajor >= 19;
|
|
68
|
+
};
|
|
69
|
+
const rsbuildRscPlugin = ({ appDir, rscClientRuntimePath, rscServerRuntimePath, internalDirectory })=>({
|
|
70
|
+
name: 'builder:rsc-rsbuild-plugin',
|
|
71
|
+
setup (api) {
|
|
72
|
+
api.modifyBundlerChain({
|
|
73
|
+
handler: async (chain, { isServer, CHAIN_ID, isWebWorker })=>{
|
|
74
|
+
if (!await checkReactVersionAtLeast19(appDir)) {
|
|
75
|
+
core_namespaceObject.logger.error('Enable react server component, please make sure the react and react-dom versions are greater than or equal to 19.0.0');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const entryPath2Name = new Map();
|
|
79
|
+
for (const [name, entry] of Object.entries(chain.entryPoints.entries()))entry.values().forEach((value)=>{
|
|
80
|
+
entryPath2Name.set(value, name);
|
|
81
|
+
});
|
|
82
|
+
const jsHandler = ()=>{
|
|
83
|
+
const originalJsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
|
|
84
|
+
if (!originalJsRule) throw new Error('Original JS rule not found when setup RSC plugin.');
|
|
85
|
+
const originalJsMainRule = originalJsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
86
|
+
if (!originalJsMainRule) throw new Error('Original JS main rule not found when setup RSC plugin.');
|
|
87
|
+
const useBabel = originalJsMainRule.uses.has(CHAIN_ID.USE.BABEL);
|
|
88
|
+
const jsLoader = useBabel ? CHAIN_ID.USE.BABEL : CHAIN_ID.USE.SWC;
|
|
89
|
+
const jsLoaderOptions = originalJsMainRule.use(jsLoader).get('options');
|
|
90
|
+
const jsLoaderPath = originalJsMainRule.use(jsLoader).get('loader');
|
|
91
|
+
originalJsRule.oneOfs.delete(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
92
|
+
chain.module.rule(CHAIN_ID.RULE.JS).oneOf('rsc-server').issuerLayer(external_common_js_namespaceObject.rspackRscLayerName).exclude.add(/universal[/\\]async_storage/).end().use('rsc-server-loader').loader(require.resolve('../rsc-server-loader')).options({
|
|
93
|
+
entryPath2Name,
|
|
94
|
+
appDir,
|
|
95
|
+
runtimePath: rscServerRuntimePath,
|
|
96
|
+
internalDirectory
|
|
97
|
+
}).end().use(jsLoader).loader(jsLoaderPath).options(jsLoaderOptions).end().end().oneOf('rsc-ssr').exclude.add(/universal[/\\]async_storage/).end().use('rsc-ssr-loader').loader(require.resolve('../rsc-ssr-loader')).options({
|
|
98
|
+
entryPath2Name,
|
|
99
|
+
internalDirectory
|
|
100
|
+
}).end().use(jsLoader).loader(jsLoaderPath).options(jsLoaderOptions).end().end();
|
|
101
|
+
};
|
|
102
|
+
const layerHandler = ()=>{
|
|
103
|
+
const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
|
|
104
|
+
chain.module.rule('server-module').resource([
|
|
105
|
+
/render[/\\].*[/\\]server[/\\]rsc/,
|
|
106
|
+
/AppProxy/,
|
|
107
|
+
routesFileReg
|
|
108
|
+
]).layer(external_common_js_namespaceObject.rspackRscLayerName).end();
|
|
109
|
+
chain.module.rule(external_common_js_namespaceObject.rspackRscLayerName).issuerLayer(external_common_js_namespaceObject.rspackRscLayerName).resolve.conditionNames.add(external_common_js_namespaceObject.rspackRscLayerName).add('...');
|
|
110
|
+
chain.module.rule('rsc-common').resource([
|
|
111
|
+
/universal[/\\]async_storage/
|
|
112
|
+
]).layer('rsc-common');
|
|
113
|
+
};
|
|
114
|
+
const flightCssHandler = ()=>{
|
|
115
|
+
CSS_RULE_NAMES.forEach((ruleName)=>{
|
|
116
|
+
const rule = chain.module.rules.get(ruleName);
|
|
117
|
+
if (rule) chain.module.rule(ruleName).use('custom-loader').before('ignore-css').loader(require.resolve('../rsc-css-loader'));
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
const addServerRscPlugin = ()=>{
|
|
121
|
+
const ServerPlugin = external_rspack_rsc_server_plugin_js_namespaceObject.RscServerPlugin;
|
|
122
|
+
chain.plugin('rsc-server-plugin').use(ServerPlugin, [
|
|
123
|
+
{
|
|
124
|
+
entryPath2Name
|
|
125
|
+
}
|
|
126
|
+
]);
|
|
127
|
+
};
|
|
128
|
+
const addRscClientLoader = ()=>{
|
|
129
|
+
chain.module.rule('js').use('rsc-client-loader').loader(require.resolve('../rsc-client-loader')).before('babel').options({
|
|
130
|
+
callServerImport: rscClientRuntimePath,
|
|
131
|
+
registerImport: rscClientRuntimePath
|
|
132
|
+
}).end();
|
|
133
|
+
};
|
|
134
|
+
const addRscClientPlugin = ()=>{
|
|
135
|
+
const ClientPlugin = external_rspack_rsc_client_plugin_js_namespaceObject.RspackRscClientPlugin;
|
|
136
|
+
chain.plugin('rsc-client-plugin').use(ClientPlugin);
|
|
137
|
+
};
|
|
138
|
+
if (isServer) {
|
|
139
|
+
chain.name('server');
|
|
140
|
+
layerHandler();
|
|
141
|
+
flightCssHandler();
|
|
142
|
+
jsHandler();
|
|
143
|
+
addServerRscPlugin();
|
|
144
|
+
} else if (!isWebWorker) {
|
|
145
|
+
chain.name('client');
|
|
146
|
+
chain.dependencies([
|
|
147
|
+
'server'
|
|
148
|
+
]);
|
|
149
|
+
const entries = chain.entryPoints.entries();
|
|
150
|
+
for (const entryName of Object.keys(entries)){
|
|
151
|
+
const entryPoint = chain.entry(entryName);
|
|
152
|
+
const code = `window.__MODERN_JS_ENTRY_NAME="${entryName}";`;
|
|
153
|
+
entryPoint.add(createVirtualModule(code));
|
|
154
|
+
}
|
|
155
|
+
addRscClientLoader();
|
|
156
|
+
addRscClientPlugin();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
order: 'post'
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
exports.rsbuildRscPlugin = __webpack_exports__.rsbuildRscPlugin;
|
|
164
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
165
|
+
"rsbuildRscPlugin"
|
|
166
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
167
|
+
Object.defineProperty(exports, '__esModule', {
|
|
168
|
+
value: true
|
|
169
|
+
});
|