@lark-apaas/fullstack-rspack-preset 1.0.48 → 1.0.50-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
@@ -29,8 +29,6 @@ function sendBackendUnavailable502(_err, _req, res) {
29
29
  });
30
30
  res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
31
31
  }
32
- // 检查是否启用宽松 build 模式
33
- const isLooseMode = process.env.FORCE_FRAMEWORK_BUILD_LOOSE_MODE === 'true';
34
32
  function readAppFlags(rootDir) {
35
33
  try {
36
34
  return JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(rootDir, 'package.json'), 'utf-8')).flags || {};
@@ -46,6 +44,12 @@ function createRecommendRspackConfig(options) {
46
44
  const rootDir = process.cwd();
47
45
  const serverPort = process.env.SERVER_PORT || '3000';
48
46
  const appFlags = readAppFlags(rootDir);
47
+ // 从 clientBasePath(如 /app/app123)中提取 appId,用于构造旧路径代理规则
48
+ // 仅在新路径格式(/app/:appId)下启用旧路径兼容
49
+ const isNewPathFormat = /^\/app\/[^/]/.test(clientBasePath);
50
+ const appId = isNewPathFormat
51
+ ? clientBasePath.replace(/\/+$/, '').split('/').pop()
52
+ : '';
49
53
  // 提前创建实例,以便在 plugins 和 setupMiddlewares 中复用
50
54
  const staticAssetsPlugin = new static_assets_plugin_1.default({ clientBasePath, rootDir });
51
55
  // 优先从环境变量获取 RELEASE_ID,否则使用时间戳作为兜底
@@ -123,16 +127,16 @@ function createRecommendRspackConfig(options) {
123
127
  {
124
128
  test: /\.tsx?$/,
125
129
  use: [
126
- ...(isLooseMode ? [{
127
- loader: require.resolve('babel-loader'),
128
- options: {
129
- plugins: [
130
- [
131
- require.resolve('@lark-apaas/styled-jsx/babel'),
132
- ]
130
+ {
131
+ loader: require.resolve('babel-loader'),
132
+ options: {
133
+ plugins: [
134
+ [
135
+ require.resolve('@lark-apaas/styled-jsx/babel'),
133
136
  ]
134
- },
135
- }] : []),
137
+ ]
138
+ },
139
+ },
136
140
  {
137
141
  loader: 'builtin:swc-loader',
138
142
  options: {
@@ -154,8 +158,8 @@ function createRecommendRspackConfig(options) {
154
158
  experimental: {
155
159
  // 避免 wasm 出现到根目录,统一放到 node_modules/.cache 目录下
156
160
  cacheRoot: path_1.default.join(rootDir, './node_modules/.cache/swc'),
157
- // 支持 styled-jsx 语法
158
- plugins: [isLooseMode ? null : [require.resolve('@swc/plugin-styled-jsx'), {}]].filter(Boolean),
161
+ // styled-jsx 统一由 babel-loader 处理,不再使用 @swc/plugin-styled-jsx(SWC 插件存在编译卡死问题)
162
+ plugins: [],
159
163
  },
160
164
  },
161
165
  },
@@ -222,10 +226,10 @@ function createRecommendRspackConfig(options) {
222
226
  },
223
227
  minify: false, // 关闭 html 压缩,导致数据注入异常
224
228
  }),
229
+ // 视图上下文注入插件(必须在 slardar 之前,确保 HTML 中 viewContext 先于 slardar)
230
+ new view_context_injection_plugin_1.default(),
225
231
  // 性能监控&tea埋点sdk插件
226
232
  new slardar_performance_monitor_plugin_1.default(),
227
- // 视图上下文注入插件
228
- new view_context_injection_plugin_1.default(),
229
233
  // OG Meta 标签注入插件
230
234
  new og_meta_injection_plugin_1.default(),
231
235
  // 生产环境:生成 legacy CSS 并注入检测脚本
@@ -357,6 +361,23 @@ function createRecommendRspackConfig(options) {
357
361
  changeOrigin: true,
358
362
  onError: sendBackendUnavailable502,
359
363
  },
364
+ // 旧路径(/af/p/:appId)兼容代理,转发到 Node Server 由 legacy-path-redirect 中间件处理
365
+ ...(appId
366
+ ? [
367
+ {
368
+ context: [`/af/p/${appId}/api`],
369
+ target: `http://localhost:${serverPort}`,
370
+ changeOrigin: true,
371
+ onError: sendBackendUnavailable502,
372
+ },
373
+ {
374
+ context: [`/af/p/${appId}/__innerapi__`],
375
+ target: `http://localhost:${serverPort}`,
376
+ changeOrigin: true,
377
+ onError: sendBackendUnavailable502,
378
+ },
379
+ ]
380
+ : []),
360
381
  {
361
382
  context: (pathname, req) => {
362
383
  // 代理所有请求 HTML 响应的请求(页面路由)
@@ -106,10 +106,14 @@ function getSlardarScriptContent(option = {}) {
106
106
  slardarScript.onload = function() {
107
107
  // 脚本加载完成后执行初始化
108
108
  if (window.${globalName}) {
109
+ window.${globalName}('context.merge', {
110
+ tenantId: window.tenantId ?? '',
111
+ appId: window.appId ?? '',
112
+ });
109
113
  window.${globalName}('init', {
110
114
  bid: '${bid}',
111
- // 四种类型:dev/boe/pre/online
112
- env: 'online',
115
+ env: window.ENVIRONMENT || 'online',
116
+ userId: window.userId ?? '',
113
117
  });
114
118
  window.${globalName}('start');
115
119
  }
@@ -63,9 +63,14 @@ class SourceMapUploadPlugin {
63
63
  const outputBaseDir = path.basename(outputPath); // e.g., 'client'
64
64
  const sourcemapTargetDir = path.join(this.options.outputDir, outputBaseDir); // e.g., 'dist/sourcemaps/client'
65
65
  for (const sourceMap of sourceMaps) {
66
- const assetName = sourceMap.name;
66
+ let assetName = sourceMap.name;
67
+ // Align with Vite's output structure by adding 'assets' and removing 'chunks'
68
+ if (assetName.startsWith('chunks/')) {
69
+ assetName = assetName.substring('chunks/'.length);
70
+ }
71
+ assetName = path.join('assets', assetName);
67
72
  const destinationPath = path.join(sourcemapTargetDir, assetName);
68
- const originalPath = path.join(outputPath, assetName);
73
+ const originalPath = path.join(outputPath, sourceMap.name);
69
74
  try {
70
75
  // Ensure the destination directory for the specific file exists.
71
76
  const destinationDir = path.dirname(destinationPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.48",
3
+ "version": "1.0.50-alpha.0",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",
@@ -31,8 +31,8 @@
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.18",
35
- "@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.1",
34
+ "@lark-apaas/devtool-kits": "^1.2.19",
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",
38
38
  "@swc/plugin-styled-jsx": "^11.0.0",
@@ -55,7 +55,7 @@
55
55
  "@rspack/core": "^1.5.5",
56
56
  "@types/node": "^22.15.30",
57
57
  "typescript": "^5.9.2",
58
- "vitest": "^2.1.8"
58
+ "vitest": "^3.2.4"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@rspack/core": "^1.5.5",