@lark-apaas/fullstack-rspack-preset 1.0.33-alpha.3 → 1.0.33-alpha.5
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
|
@@ -11,7 +11,6 @@ const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-ref
|
|
|
11
11
|
const dev_server_listener_1 = require("./utils/dev-server-listener");
|
|
12
12
|
const route_parser_plugin_1 = __importDefault(require("./rspack-plugins/route-parser-plugin"));
|
|
13
13
|
const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-plugins/slardar-performance-monitor-plugin"));
|
|
14
|
-
const environment_injection_plugin_1 = __importDefault(require("./rspack-plugins/environment-injection-plugin"));
|
|
15
14
|
const view_context_injection_plugin_1 = __importDefault(require("./rspack-plugins/view-context-injection-plugin"));
|
|
16
15
|
const og_meta_injection_plugin_1 = __importDefault(require("./rspack-plugins/og-meta-injection-plugin"));
|
|
17
16
|
const dev_server_snapdom_proxy_1 = require("./utils/dev-server-snapdom-proxy");
|
|
@@ -171,7 +170,6 @@ function createRecommendRspackConfig(options) {
|
|
|
171
170
|
},
|
|
172
171
|
minify: false, // 关闭 html 压缩,导致数据注入异常
|
|
173
172
|
}),
|
|
174
|
-
new environment_injection_plugin_1.default(),
|
|
175
173
|
// 性能监控&tea埋点sdk插件
|
|
176
174
|
new slardar_performance_monitor_plugin_1.default(),
|
|
177
175
|
// 视图上下文注入插件
|
|
@@ -22,7 +22,14 @@ class EnvironmentInjectionPlugin {
|
|
|
22
22
|
const envTag = {
|
|
23
23
|
tagName: 'script',
|
|
24
24
|
voidTag: false,
|
|
25
|
-
innerHTML: `
|
|
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);
|
|
@@ -65,11 +65,17 @@ class ViewContextInjectionPlugin {
|
|
|
65
65
|
}
|
|
66
66
|
exports.default = ViewContextInjectionPlugin;
|
|
67
67
|
function getViewContextScriptContent() {
|
|
68
|
+
const fallbackEnvironment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
68
69
|
return `
|
|
69
70
|
window.csrfToken = "{{csrfToken}}";
|
|
70
71
|
window.userId = "{{userId}}";
|
|
71
72
|
window.tenantId = "{{tenantId}}";
|
|
72
73
|
window.appId = "{{appId}}";
|
|
74
|
+
(() => {
|
|
75
|
+
const templateValue = "{{environment}}";
|
|
76
|
+
const resolved = templateValue !== "{{environment}}" ? templateValue : ${JSON.stringify(fallbackEnvironment)};
|
|
77
|
+
window.ENVIRONMENT = resolved;
|
|
78
|
+
})();
|
|
73
79
|
const appInfo = {
|
|
74
80
|
name: "{{appName}}",
|
|
75
81
|
avatar: "{{{appAvatar}}}",
|
|
@@ -80,3 +86,13 @@ function getViewContextScriptContent() {
|
|
|
80
86
|
}
|
|
81
87
|
`;
|
|
82
88
|
}
|
|
89
|
+
function mapToWindowEnvironment(input) {
|
|
90
|
+
const value = (input || '').trim().toLowerCase();
|
|
91
|
+
if (value === 'boe')
|
|
92
|
+
return 'staging';
|
|
93
|
+
if (value === 'pre')
|
|
94
|
+
return 'gray';
|
|
95
|
+
if (value === 'online')
|
|
96
|
+
return 'online';
|
|
97
|
+
return '';
|
|
98
|
+
}
|