@lark-apaas/fullstack-rspack-preset 1.0.32-alpha.22 → 1.0.32-alpha.24

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
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -43,7 +10,7 @@ const core_1 = __importDefault(require("@rspack/core"));
43
10
  const devtool_kits_1 = require("@lark-apaas/devtool-kits");
44
11
  const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
45
12
  const dev_server_listener_1 = require("./utils/dev-server-listener");
46
- const route_parser_plugin_1 = __importStar(require("./rspack-plugins/route-parser-plugin"));
13
+ const route_parser_plugin_1 = __importDefault(require("./rspack-plugins/route-parser-plugin"));
47
14
  const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-plugins/slardar-performance-monitor-plugin"));
48
15
  const view_context_injection_plugin_1 = __importDefault(require("./rspack-plugins/view-context-injection-plugin"));
49
16
  const og_meta_injection_plugin_1 = __importDefault(require("./rspack-plugins/og-meta-injection-plugin"));
@@ -89,11 +56,25 @@ function createRecommendRspackConfig(options) {
89
56
  const staticAssetsPlugin = new static_assets_plugin_1.default({ clientBasePath, rootDir });
90
57
  // 优先从环境变量获取 RELEASE_ID,否则使用时间戳作为兜底
91
58
  const releaseId = process.env.RELEASE_ID || new Date().toISOString();
92
- // 解析路由定义,供 DefinePlugin 注入到 bundle
93
- let routeDefinitions = [];
59
+ // 读取构建前生成的路由定义 JSON,供 DefinePlugin 注入到 bundle
60
+ // build.sh client 构建之前已将 page-routes.json / api-routes.json 写入 dist/
61
+ let pageRouteDefinitions = [];
62
+ let apiRouteDefinitions = [];
94
63
  if (needRoutes) {
95
- const routeBasePath = isDev ? '' : (0, route_parser_plugin_1.normalizeBasePath)(clientBasePath || '');
96
- routeDefinitions = (0, route_parser_plugin_1.parseRoutesFromFile)('./client/src/app.tsx', routeBasePath);
64
+ try {
65
+ const pageRoutesPath = path_1.default.resolve(rootDir, 'dist/page-routes.json');
66
+ if (fs_1.default.existsSync(pageRoutesPath)) {
67
+ pageRouteDefinitions = JSON.parse(fs_1.default.readFileSync(pageRoutesPath, 'utf-8'));
68
+ }
69
+ }
70
+ catch { /* ignore */ }
71
+ try {
72
+ const apiRoutesPath = path_1.default.resolve(rootDir, 'dist/api-routes.json');
73
+ if (fs_1.default.existsSync(apiRoutesPath)) {
74
+ apiRouteDefinitions = JSON.parse(fs_1.default.readFileSync(apiRoutesPath, 'utf-8'));
75
+ }
76
+ }
77
+ catch { /* ignore */ }
97
78
  }
98
79
  return {
99
80
  mode: isDev ? 'development' : 'production',
@@ -245,6 +226,9 @@ function createRecommendRspackConfig(options) {
245
226
  'process.env.BUILD_TOOL': JSON.stringify('rspack'),
246
227
  // 模板 flags 配置
247
228
  'process.env.APP_FLAGS': JSON.stringify(appFlags),
229
+ // 路由定义,供客户端匹配 referer_path 和 api
230
+ 'process.env.__PAGE_ROUTE_DEFINITIONS__': JSON.stringify(JSON.stringify(pageRouteDefinitions)),
231
+ 'process.env.__API_ROUTE_DEFINITIONS__': JSON.stringify(JSON.stringify(apiRouteDefinitions)),
248
232
  // 解决 window 未定义问题
249
233
  'typeof window': JSON.stringify('object'),
250
234
  window: 'globalThis',
@@ -7,8 +7,6 @@ declare class RouteParserPlugin {
7
7
  private options;
8
8
  private lastAppPathHash;
9
9
  private cachedRoutes;
10
- /** 不带 basePath 前缀的路由(供日志服务消费) */
11
- private cachedPageRoutes;
12
10
  constructor(options?: RouteParserPluginOptions);
13
11
  private normalizeBasePath;
14
12
  private log;
@@ -48,8 +48,6 @@ class RouteParserPlugin {
48
48
  constructor(options = {}) {
49
49
  this.lastAppPathHash = null;
50
50
  this.cachedRoutes = null;
51
- /** 不带 basePath 前缀的路由(供日志服务消费) */
52
- this.cachedPageRoutes = null;
53
51
  // 从环境变量读取 basePath,并规范化(确保以 / 开头,不以 / 结尾)
54
52
  const envBasePath = process.env.CLIENT_BASE_PATH || '';
55
53
  const normalizedBasePath = this.normalizeBasePath(options.basePath ?? envBasePath);
@@ -104,12 +102,6 @@ class RouteParserPlugin {
104
102
  source: () => routesJson,
105
103
  size: () => routesJson.length
106
104
  };
107
- // 不带 basePath 前缀的路由,供日志服务消费
108
- const pageRoutesJson = JSON.stringify(this.cachedPageRoutes, null, 2);
109
- compilation.assets['page-routes.json'] = {
110
- source: () => pageRoutesJson,
111
- size: () => pageRoutesJson.length
112
- };
113
105
  callback();
114
106
  }
115
107
  catch (error) {
@@ -118,16 +110,10 @@ class RouteParserPlugin {
118
110
  const defaultPath = basePath ? `${basePath}/` : '/';
119
111
  const defaultRoutes = [{ path: defaultPath }];
120
112
  const routesJson = JSON.stringify(defaultRoutes, null, 2);
121
- const defaultPageRoutes = [{ path: '/' }];
122
- const pageRoutesJson = JSON.stringify(defaultPageRoutes, null, 2);
123
113
  compilation.assets['routes.json'] = {
124
114
  source: () => routesJson,
125
115
  size: () => routesJson.length
126
116
  };
127
- compilation.assets['page-routes.json'] = {
128
- source: () => pageRoutesJson,
129
- size: () => pageRoutesJson.length
130
- };
131
117
  callback();
132
118
  }
133
119
  });
@@ -214,11 +200,6 @@ class RouteParserPlugin {
214
200
  }
215
201
  });
216
202
  const { basePath } = this.options;
217
- // 不带前缀的纯页面路由(供日志服务消费)
218
- const pageRoutes = Array.from(routeSet).map(routePath => ({
219
- path: routePath,
220
- }));
221
- this.cachedPageRoutes = pageRoutes.length > 0 ? pageRoutes : [{ path: '/' }];
222
203
  const routes = Array.from(routeSet).map(routePath => ({
223
204
  path: basePath ? `${basePath}${routePath}` : routePath,
224
205
  }));
@@ -230,7 +211,6 @@ class RouteParserPlugin {
230
211
  this.log('warn', '⚠️ 路由解析失败,使用默认路由:', error.message);
231
212
  const { basePath } = this.options;
232
213
  const defaultPath = basePath ? `${basePath}/` : '/';
233
- this.cachedPageRoutes = [{ path: '/' }];
234
214
  return [{ path: defaultPath }];
235
215
  }
236
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.32-alpha.22",
3
+ "version": "1.0.32-alpha.24",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",
@@ -31,7 +31,7 @@
31
31
  "@babel/parser": "^7.28.0",
32
32
  "@babel/traverse": "^7.28.0",
33
33
  "@babel/types": "^7.28.2",
34
- "@lark-apaas/devtool-kits": "1.2.17-alpha.35",
34
+ "@lark-apaas/devtool-kits": "1.2.17-alpha.37",
35
35
  "@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.2",
36
36
  "@lark-apaas/styled-jsx": "^1.0.1",
37
37
  "@rspack/plugin-react-refresh": "^1.5.1",