@lark-apaas/fullstack-rspack-preset 1.0.32-alpha.23 → 1.0.32-alpha.25

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.
Files changed (2) hide show
  1. package/lib/preset.js +22 -38
  2. package/package.json +2 -2
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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.32-alpha.23",
3
+ "version": "1.0.32-alpha.25",
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.36",
34
+ "@lark-apaas/devtool-kits": "1.2.17-alpha.38",
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",