@lark-apaas/fullstack-rspack-preset 1.0.33-alpha.2 → 1.0.33-alpha.4

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
@@ -8,7 +8,6 @@ const path_1 = __importDefault(require("path"));
8
8
  const core_1 = __importDefault(require("@rspack/core"));
9
9
  const devtool_kits_1 = require("@lark-apaas/devtool-kits");
10
10
  const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
11
- const dotenv_1 = __importDefault(require("dotenv"));
12
11
  const dev_server_listener_1 = require("./utils/dev-server-listener");
13
12
  const route_parser_plugin_1 = __importDefault(require("./rspack-plugins/route-parser-plugin"));
14
13
  const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-plugins/slardar-performance-monitor-plugin"));
@@ -25,18 +24,11 @@ function sendBackendUnavailable502(_err, _req, res) {
25
24
  res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
26
25
  }
27
26
  function createRecommendRspackConfig(options) {
28
- try {
29
- dotenv_1.default.config();
30
- }
31
- catch (_e) {
32
- void _e;
33
- }
34
27
  const { isDev = true, enableReactRefresh = isDev, needRoutes = true, clientBasePath = '', publicPath = '', // 静态资源路径
35
28
  } = options;
36
29
  const assetsCDNPath = publicPath + '/';
37
30
  const rootDir = process.cwd();
38
31
  const serverPort = process.env.SERVER_PORT || '3000';
39
- const windowEnvironment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
40
32
  return {
41
33
  mode: isDev ? 'development' : 'production',
42
34
  cache: false,
@@ -181,7 +173,7 @@ function createRecommendRspackConfig(options) {
181
173
  // 性能监控&tea埋点sdk插件
182
174
  new slardar_performance_monitor_plugin_1.default(),
183
175
  // 视图上下文注入插件
184
- new view_context_injection_plugin_1.default({ environment: windowEnvironment }),
176
+ new view_context_injection_plugin_1.default(),
185
177
  // OG Meta 标签注入插件
186
178
  new og_meta_injection_plugin_1.default(),
187
179
  // 开发环境下,解析路由
@@ -347,13 +339,3 @@ function createRecommendRspackConfig(options) {
347
339
  },
348
340
  };
349
341
  }
350
- function mapToWindowEnvironment(input) {
351
- const value = (input || '').trim().toLowerCase();
352
- if (value === 'boe')
353
- return 'staging';
354
- if (value === 'pre')
355
- return 'gray';
356
- if (value === 'online')
357
- return 'online';
358
- return '';
359
- }
@@ -22,7 +22,14 @@ class EnvironmentInjectionPlugin {
22
22
  const envTag = {
23
23
  tagName: 'script',
24
24
  voidTag: false,
25
- innerHTML: `window.ENVIRONMENT = ${JSON.stringify(mapped)};`,
25
+ innerHTML: `(() => {
26
+ const templateValue = '{{environment}}';
27
+ const resolved =
28
+ templateValue && templateValue !== '{{environment}}'
29
+ ? templateValue
30
+ : ${JSON.stringify(mapped)};
31
+ window.ENVIRONMENT = resolved;
32
+ })();`,
26
33
  attributes: {},
27
34
  };
28
35
  const headIndex = findMainJsIndex(data.headTags);
@@ -52,7 +59,7 @@ function mapToWindowEnvironment(input) {
52
59
  return 'staging';
53
60
  if (value === 'pre')
54
61
  return 'gray';
55
- if (value === 'prod')
62
+ if (value === 'online')
56
63
  return 'online';
57
64
  return '';
58
65
  }
@@ -1,5 +1,4 @@
1
1
  interface ViewContextInjectionPluginOptions {
2
- environment?: string;
3
2
  }
4
3
  declare class ViewContextInjectionPlugin {
5
4
  private options;
@@ -38,7 +38,7 @@ class ViewContextInjectionPlugin {
38
38
  const viewContextTag = {
39
39
  tagName: 'script',
40
40
  voidTag: false,
41
- innerHTML: getViewContextScriptContent(this.options.environment),
41
+ innerHTML: getViewContextScriptContent(),
42
42
  attributes: {},
43
43
  };
44
44
  // 找到 main.js 的索引位置
@@ -64,13 +64,13 @@ class ViewContextInjectionPlugin {
64
64
  }
65
65
  }
66
66
  exports.default = ViewContextInjectionPlugin;
67
- function getViewContextScriptContent(environment) {
67
+ function getViewContextScriptContent() {
68
68
  return `
69
- window.ENVIRONMENT = ${JSON.stringify(environment ?? '')};
70
69
  window.csrfToken = "{{csrfToken}}";
71
70
  window.userId = "{{userId}}";
72
71
  window.tenantId = "{{tenantId}}";
73
72
  window.appId = "{{appId}}";
73
+ window.ENVIRONMENT = "{{environment}}";
74
74
  const appInfo = {
75
75
  name: "{{appName}}",
76
76
  avatar: "{{{appAvatar}}}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.33-alpha.2",
3
+ "version": "1.0.33-alpha.4",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",