rsbuild-plugin-react-router 0.0.1
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/LICENSE +21 -0
- package/README.md +484 -0
- package/dist/babel.d.ts +8 -0
- package/dist/constants.d.ts +28 -0
- package/dist/dev-server.d.ts +3 -0
- package/dist/index.cjs +746 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +726 -0
- package/dist/manifest.d.ts +14 -0
- package/dist/modify-browser-manifest.d.ts +12 -0
- package/dist/plugin-utils.d.ts +16 -0
- package/dist/server-utils.d.ts +16 -0
- package/dist/templates/context.d.ts +6 -0
- package/dist/templates/entry.client.cjs +12 -0
- package/dist/templates/entry.client.d.ts +1 -0
- package/dist/templates/entry.client.js +6 -0
- package/dist/templates/entry.server.cjs +49 -0
- package/dist/templates/entry.server.d.ts +2 -0
- package/dist/templates/entry.server.js +31 -0
- package/dist/transform-route-federation.d.ts +6 -0
- package/dist/types.d.ts +49 -0
- package/package.json +122 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
+
var __webpack_modules__ = {
|
|
4
|
+
"@babel/generator": function(module) {
|
|
5
|
+
module.exports = require("@babel/generator");
|
|
6
|
+
},
|
|
7
|
+
"@babel/traverse": function(module) {
|
|
8
|
+
module.exports = require("@babel/traverse");
|
|
9
|
+
},
|
|
10
|
+
execa: function(module) {
|
|
11
|
+
module.exports = import("execa");
|
|
12
|
+
}
|
|
13
|
+
}, __webpack_module_cache__ = {};
|
|
14
|
+
function __webpack_require__(moduleId) {
|
|
15
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
16
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
17
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
18
|
+
exports: {}
|
|
19
|
+
};
|
|
20
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
21
|
+
}
|
|
22
|
+
__webpack_require__.n = (module)=>{
|
|
23
|
+
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
24
|
+
return __webpack_require__.d(getter, {
|
|
25
|
+
a: getter
|
|
26
|
+
}), getter;
|
|
27
|
+
}, __webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: !0,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
33
|
+
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
34
|
+
value: 'Module'
|
|
35
|
+
}), Object.defineProperty(exports1, '__esModule', {
|
|
36
|
+
value: !0
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
pluginReactRouter: ()=>pluginReactRouter
|
|
43
|
+
});
|
|
44
|
+
let external_node_fs_namespaceObject = require("node:fs"), external_fs_extra_namespaceObject = require("fs-extra"), external_esbuild_namespaceObject = require("esbuild"), external_jiti_namespaceObject = require("jiti"), external_jsesc_namespaceObject = require("jsesc");
|
|
45
|
+
var external_jsesc_default = __webpack_require__.n(external_jsesc_namespaceObject);
|
|
46
|
+
let external_pathe_namespaceObject = require("pathe"), external_rspack_plugin_virtual_module_namespaceObject = require("rspack-plugin-virtual-module"), parser_namespaceObject = require("@babel/parser"), types_namespaceObject = require("@babel/types"), traverse = __webpack_require__("@babel/traverse").default, generate = __webpack_require__("@babel/generator").default, JS_EXTENSIONS = [
|
|
47
|
+
'.tsx',
|
|
48
|
+
'.ts',
|
|
49
|
+
'.jsx',
|
|
50
|
+
'.js',
|
|
51
|
+
'.mjs'
|
|
52
|
+
], JS_LOADERS = {
|
|
53
|
+
'.ts': 'ts',
|
|
54
|
+
'.tsx': 'tsx',
|
|
55
|
+
'.js': 'js',
|
|
56
|
+
'.jsx': 'jsx'
|
|
57
|
+
}, SERVER_ONLY_ROUTE_EXPORTS = [
|
|
58
|
+
'loader',
|
|
59
|
+
'action',
|
|
60
|
+
'headers'
|
|
61
|
+
], NAMED_COMPONENT_EXPORTS = [
|
|
62
|
+
'HydrateFallback',
|
|
63
|
+
'ErrorBoundary'
|
|
64
|
+
], SERVER_EXPORTS = {
|
|
65
|
+
loader: 'loader',
|
|
66
|
+
action: 'action'
|
|
67
|
+
}, CLIENT_EXPORTS = {
|
|
68
|
+
clientAction: 'clientAction',
|
|
69
|
+
clientLoader: 'clientLoader',
|
|
70
|
+
ErrorBoundary: 'ErrorBoundary'
|
|
71
|
+
}, node_namespaceObject = require("@react-router/node"), createDevServerMiddleware = (server)=>async (req, res, next)=>{
|
|
72
|
+
try {
|
|
73
|
+
let bundle = await server.environments.node.loadBundle('app');
|
|
74
|
+
if (!bundle || !bundle.routes) throw Error('Server bundle not found or invalid');
|
|
75
|
+
let listener = (0, node_namespaceObject.createRequestListener)({
|
|
76
|
+
build: bundle
|
|
77
|
+
});
|
|
78
|
+
await listener(req, res);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('SSR Error:', error), next(error);
|
|
81
|
+
}
|
|
82
|
+
}, external_babel_dead_code_elimination_namespaceObject = require("babel-dead-code-elimination");
|
|
83
|
+
function invalidDestructureError(name) {
|
|
84
|
+
return Error(`Cannot remove destructured export "${name}"`);
|
|
85
|
+
}
|
|
86
|
+
function toFunctionExpression(decl) {
|
|
87
|
+
return types_namespaceObject.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async);
|
|
88
|
+
}
|
|
89
|
+
function combineURLs(baseURL, relativeURL) {
|
|
90
|
+
return relativeURL ? `${baseURL.replace(/\/+$/, '')}/${relativeURL.replace(/^\/+/, '')}` : baseURL;
|
|
91
|
+
}
|
|
92
|
+
function findEntryFile(basePath) {
|
|
93
|
+
for (let ext of JS_EXTENSIONS){
|
|
94
|
+
let filePath = `${basePath}${ext}`;
|
|
95
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(filePath)) return filePath;
|
|
96
|
+
}
|
|
97
|
+
return `${basePath}.tsx`;
|
|
98
|
+
}
|
|
99
|
+
let removeExports = (ast, exportsToRemove)=>{
|
|
100
|
+
let previouslyReferencedIdentifiers = (0, external_babel_dead_code_elimination_namespaceObject.findReferencedIdentifiers)(ast), exportsFiltered = !1, markedForRemoval = new Set();
|
|
101
|
+
if (traverse(ast, {
|
|
102
|
+
ExportDeclaration (path) {
|
|
103
|
+
if ('ExportNamedDeclaration' === path.node.type) {
|
|
104
|
+
var _path_node_declaration, _path_node_declaration1, _path_node_declaration2;
|
|
105
|
+
if (path.node.specifiers.length && (path.node.specifiers = path.node.specifiers.filter((specifier)=>!('ExportSpecifier' === specifier.type && 'Identifier' === specifier.exported.type && exportsToRemove.includes(specifier.exported.name)) || (exportsFiltered = !0, !1)), 0 === path.node.specifiers.length && markedForRemoval.add(path)), (null === (_path_node_declaration = path.node.declaration) || void 0 === _path_node_declaration ? void 0 : _path_node_declaration.type) === 'VariableDeclaration') {
|
|
106
|
+
let declaration = path.node.declaration;
|
|
107
|
+
declaration.declarations = declaration.declarations.filter((declaration)=>'Identifier' === declaration.id.type && exportsToRemove.includes(declaration.id.name) ? (exportsFiltered = !0, !1) : (('ArrayPattern' === declaration.id.type || 'ObjectPattern' === declaration.id.type) && function validateDestructuredExports(id, exportsToRemove) {
|
|
108
|
+
if ('ArrayPattern' === id.type) {
|
|
109
|
+
for (let element of id.elements)if (element) {
|
|
110
|
+
if ('Identifier' === element.type && exportsToRemove.includes(element.name)) throw invalidDestructureError(element.name);
|
|
111
|
+
if ('RestElement' === element.type && 'Identifier' === element.argument.type && exportsToRemove.includes(element.argument.name)) throw invalidDestructureError(element.argument.name);
|
|
112
|
+
('ArrayPattern' === element.type || 'ObjectPattern' === element.type) && validateDestructuredExports(element, exportsToRemove);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if ('ObjectPattern' === id.type) {
|
|
116
|
+
for (let property of id.properties)if (property) {
|
|
117
|
+
if ('ObjectProperty' === property.type && 'Identifier' === property.key.type) {
|
|
118
|
+
if ('Identifier' === property.value.type && exportsToRemove.includes(property.value.name)) throw invalidDestructureError(property.value.name);
|
|
119
|
+
('ArrayPattern' === property.value.type || 'ObjectPattern' === property.value.type) && validateDestructuredExports(property.value, exportsToRemove);
|
|
120
|
+
}
|
|
121
|
+
if ('RestElement' === property.type && 'Identifier' === property.argument.type && exportsToRemove.includes(property.argument.name)) throw invalidDestructureError(property.argument.name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}(declaration.id, exportsToRemove), !0)), 0 === declaration.declarations.length && markedForRemoval.add(path);
|
|
125
|
+
}
|
|
126
|
+
if ((null === (_path_node_declaration1 = path.node.declaration) || void 0 === _path_node_declaration1 ? void 0 : _path_node_declaration1.type) === 'FunctionDeclaration') {
|
|
127
|
+
let id = path.node.declaration.id;
|
|
128
|
+
id && exportsToRemove.includes(id.name) && markedForRemoval.add(path);
|
|
129
|
+
}
|
|
130
|
+
if ((null === (_path_node_declaration2 = path.node.declaration) || void 0 === _path_node_declaration2 ? void 0 : _path_node_declaration2.type) === 'ClassDeclaration') {
|
|
131
|
+
let id = path.node.declaration.id;
|
|
132
|
+
id && exportsToRemove.includes(id.name) && markedForRemoval.add(path);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
'ExportDefaultDeclaration' === path.node.type && exportsToRemove.includes('default') && markedForRemoval.add(path);
|
|
136
|
+
}
|
|
137
|
+
}), markedForRemoval.size > 0 || exportsFiltered) {
|
|
138
|
+
for (let path of markedForRemoval)path.remove();
|
|
139
|
+
(0, external_babel_dead_code_elimination_namespaceObject.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
140
|
+
}
|
|
141
|
+
}, transformRoute = (ast)=>{
|
|
142
|
+
let hocs = [];
|
|
143
|
+
function getHocUid(path, hocName) {
|
|
144
|
+
let uid = path.scope.generateUidIdentifier(hocName);
|
|
145
|
+
return hocs.push([
|
|
146
|
+
hocName,
|
|
147
|
+
uid
|
|
148
|
+
]), uid;
|
|
149
|
+
}
|
|
150
|
+
traverse(ast, {
|
|
151
|
+
ExportDeclaration (path) {
|
|
152
|
+
if (path.isExportDefaultDeclaration()) {
|
|
153
|
+
let declaration = path.get('declaration'), expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
154
|
+
if (expr) {
|
|
155
|
+
let uid = getHocUid(path, 'withComponentProps');
|
|
156
|
+
declaration.replaceWith(types_namespaceObject.callExpression(uid, [
|
|
157
|
+
expr
|
|
158
|
+
]));
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (path.isExportNamedDeclaration()) {
|
|
163
|
+
let decl = path.get('declaration');
|
|
164
|
+
if (decl.isVariableDeclaration()) {
|
|
165
|
+
decl.get('declarations').forEach((varDeclarator)=>{
|
|
166
|
+
let id = varDeclarator.get('id'), init = varDeclarator.get('init'), expr = init.node;
|
|
167
|
+
if (!expr || !id.isIdentifier()) return;
|
|
168
|
+
let { name } = id.node;
|
|
169
|
+
if (!isNamedComponentExport(name)) return;
|
|
170
|
+
let uid = getHocUid(path, `with${name}Props`);
|
|
171
|
+
init.replaceWith(types_namespaceObject.callExpression(uid, [
|
|
172
|
+
expr
|
|
173
|
+
]));
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (decl.isFunctionDeclaration()) {
|
|
178
|
+
let { id } = decl.node;
|
|
179
|
+
if (!id) return;
|
|
180
|
+
let { name } = id;
|
|
181
|
+
if (!isNamedComponentExport(name)) return;
|
|
182
|
+
let uid = getHocUid(path, `with${name}Props`);
|
|
183
|
+
decl.replaceWith(types_namespaceObject.variableDeclaration('const', [
|
|
184
|
+
types_namespaceObject.variableDeclarator(types_namespaceObject.identifier(name), types_namespaceObject.callExpression(uid, [
|
|
185
|
+
toFunctionExpression(decl.node)
|
|
186
|
+
]))
|
|
187
|
+
]));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}), hocs.length > 0 && ast.program.body.unshift(types_namespaceObject.importDeclaration(hocs.map(([name, identifier])=>types_namespaceObject.importSpecifier(identifier, types_namespaceObject.identifier(name))), types_namespaceObject.stringLiteral('virtual/react-router/with-props')));
|
|
192
|
+
};
|
|
193
|
+
function isNamedComponentExport(name) {
|
|
194
|
+
return NAMED_COMPONENT_EXPORTS.includes(name);
|
|
195
|
+
}
|
|
196
|
+
async function getReactRouterManifestForDev(routes, options, clientStats, context) {
|
|
197
|
+
var _clientStats_assetsByChunkName, _clientStats_assetsByChunkName1;
|
|
198
|
+
let result = {};
|
|
199
|
+
for (let [key, route] of Object.entries(routes)){
|
|
200
|
+
let assets = null == clientStats ? void 0 : null === (_clientStats_assetsByChunkName1 = clientStats.assetsByChunkName) || void 0 === _clientStats_assetsByChunkName1 ? void 0 : _clientStats_assetsByChunkName1[route.id], jsAssets = (null == assets ? void 0 : assets.filter((asset)=>asset.endsWith('.js'))) || [], cssAssets = (null == assets ? void 0 : assets.filter((asset)=>asset.endsWith('.css'))) || [], routeFilePath = (0, external_pathe_namespaceObject.resolve)(context, route.file), exports1 = new Set();
|
|
201
|
+
try {
|
|
202
|
+
let buildResult = await external_esbuild_namespaceObject.build({
|
|
203
|
+
entryPoints: [
|
|
204
|
+
routeFilePath
|
|
205
|
+
],
|
|
206
|
+
bundle: !1,
|
|
207
|
+
write: !1,
|
|
208
|
+
metafile: !0,
|
|
209
|
+
jsx: 'automatic',
|
|
210
|
+
format: 'esm',
|
|
211
|
+
platform: 'neutral',
|
|
212
|
+
loader: JS_LOADERS
|
|
213
|
+
}), entryPoint = Object.values(buildResult.metafile.outputs)[0];
|
|
214
|
+
(null == entryPoint ? void 0 : entryPoint.exports) && (exports1 = new Set(entryPoint.exports));
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error(`Failed to analyze route file ${routeFilePath}:`, error);
|
|
217
|
+
}
|
|
218
|
+
result[key] = {
|
|
219
|
+
id: route.id,
|
|
220
|
+
parentId: route.parentId,
|
|
221
|
+
path: route.path,
|
|
222
|
+
index: route.index,
|
|
223
|
+
caseSensitive: route.caseSensitive,
|
|
224
|
+
module: combineURLs('/', jsAssets[0] || ''),
|
|
225
|
+
hasAction: exports1.has(SERVER_EXPORTS.action),
|
|
226
|
+
hasLoader: exports1.has(SERVER_EXPORTS.loader),
|
|
227
|
+
hasClientAction: exports1.has(CLIENT_EXPORTS.clientAction),
|
|
228
|
+
hasClientLoader: exports1.has(CLIENT_EXPORTS.clientLoader),
|
|
229
|
+
hasErrorBoundary: exports1.has(CLIENT_EXPORTS.ErrorBoundary),
|
|
230
|
+
imports: jsAssets.map((asset)=>combineURLs('/', asset)),
|
|
231
|
+
css: cssAssets.map((asset)=>combineURLs('/', asset))
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
let entryAssets = null == clientStats ? void 0 : null === (_clientStats_assetsByChunkName = clientStats.assetsByChunkName) || void 0 === _clientStats_assetsByChunkName ? void 0 : _clientStats_assetsByChunkName['entry.client'], entryJsAssets = (null == entryAssets ? void 0 : entryAssets.filter((asset)=>asset.endsWith('.js'))) || [], entryCssAssets = (null == entryAssets ? void 0 : entryAssets.filter((asset)=>asset.endsWith('.css'))) || [];
|
|
235
|
+
return {
|
|
236
|
+
version: String(Math.random()),
|
|
237
|
+
url: '/static/js/virtual/react-router/browser-manifest.js',
|
|
238
|
+
entry: {
|
|
239
|
+
module: combineURLs('/', entryJsAssets[0] || ''),
|
|
240
|
+
imports: entryJsAssets.map((asset)=>combineURLs('/', asset)),
|
|
241
|
+
css: entryCssAssets.map((asset)=>combineURLs('/', asset))
|
|
242
|
+
},
|
|
243
|
+
routes: result
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
async function transformRouteFederation(args) {
|
|
247
|
+
var _args_environment;
|
|
248
|
+
let code = args.code, defaultExportMatch = code.match(/\n\s{0,}([\w\d_]+)\sas default,?/);
|
|
249
|
+
defaultExportMatch && 'number' == typeof defaultExportMatch.index && (code = code.slice(0, defaultExportMatch.index) + code.slice(defaultExportMatch.index + defaultExportMatch[0].length) + `\nexport default ${defaultExportMatch[1]};`);
|
|
250
|
+
let ast = (0, parser_namespaceObject.parse)(code, {
|
|
251
|
+
sourceType: 'module',
|
|
252
|
+
plugins: [
|
|
253
|
+
"typescript",
|
|
254
|
+
'jsx'
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
args.environment && 'web' === args.environment.name && removeExports(ast, [
|
|
258
|
+
...SERVER_ONLY_ROUTE_EXPORTS
|
|
259
|
+
]), transformRoute(ast);
|
|
260
|
+
let transformedCode = generate(ast, {
|
|
261
|
+
sourceMaps: !0,
|
|
262
|
+
filename: args.resource,
|
|
263
|
+
sourceFileName: args.resourcePath,
|
|
264
|
+
retainLines: !0,
|
|
265
|
+
compact: !1,
|
|
266
|
+
concise: !1
|
|
267
|
+
}).code, output = (await external_esbuild_namespaceObject.build({
|
|
268
|
+
bundle: !1,
|
|
269
|
+
write: !1,
|
|
270
|
+
metafile: !0,
|
|
271
|
+
jsx: 'automatic',
|
|
272
|
+
format: 'esm',
|
|
273
|
+
platform: 'neutral',
|
|
274
|
+
loader: {
|
|
275
|
+
'.ts': 'ts',
|
|
276
|
+
'.tsx': 'tsx'
|
|
277
|
+
},
|
|
278
|
+
stdin: {
|
|
279
|
+
contents: transformedCode,
|
|
280
|
+
resolveDir: args.context || void 0,
|
|
281
|
+
sourcefile: args.resourcePath
|
|
282
|
+
}
|
|
283
|
+
})).metafile.outputs['stdin.js'];
|
|
284
|
+
return (null === (_args_environment = args.environment) || void 0 === _args_environment ? void 0 : _args_environment.name) === 'node' ? `
|
|
285
|
+
let cache;
|
|
286
|
+
const loadRoute = async (exportName)=>{
|
|
287
|
+
if(cache !== undefined) {
|
|
288
|
+
return cache[exportName];
|
|
289
|
+
}
|
|
290
|
+
let exp = await import('${args.resourcePath}?react-router-route');
|
|
291
|
+
cache = exp;
|
|
292
|
+
return exp[exportName]
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
${output.exports.map((exp)=>'default' === exp ? "export default (...args) => loadRoute(\"default\").then(fn => typeof fn === 'function' ? fn(...args) : fn);" : `export const ${exp} = (...args) => loadRoute(${JSON.stringify(exp)}).then(fn => typeof fn === 'function' ? fn(...args) : fn);`).join('\n')}
|
|
296
|
+
` : `const moduleProxy = await import('${args.resourcePath}?react-router-route');
|
|
297
|
+
${output.exports.includes('default') ? `const { default: defaultExport, ${output.exports.filter((exp)=>'default' !== exp).join(', ')} } = moduleProxy;` : `const { ${output.exports.join(', ')} } = moduleProxy;`}
|
|
298
|
+
export { ${output.exports.map((exp)=>'default' === exp ? 'defaultExport as default' : exp).join(', ')} };
|
|
299
|
+
`;
|
|
300
|
+
}
|
|
301
|
+
let pluginReactRouter = (options = {})=>({
|
|
302
|
+
name: 'rsbuild:react-router',
|
|
303
|
+
async setup (api) {
|
|
304
|
+
var options1;
|
|
305
|
+
let clientStats, pluginOptions = {
|
|
306
|
+
customServer: !1,
|
|
307
|
+
serverOutput: 'module',
|
|
308
|
+
...options
|
|
309
|
+
};
|
|
310
|
+
'commonjs' === pluginOptions.serverOutput && api.processAssets({
|
|
311
|
+
stage: 'additional',
|
|
312
|
+
targets: [
|
|
313
|
+
'node'
|
|
314
|
+
]
|
|
315
|
+
}, async ({ compilation })=>{
|
|
316
|
+
let { RawSource } = compilation.compiler.webpack.sources, packageJsonPath = 'package.json', source = new RawSource(JSON.stringify({
|
|
317
|
+
type: 'commonjs'
|
|
318
|
+
}));
|
|
319
|
+
compilation.getAsset(packageJsonPath) ? compilation.updateAsset(packageJsonPath, source) : compilation.emitAsset(packageJsonPath, source);
|
|
320
|
+
}), api.onBeforeStartDevServer(async ()=>{
|
|
321
|
+
let { $ } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "execa"));
|
|
322
|
+
$`npx --yes react-router typegen --watch`;
|
|
323
|
+
}), api.onBeforeBuild(async ()=>{
|
|
324
|
+
let { $ } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "execa"));
|
|
325
|
+
$`npx --yes react-router typegen`;
|
|
326
|
+
});
|
|
327
|
+
let jiti = (0, external_jiti_namespaceObject.createJiti)(process.cwd()), { appDirectory = 'app', basename = '/', buildDirectory = 'build', ssr = !0 } = await jiti.import('./react-router.config.ts', {
|
|
328
|
+
default: !0
|
|
329
|
+
}).catch(()=>(console.error('No react-router.config.ts found, using default configuration.'), {})), routesPath = (0, external_pathe_namespaceObject.resolve)(appDirectory, 'routes.ts'), routeConfig = await jiti.import(routesPath, {
|
|
330
|
+
default: !0
|
|
331
|
+
}).catch((error)=>(console.error('Failed to load routes.ts:', error), console.error('No routes.ts found in app directory.'), [])), entryClientPath = findEntryFile((0, external_pathe_namespaceObject.resolve)(appDirectory, 'entry.client')), entryServerPath = findEntryFile((0, external_pathe_namespaceObject.resolve)(appDirectory, 'entry.server')), serverAppPath = findEntryFile((0, external_pathe_namespaceObject.resolve)(appDirectory, '../server/index')), hasServerApp = (0, external_node_fs_namespaceObject.existsSync)(serverAppPath), templateDir = (0, external_pathe_namespaceObject.resolve)(__dirname, 'templates'), templateClientPath = (0, external_pathe_namespaceObject.resolve)(templateDir, 'entry.client.js'), templateServerPath = (0, external_pathe_namespaceObject.resolve)(templateDir, 'entry.server.js'), finalEntryClientPath = (0, external_node_fs_namespaceObject.existsSync)(entryClientPath) ? entryClientPath : templateClientPath, finalEntryServerPath = (0, external_node_fs_namespaceObject.existsSync)(entryServerPath) ? entryServerPath : templateServerPath, routes = {
|
|
332
|
+
root: {
|
|
333
|
+
path: '',
|
|
334
|
+
id: 'root',
|
|
335
|
+
file: (0, external_pathe_namespaceObject.relative)(appDirectory, (0, external_pathe_namespaceObject.resolve)(appDirectory, 'root.tsx'))
|
|
336
|
+
},
|
|
337
|
+
...function(appDirectory, routes, rootId = 'root') {
|
|
338
|
+
let routeManifest = {};
|
|
339
|
+
for (let route of routes)!function walk(route, parentId) {
|
|
340
|
+
var file;
|
|
341
|
+
let id = route.id || (file = route.file, (0, external_pathe_namespaceObject.normalize)(file.replace(/\.[^/.]+$/, ''))), manifestItem = {
|
|
342
|
+
id,
|
|
343
|
+
parentId,
|
|
344
|
+
file: (0, external_pathe_namespaceObject.isAbsolute)(route.file) ? (0, external_pathe_namespaceObject.relative)(appDirectory, route.file) : route.file,
|
|
345
|
+
path: route.path,
|
|
346
|
+
index: route.index,
|
|
347
|
+
caseSensitive: route.caseSensitive
|
|
348
|
+
};
|
|
349
|
+
if (Object.prototype.hasOwnProperty.call(routeManifest, id)) throw Error(`Unable to define routes with duplicate route id: "${id}"`);
|
|
350
|
+
if (routeManifest[id] = manifestItem, route.children) for (let child of route.children)walk(child, id);
|
|
351
|
+
}(route, rootId);
|
|
352
|
+
return routeManifest;
|
|
353
|
+
}(appDirectory, routeConfig)
|
|
354
|
+
}, outputClientPath = (0, external_pathe_namespaceObject.resolve)(buildDirectory, 'client'), assetsBuildDirectory = (0, external_pathe_namespaceObject.relative)(process.cwd(), outputClientPath);
|
|
355
|
+
api.onAfterEnvironmentCompile(({ stats, environment })=>{
|
|
356
|
+
if ('web' === environment.name && (clientStats = null == stats ? void 0 : stats.toJson()), pluginOptions.federation && ssr) {
|
|
357
|
+
let serverBuildDir = (0, external_pathe_namespaceObject.resolve)(buildDirectory, 'server'), clientBuildDir = (0, external_pathe_namespaceObject.resolve)(buildDirectory, 'client');
|
|
358
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(serverBuildDir)) {
|
|
359
|
+
let ssrDir = (0, external_pathe_namespaceObject.resolve)(clientBuildDir, 'static');
|
|
360
|
+
(0, external_fs_extra_namespaceObject.copySync)(serverBuildDir, ssrDir);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
let vmodPlugin = new external_rspack_plugin_virtual_module_namespaceObject.RspackVirtualModulePlugin({
|
|
365
|
+
'virtual/react-router/browser-manifest': 'export default {};',
|
|
366
|
+
'virtual/react-router/server-manifest': 'export default {};',
|
|
367
|
+
'virtual/react-router/server-build': (options1 = {
|
|
368
|
+
entryServerPath: finalEntryServerPath,
|
|
369
|
+
assetsBuildDirectory,
|
|
370
|
+
basename,
|
|
371
|
+
appDirectory,
|
|
372
|
+
ssr,
|
|
373
|
+
federation: options.federation
|
|
374
|
+
}).federation ? `
|
|
375
|
+
// Create a module cache to store the dynamically imported module
|
|
376
|
+
let entryServerModule = null;
|
|
377
|
+
|
|
378
|
+
// Function to ensure the module is loaded
|
|
379
|
+
const ensureEntryServerLoaded = async () => {
|
|
380
|
+
if (!entryServerModule) {
|
|
381
|
+
entryServerModule = await import(${JSON.stringify(options1.entryServerPath)});
|
|
382
|
+
}
|
|
383
|
+
return entryServerModule;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// Helper function to create async handlers
|
|
387
|
+
const createAsyncHandler = (exportName) => {
|
|
388
|
+
return async (...args) => {
|
|
389
|
+
const module = await ensureEntryServerLoaded();
|
|
390
|
+
const handler = module[exportName];
|
|
391
|
+
return typeof handler === 'function' ? handler(...args) : handler;
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// Helper function to create sync handlers
|
|
396
|
+
const createSyncHandler = (exportName) => {
|
|
397
|
+
return (...args) => {
|
|
398
|
+
if (!entryServerModule) {
|
|
399
|
+
throw new Error('Entry server module not loaded yet. Call an async method first or await ensureEntryServerLoaded()');
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const handler = entryServerModule[exportName];
|
|
403
|
+
return typeof handler === 'function' ? handler(...args) : handler;
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// Create a proxy for the entryServer exports
|
|
408
|
+
const entryServer = new Proxy({}, {
|
|
409
|
+
get: (target, prop) => {
|
|
410
|
+
|
|
411
|
+
console.log(prop);
|
|
412
|
+
if (entryServerModule) {
|
|
413
|
+
return entryServerModule[prop];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (prop === 'handleDataRequest' || prop === 'handleRequest' || prop === 'default') {
|
|
417
|
+
return createAsyncHandler(prop);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return entryServerModule[prop];
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Preload the entry server module
|
|
425
|
+
ensureEntryServerLoaded().catch(console.error);
|
|
426
|
+
|
|
427
|
+
${Object.keys(routes).map((key, index)=>{
|
|
428
|
+
let route = routes[key];
|
|
429
|
+
return `import * as route${index} from ${JSON.stringify(`${(0, external_pathe_namespaceObject.resolve)(options1.appDirectory, route.file)}?react-router-route`)};`;
|
|
430
|
+
}).join('\n')}
|
|
431
|
+
|
|
432
|
+
export { default as assets } from "virtual/react-router/server-manifest";
|
|
433
|
+
export const assetsBuildDirectory = ${JSON.stringify(options1.assetsBuildDirectory)};
|
|
434
|
+
export const basename = ${JSON.stringify(options1.basename)};
|
|
435
|
+
export const future = ${JSON.stringify({})};
|
|
436
|
+
export const isSpaMode = ${!options1.ssr};
|
|
437
|
+
export const ssr = ${options1.ssr};
|
|
438
|
+
export const publicPath = "/";
|
|
439
|
+
export const prerender = [];
|
|
440
|
+
export const entry = { module: entryServer };
|
|
441
|
+
export const routes = {
|
|
442
|
+
${Object.keys(routes).map((key, index)=>{
|
|
443
|
+
let route = routes[key];
|
|
444
|
+
return `${JSON.stringify(key)}: {
|
|
445
|
+
id: ${JSON.stringify(route.id)},
|
|
446
|
+
parentId: ${JSON.stringify(route.parentId)},
|
|
447
|
+
path: ${JSON.stringify(route.path)},
|
|
448
|
+
index: ${JSON.stringify(route.index)},
|
|
449
|
+
caseSensitive: ${JSON.stringify(route.caseSensitive)},
|
|
450
|
+
module: route${index}
|
|
451
|
+
}
|
|
452
|
+
`;
|
|
453
|
+
}).join(',\n ')}
|
|
454
|
+
};
|
|
455
|
+
` : `
|
|
456
|
+
import * as entryServer from ${JSON.stringify(options1.entryServerPath)};
|
|
457
|
+
${Object.keys(routes).map((key, index)=>{
|
|
458
|
+
let route = routes[key];
|
|
459
|
+
return `import * as route${index} from ${JSON.stringify(`${(0, external_pathe_namespaceObject.resolve)(options1.appDirectory, route.file)}?react-router-route`)};`;
|
|
460
|
+
}).join('\n')}
|
|
461
|
+
|
|
462
|
+
export { default as assets } from "virtual/react-router/server-manifest";
|
|
463
|
+
export const assetsBuildDirectory = ${JSON.stringify(options1.assetsBuildDirectory)};
|
|
464
|
+
export const basename = ${JSON.stringify(options1.basename)};
|
|
465
|
+
export const future = ${JSON.stringify({})};
|
|
466
|
+
export const isSpaMode = ${!options1.ssr};
|
|
467
|
+
export const ssr = ${options1.ssr};
|
|
468
|
+
export const prerender = [];
|
|
469
|
+
export const publicPath = "/";
|
|
470
|
+
export const entry = { module: entryServer };
|
|
471
|
+
export const routes = {
|
|
472
|
+
${Object.keys(routes).map((key, index)=>{
|
|
473
|
+
let route = routes[key];
|
|
474
|
+
return `${JSON.stringify(key)}: {
|
|
475
|
+
id: ${JSON.stringify(route.id)},
|
|
476
|
+
parentId: ${JSON.stringify(route.parentId)},
|
|
477
|
+
path: ${JSON.stringify(route.path)},
|
|
478
|
+
index: ${JSON.stringify(route.index)},
|
|
479
|
+
caseSensitive: ${JSON.stringify(route.caseSensitive)},
|
|
480
|
+
module: route${index}
|
|
481
|
+
}
|
|
482
|
+
`;
|
|
483
|
+
}).join(',\n ')}
|
|
484
|
+
};
|
|
485
|
+
`,
|
|
486
|
+
'virtual/react-router/with-props': `
|
|
487
|
+
import { createElement as h } from "react";
|
|
488
|
+
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
489
|
+
|
|
490
|
+
export function withComponentProps(Component) {
|
|
491
|
+
return function Wrapped() {
|
|
492
|
+
const props = {
|
|
493
|
+
params: useParams(),
|
|
494
|
+
loaderData: useLoaderData(),
|
|
495
|
+
actionData: useActionData(),
|
|
496
|
+
matches: useMatches(),
|
|
497
|
+
};
|
|
498
|
+
return h(Component, props);
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export function withHydrateFallbackProps(HydrateFallback) {
|
|
503
|
+
return function Wrapped() {
|
|
504
|
+
const props = {
|
|
505
|
+
params: useParams(),
|
|
506
|
+
};
|
|
507
|
+
return h(HydrateFallback, props);
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function withErrorBoundaryProps(ErrorBoundary) {
|
|
512
|
+
return function Wrapped() {
|
|
513
|
+
const props = {
|
|
514
|
+
params: useParams(),
|
|
515
|
+
loaderData: useLoaderData(),
|
|
516
|
+
actionData: useActionData(),
|
|
517
|
+
error: useRouteError(),
|
|
518
|
+
};
|
|
519
|
+
return h(ErrorBoundary, props);
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
`
|
|
523
|
+
});
|
|
524
|
+
api.modifyRsbuildConfig(async (config, { mergeRsbuildConfig })=>{
|
|
525
|
+
var _config_output, _config_environments_node_output, _config_environments_node, _config_environments;
|
|
526
|
+
return mergeRsbuildConfig(config, {
|
|
527
|
+
output: {
|
|
528
|
+
assetPrefix: (null === (_config_output = config.output) || void 0 === _config_output ? void 0 : _config_output.assetPrefix) || '/'
|
|
529
|
+
},
|
|
530
|
+
dev: {
|
|
531
|
+
writeToDisk: !0,
|
|
532
|
+
hmr: !1,
|
|
533
|
+
liveReload: !0,
|
|
534
|
+
setupMiddlewares: pluginOptions.customServer ? [] : [
|
|
535
|
+
(middlewares, server)=>{
|
|
536
|
+
middlewares.push(createDevServerMiddleware(server));
|
|
537
|
+
}
|
|
538
|
+
]
|
|
539
|
+
},
|
|
540
|
+
tools: {
|
|
541
|
+
rspack: {
|
|
542
|
+
plugins: [
|
|
543
|
+
vmodPlugin
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
environments: {
|
|
548
|
+
web: {
|
|
549
|
+
source: {
|
|
550
|
+
entry: {
|
|
551
|
+
'entry.client': finalEntryClientPath + (options.federation ? '?react-router-route-federation' : ''),
|
|
552
|
+
'virtual/react-router/browser-manifest': 'virtual/react-router/browser-manifest',
|
|
553
|
+
...Object.values(routes).reduce((acc, route)=>(acc[route.file.slice(0, route.file.lastIndexOf('.'))] = {
|
|
554
|
+
import: `${(0, external_pathe_namespaceObject.resolve)(appDirectory, route.file)}?${options.federation ? 'react-router-route-federation' : 'react-router-route'}`
|
|
555
|
+
}, acc), {})
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
output: {
|
|
559
|
+
filename: {
|
|
560
|
+
js: '[name].js'
|
|
561
|
+
},
|
|
562
|
+
distPath: {
|
|
563
|
+
root: outputClientPath
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
tools: {
|
|
567
|
+
rspack: {
|
|
568
|
+
name: 'web',
|
|
569
|
+
experiments: {
|
|
570
|
+
topLevelAwait: !0,
|
|
571
|
+
outputModule: !0
|
|
572
|
+
},
|
|
573
|
+
externalsType: 'module',
|
|
574
|
+
output: {
|
|
575
|
+
chunkFormat: 'module',
|
|
576
|
+
chunkLoading: 'import',
|
|
577
|
+
workerChunkLoading: 'import',
|
|
578
|
+
wasmLoading: 'fetch',
|
|
579
|
+
library: {
|
|
580
|
+
type: 'module'
|
|
581
|
+
},
|
|
582
|
+
module: !0
|
|
583
|
+
},
|
|
584
|
+
optimization: {
|
|
585
|
+
runtimeChunk: 'single'
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
node: {
|
|
591
|
+
source: {
|
|
592
|
+
entry: {
|
|
593
|
+
...hasServerApp ? {
|
|
594
|
+
app: serverAppPath + (options.federation ? '?react-router-route-federation' : '')
|
|
595
|
+
} : {
|
|
596
|
+
app: 'virtual/react-router/server-build' + (options.federation ? '?react-router-route-federation' : '')
|
|
597
|
+
},
|
|
598
|
+
'entry.server': finalEntryServerPath + (options.federation ? '?react-router-route-federation' : '')
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
output: {
|
|
602
|
+
distPath: {
|
|
603
|
+
root: (0, external_pathe_namespaceObject.resolve)(buildDirectory, 'server')
|
|
604
|
+
},
|
|
605
|
+
target: (null === (_config_environments = config.environments) || void 0 === _config_environments ? void 0 : null === (_config_environments_node = _config_environments.node) || void 0 === _config_environments_node ? void 0 : null === (_config_environments_node_output = _config_environments_node.output) || void 0 === _config_environments_node_output ? void 0 : _config_environments_node_output.target) || 'node',
|
|
606
|
+
filename: {
|
|
607
|
+
js: 'static/js/[name].js'
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
tools: {
|
|
611
|
+
rspack: {
|
|
612
|
+
target: 'async-node',
|
|
613
|
+
externals: [
|
|
614
|
+
'express'
|
|
615
|
+
],
|
|
616
|
+
dependencies: [
|
|
617
|
+
'web'
|
|
618
|
+
],
|
|
619
|
+
experiments: {
|
|
620
|
+
outputModule: 'module' === pluginOptions.serverOutput
|
|
621
|
+
},
|
|
622
|
+
externalsType: pluginOptions.serverOutput,
|
|
623
|
+
output: {
|
|
624
|
+
chunkFormat: pluginOptions.serverOutput,
|
|
625
|
+
chunkLoading: 'module' === pluginOptions.serverOutput ? 'import' : options.federation ? 'async-node' : 'require',
|
|
626
|
+
workerChunkLoading: 'module' === pluginOptions.serverOutput ? 'import' : 'require',
|
|
627
|
+
wasmLoading: 'fetch',
|
|
628
|
+
library: {
|
|
629
|
+
type: pluginOptions.serverOutput
|
|
630
|
+
},
|
|
631
|
+
module: 'module' === pluginOptions.serverOutput
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}), api.modifyEnvironmentConfig(async (config, { name, mergeEnvironmentConfig })=>'web' === name ? mergeEnvironmentConfig(config, {
|
|
639
|
+
tools: {
|
|
640
|
+
rspack: (rspackConfig)=>{
|
|
641
|
+
if (rspackConfig.plugins) rspackConfig.plugins.push({
|
|
642
|
+
apply (compiler) {
|
|
643
|
+
compiler.hooks.emit.tapAsync('ModifyBrowserManifest', async (compilation, callback)=>{
|
|
644
|
+
let manifest = await getReactRouterManifestForDev(routes, pluginOptions, compilation.getStats().toJson(), appDirectory), manifestPath = 'static/js/virtual/react-router/browser-manifest.js';
|
|
645
|
+
if (compilation.assets[manifestPath]) {
|
|
646
|
+
let newSource = compilation.assets[manifestPath].source().toString().replace(/["'`]PLACEHOLDER["'`]/, external_jsesc_default()(manifest, {
|
|
647
|
+
es6: !0
|
|
648
|
+
}));
|
|
649
|
+
compilation.assets[manifestPath] = {
|
|
650
|
+
source: ()=>newSource,
|
|
651
|
+
size: ()=>newSource.length,
|
|
652
|
+
map: ()=>({
|
|
653
|
+
version: 3,
|
|
654
|
+
sources: [
|
|
655
|
+
manifestPath
|
|
656
|
+
],
|
|
657
|
+
names: [],
|
|
658
|
+
mappings: '',
|
|
659
|
+
file: manifestPath,
|
|
660
|
+
sourcesContent: [
|
|
661
|
+
newSource
|
|
662
|
+
]
|
|
663
|
+
}),
|
|
664
|
+
sourceAndMap: ()=>({
|
|
665
|
+
source: newSource,
|
|
666
|
+
map: {
|
|
667
|
+
version: 3,
|
|
668
|
+
sources: [
|
|
669
|
+
manifestPath
|
|
670
|
+
],
|
|
671
|
+
names: [],
|
|
672
|
+
mappings: '',
|
|
673
|
+
file: manifestPath,
|
|
674
|
+
sourcesContent: [
|
|
675
|
+
newSource
|
|
676
|
+
]
|
|
677
|
+
}
|
|
678
|
+
}),
|
|
679
|
+
updateHash: (hash)=>hash.update(newSource),
|
|
680
|
+
buffer: ()=>Buffer.from(newSource)
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
callback();
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return rspackConfig;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}) : config), api.processAssets({
|
|
691
|
+
stage: 'additional',
|
|
692
|
+
targets: [
|
|
693
|
+
'node'
|
|
694
|
+
]
|
|
695
|
+
}, ({ sources, compilation })=>{
|
|
696
|
+
let packageJsonPath = 'package.json', source = new sources.RawSource(`{"type": "${pluginOptions.serverOutput}"}`);
|
|
697
|
+
compilation.getAsset(packageJsonPath) ? compilation.updateAsset(packageJsonPath, source) : compilation.emitAsset(packageJsonPath, source);
|
|
698
|
+
}), api.transform({
|
|
699
|
+
test: /virtual\/react-router\/(browser|server)-manifest/
|
|
700
|
+
}, async (args)=>{
|
|
701
|
+
if ('web' === args.environment.name) return {
|
|
702
|
+
code: 'window.__reactRouterManifest = "PLACEHOLDER";'
|
|
703
|
+
};
|
|
704
|
+
let manifest = await getReactRouterManifestForDev(routes, pluginOptions, clientStats, appDirectory);
|
|
705
|
+
return {
|
|
706
|
+
code: `export default ${external_jsesc_default()(manifest, {
|
|
707
|
+
es6: !0
|
|
708
|
+
})};`
|
|
709
|
+
};
|
|
710
|
+
}), api.transform({
|
|
711
|
+
resourceQuery: /\?react-router-route-federation/
|
|
712
|
+
}, async (args)=>await transformRouteFederation(args)), api.transform({
|
|
713
|
+
resourceQuery: /\?react-router-route/
|
|
714
|
+
}, async (args)=>{
|
|
715
|
+
let code;
|
|
716
|
+
try {
|
|
717
|
+
code = (await external_esbuild_namespaceObject.transform(args.code, {
|
|
718
|
+
jsx: 'automatic',
|
|
719
|
+
format: 'esm',
|
|
720
|
+
platform: 'neutral',
|
|
721
|
+
loader: args.resourcePath.endsWith('x') ? 'tsx' : 'ts'
|
|
722
|
+
})).code;
|
|
723
|
+
} catch (error) {
|
|
724
|
+
throw console.error(args.resourcePath), error;
|
|
725
|
+
}
|
|
726
|
+
let defaultExportMatch = code.match(/\n\s{0,}([\w\d_]+)\sas default,?/);
|
|
727
|
+
defaultExportMatch && 'number' == typeof defaultExportMatch.index && (code = code.slice(0, defaultExportMatch.index) + code.slice(defaultExportMatch.index + defaultExportMatch[0].length) + `\nexport default ${defaultExportMatch[1]};`);
|
|
728
|
+
let ast = (0, parser_namespaceObject.parse)(code, {
|
|
729
|
+
sourceType: 'module'
|
|
730
|
+
});
|
|
731
|
+
return 'web' === args.environment.name && removeExports(ast, [
|
|
732
|
+
...SERVER_ONLY_ROUTE_EXPORTS
|
|
733
|
+
]), transformRoute(ast), generate(ast, {
|
|
734
|
+
sourceMaps: !0,
|
|
735
|
+
filename: args.resource,
|
|
736
|
+
sourceFileName: args.resourcePath
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
})();
|
|
742
|
+
var __webpack_export_target__ = exports;
|
|
743
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
744
|
+
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
745
|
+
value: !0
|
|
746
|
+
});
|