@modern-js/builder 3.0.1 → 3.0.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 +3 -8
- package/dist/cjs/plugins/environmentDefaults.js +4 -4
- package/dist/cjs/plugins/rscConfig.js +159 -0
- package/dist/cjs/{rsc/rsc-css-loader.js → shared/rsc/rsc-server-entry-loader.js} +6 -7
- package/dist/esm/createBuilder.mjs +3 -8
- package/dist/esm/plugins/environmentDefaults.mjs +4 -4
- package/dist/esm/plugins/rscConfig.mjs +112 -0
- package/dist/esm/shared/rsc/rsc-server-entry-loader.mjs +7 -0
- package/dist/esm-node/createBuilder.mjs +3 -8
- package/dist/esm-node/plugins/environmentDefaults.mjs +4 -4
- package/dist/esm-node/plugins/rscConfig.mjs +117 -0
- package/dist/esm-node/shared/rsc/rsc-server-entry-loader.mjs +8 -0
- package/dist/types/plugins/rscConfig.d.ts +18 -0
- package/dist/types/shared/rsc/rsc-server-entry-loader.d.ts +5 -0
- package/package.json +7 -7
- package/dist/cjs/rsc/common.js +0 -157
- package/dist/cjs/rsc/plugins/rsbuild-rsc-plugin.js +0 -169
- package/dist/cjs/rsc/plugins/rspack-rsc-client-plugin.js +0 -187
- package/dist/cjs/rsc/plugins/rspack-rsc-server-plugin.js +0 -245
- package/dist/cjs/rsc/rsc-client-loader.js +0 -71
- package/dist/cjs/rsc/rsc-server-loader.js +0 -102
- package/dist/cjs/rsc/rsc-ssr-loader.js +0 -60
- package/dist/esm/rsc/common.mjs +0 -87
- package/dist/esm/rsc/plugins/rsbuild-rsc-plugin.mjs +0 -124
- package/dist/esm/rsc/plugins/rspack-rsc-client-plugin.mjs +0 -143
- package/dist/esm/rsc/plugins/rspack-rsc-server-plugin.mjs +0 -211
- package/dist/esm/rsc/rsc-client-loader.mjs +0 -37
- package/dist/esm/rsc/rsc-css-loader.mjs +0 -8
- package/dist/esm/rsc/rsc-server-loader.mjs +0 -58
- package/dist/esm/rsc/rsc-ssr-loader.mjs +0 -26
- package/dist/esm-node/rsc/common.mjs +0 -88
- package/dist/esm-node/rsc/plugins/rsbuild-rsc-plugin.mjs +0 -126
- package/dist/esm-node/rsc/plugins/rspack-rsc-client-plugin.mjs +0 -144
- package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +0 -212
- package/dist/esm-node/rsc/rsc-client-loader.mjs +0 -38
- package/dist/esm-node/rsc/rsc-css-loader.mjs +0 -9
- package/dist/esm-node/rsc/rsc-server-loader.mjs +0 -60
- package/dist/esm-node/rsc/rsc-ssr-loader.mjs +0 -27
- package/dist/types/rsc/common.d.ts +0 -22
- package/dist/types/rsc/plugins/rsbuild-rsc-plugin.d.ts +0 -7
- package/dist/types/rsc/plugins/rspack-rsc-client-plugin.d.ts +0 -14
- package/dist/types/rsc/plugins/rspack-rsc-server-plugin.d.ts +0 -32
- package/dist/types/rsc/rsc-client-loader.d.ts +0 -7
- package/dist/types/rsc/rsc-css-loader.d.ts +0 -2
- package/dist/types/rsc/rsc-server-loader.d.ts +0 -6
- package/dist/types/rsc/rsc-ssr-loader.d.ts +0 -6
package/dist/cjs/rsc/common.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,169 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
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
|
-
RspackRscClientPlugin: ()=>RspackRscClientPlugin
|
|
37
|
-
});
|
|
38
|
-
const external_path_namespaceObject = require("path");
|
|
39
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
40
|
-
const external_common_js_namespaceObject = require("../common.js");
|
|
41
|
-
const hasExtension = (filePath)=>'' !== external_path_default().extname(filePath);
|
|
42
|
-
class RspackRscClientPlugin {
|
|
43
|
-
apply(compiler) {
|
|
44
|
-
const { EntryPlugin, RuntimeGlobals, WebpackError, sources: { RawSource } } = compiler.rspack;
|
|
45
|
-
const ssrManifest = {
|
|
46
|
-
moduleMap: {},
|
|
47
|
-
moduleLoading: null,
|
|
48
|
-
styles: []
|
|
49
|
-
};
|
|
50
|
-
const getEntryModule = (compilation)=>{
|
|
51
|
-
const entryModules = [];
|
|
52
|
-
for (const [, entryValue] of compilation.entries.entries()){
|
|
53
|
-
const entryDependency = entryValue.dependencies[0];
|
|
54
|
-
if (!entryDependency) {
|
|
55
|
-
compilation.errors.push(new WebpackError("Could not find an entry dependency."));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const resolvedModule = compilation.moduleGraph.getModule(entryDependency);
|
|
59
|
-
if (resolvedModule) entryModules.push(resolvedModule);
|
|
60
|
-
}
|
|
61
|
-
if (0 === entryModules.length) {
|
|
62
|
-
compilation.errors.push(new WebpackError("Could not find any entries in the compilation."));
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
return entryModules;
|
|
66
|
-
};
|
|
67
|
-
const addClientReferencesChunks = (compilation, callback)=>{
|
|
68
|
-
const promises = [];
|
|
69
|
-
[
|
|
70
|
-
...this.clientReferencesMap.keys()
|
|
71
|
-
].forEach((resourcePath)=>{
|
|
72
|
-
const entries = compilation.entries.entries();
|
|
73
|
-
for (const [entryName, entry] of entries){
|
|
74
|
-
const runtimeName = entry.options.runtime || entryName;
|
|
75
|
-
if (hasExtension(entryName)) continue;
|
|
76
|
-
const dependency = EntryPlugin.createDependency(resourcePath);
|
|
77
|
-
promises.push(new Promise((resolve, reject)=>{
|
|
78
|
-
compilation.addInclude(compiler.context, dependency, {
|
|
79
|
-
name: entryName
|
|
80
|
-
}, (error, module)=>{
|
|
81
|
-
if (error) reject(error);
|
|
82
|
-
else {
|
|
83
|
-
compilation.moduleGraph.getExportsInfo(module).setUsedInUnknownWay(runtimeName);
|
|
84
|
-
this.dependencies.push(dependency);
|
|
85
|
-
resolve(void 0);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
if (this.styles && this.styles.size > 0) for (const style of this.styles){
|
|
92
|
-
const dependency = EntryPlugin.createDependency(style);
|
|
93
|
-
promises.push(new Promise((resolve, reject)=>{
|
|
94
|
-
compilation.addInclude(compiler.context, dependency, {
|
|
95
|
-
name: void 0
|
|
96
|
-
}, (error, module)=>{
|
|
97
|
-
if (error) reject(error);
|
|
98
|
-
else {
|
|
99
|
-
compilation.moduleGraph.getExportsInfo(module).setUsedInUnknownWay(void 0);
|
|
100
|
-
this.dependencies.push(dependency);
|
|
101
|
-
resolve(void 0);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
Promise.all(promises).then(()=>callback(null)).catch((error)=>callback(error));
|
|
107
|
-
};
|
|
108
|
-
compiler.hooks.finishMake.tapAsync(RspackRscClientPlugin.name, (compilation, callback)=>{
|
|
109
|
-
const entryModules = getEntryModule(compilation);
|
|
110
|
-
for (const entryModule of entryModules)if (entryModule) addClientReferencesChunks(compilation, callback);
|
|
111
|
-
});
|
|
112
|
-
compiler.hooks.thisCompilation.tap(RspackRscClientPlugin.name, (compilation)=>{
|
|
113
|
-
this.styles = external_common_js_namespaceObject.sharedData.get('styles');
|
|
114
|
-
this.clientReferencesMap = external_common_js_namespaceObject.sharedData.get('clientReferencesMap');
|
|
115
|
-
compilation.hooks.additionalTreeRuntimeRequirements.tap(RspackRscClientPlugin.name, (_chunk, runtimeRequirements)=>{
|
|
116
|
-
runtimeRequirements.add(RuntimeGlobals.ensureChunkHandlers);
|
|
117
|
-
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
|
118
|
-
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
|
119
|
-
});
|
|
120
|
-
compilation.hooks.processAssets.tap(RspackRscClientPlugin.name, ()=>{
|
|
121
|
-
const clientManifest = {};
|
|
122
|
-
const { chunkGraph, moduleGraph } = compilation;
|
|
123
|
-
for (const dependency of this.dependencies){
|
|
124
|
-
const module = moduleGraph.getModule(dependency);
|
|
125
|
-
if (!module) continue;
|
|
126
|
-
const resourcePath = module.nameForCondition();
|
|
127
|
-
const clientReferences = resourcePath ? this.clientReferencesMap.get(resourcePath) : void 0;
|
|
128
|
-
if (clientReferences) {
|
|
129
|
-
const moduleId = chunkGraph.getModuleId(module);
|
|
130
|
-
const ssrModuleMetaData = {};
|
|
131
|
-
for (const { id, exportName, ssrId } of clientReferences){
|
|
132
|
-
const clientExportName = exportName;
|
|
133
|
-
const ssrExportName = exportName;
|
|
134
|
-
const chunksSet = new Set();
|
|
135
|
-
for (const chunk of chunkGraph.getModuleChunksIterable(module))chunksSet.add(chunk);
|
|
136
|
-
for (const connection of moduleGraph.getOutgoingConnections(module))for (const chunk of chunkGraph.getModuleChunksIterable(connection.module))chunksSet.add(chunk);
|
|
137
|
-
const chunks = [];
|
|
138
|
-
const styles = [];
|
|
139
|
-
for (const chunk of chunksSet)if (chunk.id) {
|
|
140
|
-
for (const file of chunk.files)if (file.endsWith('.js')) chunks.push(chunk.id, file);
|
|
141
|
-
}
|
|
142
|
-
clientManifest[id] = {
|
|
143
|
-
id: moduleId,
|
|
144
|
-
name: clientExportName,
|
|
145
|
-
chunks,
|
|
146
|
-
styles
|
|
147
|
-
};
|
|
148
|
-
if (ssrId) ssrModuleMetaData[clientExportName] = {
|
|
149
|
-
id: ssrId,
|
|
150
|
-
name: ssrExportName,
|
|
151
|
-
chunks: []
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
ssrManifest.moduleMap[moduleId] = ssrModuleMetaData;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
compilation.emitAsset(this.clientManifestFilename, new RawSource(JSON.stringify(clientManifest, null, 2), false));
|
|
158
|
-
const { crossOriginLoading, publicPath = "" } = compilation.outputOptions;
|
|
159
|
-
ssrManifest.moduleLoading = {
|
|
160
|
-
prefix: compilation.getPath(publicPath, {
|
|
161
|
-
hash: compilation.hash ?? "XXXX"
|
|
162
|
-
}),
|
|
163
|
-
crossOrigin: crossOriginLoading ? "use-credentials" === crossOriginLoading ? crossOriginLoading : "" : void 0
|
|
164
|
-
};
|
|
165
|
-
if (this.styles && this.styles.size > 0) {
|
|
166
|
-
const assets = compilation.getAssets();
|
|
167
|
-
const cssAsset = assets.find((asset)=>asset.name.endsWith('.css'));
|
|
168
|
-
if (cssAsset) ssrManifest.styles.push(cssAsset.name);
|
|
169
|
-
}
|
|
170
|
-
compilation.emitAsset(this.ssrManifestFilename, new RawSource(JSON.stringify(ssrManifest, null, 2), false));
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
constructor(options){
|
|
175
|
-
this.clientReferencesMap = new Map();
|
|
176
|
-
this.dependencies = [];
|
|
177
|
-
this.clientManifestFilename = options?.clientManifestFilename || "react-client-manifest.json";
|
|
178
|
-
this.ssrManifestFilename = options?.ssrManifestFilename || "react-ssr-manifest.json";
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.RspackRscClientPlugin = __webpack_exports__.RspackRscClientPlugin;
|
|
182
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
183
|
-
"RspackRscClientPlugin"
|
|
184
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
185
|
-
Object.defineProperty(exports, '__esModule', {
|
|
186
|
-
value: true
|
|
187
|
-
});
|