@lark-apaas/fullstack-rspack-preset 1.0.23-alpha.1 → 1.0.23-alpha.3

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
@@ -14,6 +14,15 @@ const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-p
14
14
  const view_context_injection_plugin_1 = __importDefault(require("./rspack-plugins/view-context-injection-plugin"));
15
15
  const og_meta_injection_plugin_1 = __importDefault(require("./rspack-plugins/og-meta-injection-plugin"));
16
16
  const dev_server_snapdom_proxy_1 = require("./utils/dev-server-snapdom-proxy");
17
+ function sendBackendUnavailable502(_err, _req, res) {
18
+ if (res.headersSent)
19
+ return;
20
+ res.writeHead(502, {
21
+ 'Content-Type': 'application/json; charset=utf-8',
22
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
23
+ });
24
+ res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
25
+ }
17
26
  function createRecommendRspackConfig(options) {
18
27
  const { isDev = true, enableReactRefresh = isDev, needRoutes = true, clientBasePath = '', publicPath = '', // 静态资源路径
19
28
  } = options;
@@ -230,6 +239,7 @@ function createRecommendRspackConfig(options) {
230
239
  hot: true,
231
240
  liveReload: true,
232
241
  historyApiFallback: true,
242
+ compress: false,
233
243
  watchFiles: [{
234
244
  paths: [path_1.default.resolve(rootDir, 'client/src/api/**/*')],
235
245
  options: {
@@ -283,11 +293,13 @@ function createRecommendRspackConfig(options) {
283
293
  context: [`${clientBasePath}/api`],
284
294
  target: `http://localhost:${serverPort}`,
285
295
  changeOrigin: true,
296
+ onError: sendBackendUnavailable502,
286
297
  },
287
298
  {
288
299
  context: [`${clientBasePath}/__innerapi__`],
289
300
  target: `http://localhost:${serverPort}`,
290
301
  changeOrigin: true,
302
+ onError: sendBackendUnavailable502,
291
303
  },
292
304
  {
293
305
  context: (pathname, req) => {
@@ -4,12 +4,14 @@ interface OgMetaInjectionPluginOptions {
4
4
  placeholder: string;
5
5
  }>;
6
6
  titlePlaceholder?: string;
7
+ descriptionPlaceholder?: string;
7
8
  faviconPlaceholder?: string;
8
9
  }
9
10
  declare class OgMetaInjectionPlugin {
10
11
  private options;
11
12
  private defaultOgTags;
12
13
  private defaultTitlePlaceholder;
14
+ private defaultDescriptionPlaceholder;
13
15
  private defaultFaviconPlaceholder;
14
16
  constructor(options?: OgMetaInjectionPluginOptions);
15
17
  apply(compiler: any): void;
@@ -11,6 +11,8 @@ class OgMetaInjectionPlugin {
11
11
  ];
12
12
  // 默认 title 占位符
13
13
  this.defaultTitlePlaceholder = '{{appName}}';
14
+ // 默认 description 占位符
15
+ this.defaultDescriptionPlaceholder = '{{appDescription}}';
14
16
  // 默认 favicon 占位符
15
17
  this.defaultFaviconPlaceholder = '{{appAvatar}}';
16
18
  this.options = options || {};
@@ -77,6 +79,23 @@ class OgMetaInjectionPlugin {
77
79
  const newTitleTag = `\n <title>${titlePlaceholder}</title>`;
78
80
  html = html.replace('</head>', `${newTitleTag}\n </head>`);
79
81
  }
82
+ // 2.1 处理 <meta name="description"> 标签
83
+ const descriptionPlaceholder = this.options.descriptionPlaceholder ||
84
+ this.defaultDescriptionPlaceholder;
85
+ const descriptionMetaRegex = /<meta\b[^>]*\bname=["']description["'][^>]*>/i;
86
+ const descriptionMetaReplaceRegex = /<meta\b[^>]*\bname=["']description["'][^>]*>/gi;
87
+ if (descriptionMetaRegex.test(html)) {
88
+ html = html.replace(descriptionMetaReplaceRegex, (metaTag) => {
89
+ if (/\bcontent=/.test(metaTag)) {
90
+ return metaTag.replace(/\bcontent=(["'])([\s\S]*?)\1/i, `content="${descriptionPlaceholder}"`);
91
+ }
92
+ return metaTag.replace(/>$/, ` content="${descriptionPlaceholder}">`);
93
+ });
94
+ }
95
+ else {
96
+ const newDescriptionTag = `\n <meta name="description" content="${descriptionPlaceholder}">`;
97
+ html = html.replace('</head>', `${newDescriptionTag}\n </head>`);
98
+ }
80
99
  // 3. 处理 <link rel="icon"> 标签
81
100
  const faviconPlaceholder = this.options.faviconPlaceholder || this.defaultFaviconPlaceholder;
82
101
  const iconRegex = /<link\s+[^>]*rel=["']?(?:icon|shortcut icon)["']?[^>]*>/i;
@@ -72,7 +72,7 @@ function getViewContextScriptContent() {
72
72
  window.appId = "{{appId}}";
73
73
  const appInfo = {
74
74
  name: "{{appName}}",
75
- avatar: "{{appAvatar}}",
75
+ avatar: "{{{appAvatar}}}",
76
76
  description: "{{appDescription}}",
77
77
  };
78
78
  if (appInfo.name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.23-alpha.1",
3
+ "version": "1.0.23-alpha.3",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",
@@ -35,7 +35,7 @@
35
35
  "@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.0",
36
36
  "@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.0",
37
37
  "@rspack/plugin-react-refresh": "^1.5.1",
38
- "@swc/plugin-styled-jsx": "^11.0.0",
38
+ "@swc/plugin-styled-jsx": "^13.0.0",
39
39
  "clsx": "^2.1.1",
40
40
  "colorjs.io": "^0.5.2",
41
41
  "dotenv": "^16.4.5",