@lark-apaas/fullstack-rspack-preset 1.0.38 → 1.0.39-alpha.0
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/lib/preset.js
CHANGED
|
@@ -206,6 +206,7 @@ function createRecommendRspackConfig(options) {
|
|
|
206
206
|
new route_parser_plugin_1.default({
|
|
207
207
|
appPath: './client/src/app.tsx',
|
|
208
208
|
outputPath: path_1.default.resolve(rootDir, 'dist/client/routes.json'),
|
|
209
|
+
...(isDev ? { basePath: '' } : {}),
|
|
209
210
|
}),
|
|
210
211
|
// 热更新
|
|
211
212
|
enableReactRefresh && new plugin_react_refresh_1.default({
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
interface RouteParserPluginOptions {
|
|
2
2
|
appPath?: string;
|
|
3
3
|
outputPath?: string;
|
|
4
|
+
basePath?: string;
|
|
4
5
|
}
|
|
5
6
|
declare class RouteParserPlugin {
|
|
6
7
|
private options;
|
|
7
8
|
private lastAppPathHash;
|
|
8
9
|
private cachedRoutes;
|
|
9
10
|
constructor(options?: RouteParserPluginOptions);
|
|
11
|
+
private normalizeBasePath;
|
|
10
12
|
private log;
|
|
11
13
|
apply(compiler: any): void;
|
|
12
14
|
private shouldRegenerateRoutes;
|
|
@@ -46,11 +46,27 @@ class RouteParserPlugin {
|
|
|
46
46
|
constructor(options = {}) {
|
|
47
47
|
this.lastAppPathHash = null;
|
|
48
48
|
this.cachedRoutes = null;
|
|
49
|
+
// 从环境变量读取 basePath,并规范化(确保以 / 开头,不以 / 结尾)
|
|
50
|
+
const envBasePath = process.env.CLIENT_BASE_PATH || '';
|
|
51
|
+
const normalizedBasePath = this.normalizeBasePath(options.basePath ?? envBasePath);
|
|
49
52
|
this.options = {
|
|
50
53
|
appPath: options.appPath || './client/src/app.tsx',
|
|
51
54
|
outputPath: options.outputPath || './dist/client/routes.json',
|
|
55
|
+
basePath: normalizedBasePath,
|
|
52
56
|
};
|
|
53
57
|
}
|
|
58
|
+
normalizeBasePath(basePath) {
|
|
59
|
+
if (!basePath || basePath === '/') {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
// 确保以 / 开头
|
|
63
|
+
let normalized = basePath.startsWith('/') ? basePath : `/${basePath}`;
|
|
64
|
+
// 确保不以 / 结尾
|
|
65
|
+
if (normalized.endsWith('/')) {
|
|
66
|
+
normalized = normalized.slice(0, -1);
|
|
67
|
+
}
|
|
68
|
+
return normalized;
|
|
69
|
+
}
|
|
54
70
|
log(level, message, ...args) {
|
|
55
71
|
const prefix = '[route-parser]';
|
|
56
72
|
const logMessage = `${prefix} ${message}`;
|
|
@@ -88,7 +104,9 @@ class RouteParserPlugin {
|
|
|
88
104
|
}
|
|
89
105
|
catch (error) {
|
|
90
106
|
this.log('warn', '⚠️ 路由解析失败,使用默认路由:', error.message);
|
|
91
|
-
const
|
|
107
|
+
const { basePath } = this.options;
|
|
108
|
+
const defaultPath = basePath ? `${basePath}/` : '/';
|
|
109
|
+
const defaultRoutes = [{ path: defaultPath }];
|
|
92
110
|
const routesJson = JSON.stringify(defaultRoutes, null, 2);
|
|
93
111
|
compilation.assets['routes.json'] = {
|
|
94
112
|
source: () => routesJson,
|
|
@@ -179,12 +197,19 @@ class RouteParserPlugin {
|
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
199
|
});
|
|
182
|
-
const
|
|
183
|
-
|
|
200
|
+
const { basePath } = this.options;
|
|
201
|
+
const routes = Array.from(routeSet).map(routePath => ({
|
|
202
|
+
path: basePath ? `${basePath}${routePath}` : routePath,
|
|
203
|
+
}));
|
|
204
|
+
// 默认路由也需要加上 basePath
|
|
205
|
+
const defaultPath = basePath ? `${basePath}/` : '/';
|
|
206
|
+
return routes.length > 0 ? routes : [{ path: defaultPath }];
|
|
184
207
|
}
|
|
185
208
|
catch (error) {
|
|
186
209
|
this.log('warn', '⚠️ 路由解析失败,使用默认路由:', error.message);
|
|
187
|
-
|
|
210
|
+
const { basePath } = this.options;
|
|
211
|
+
const defaultPath = basePath ? `${basePath}/` : '/';
|
|
212
|
+
return [{ path: defaultPath }];
|
|
188
213
|
}
|
|
189
214
|
}
|
|
190
215
|
isRouteComponent(openingElement) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-rspack-preset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39-alpha.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"patches",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/parser": "^7.28.0",
|
|
33
33
|
"@babel/traverse": "^7.28.0",
|
|
34
34
|
"@babel/types": "^7.28.2",
|
|
35
|
-
"@lark-apaas/devtool-kits": "
|
|
35
|
+
"@lark-apaas/devtool-kits": "1.2.17-alpha.22",
|
|
36
36
|
"@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.0",
|
|
37
37
|
"@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.1",
|
|
38
38
|
"@lark-apaas/styled-jsx": "^1.0.1",
|