@lark-apaas/fullstack-rspack-preset 1.0.33-alpha.1 → 1.0.33-alpha.2
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,6 +8,7 @@ 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"));
|
|
11
12
|
const dev_server_listener_1 = require("./utils/dev-server-listener");
|
|
12
13
|
const route_parser_plugin_1 = __importDefault(require("./rspack-plugins/route-parser-plugin"));
|
|
13
14
|
const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-plugins/slardar-performance-monitor-plugin"));
|
|
@@ -24,11 +25,18 @@ function sendBackendUnavailable502(_err, _req, res) {
|
|
|
24
25
|
res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
|
|
25
26
|
}
|
|
26
27
|
function createRecommendRspackConfig(options) {
|
|
28
|
+
try {
|
|
29
|
+
dotenv_1.default.config();
|
|
30
|
+
}
|
|
31
|
+
catch (_e) {
|
|
32
|
+
void _e;
|
|
33
|
+
}
|
|
27
34
|
const { isDev = true, enableReactRefresh = isDev, needRoutes = true, clientBasePath = '', publicPath = '', // 静态资源路径
|
|
28
35
|
} = options;
|
|
29
36
|
const assetsCDNPath = publicPath + '/';
|
|
30
37
|
const rootDir = process.cwd();
|
|
31
38
|
const serverPort = process.env.SERVER_PORT || '3000';
|
|
39
|
+
const windowEnvironment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
32
40
|
return {
|
|
33
41
|
mode: isDev ? 'development' : 'production',
|
|
34
42
|
cache: false,
|
|
@@ -173,7 +181,7 @@ function createRecommendRspackConfig(options) {
|
|
|
173
181
|
// 性能监控&tea埋点sdk插件
|
|
174
182
|
new slardar_performance_monitor_plugin_1.default(),
|
|
175
183
|
// 视图上下文注入插件
|
|
176
|
-
new view_context_injection_plugin_1.default(),
|
|
184
|
+
new view_context_injection_plugin_1.default({ environment: windowEnvironment }),
|
|
177
185
|
// OG Meta 标签注入插件
|
|
178
186
|
new og_meta_injection_plugin_1.default(),
|
|
179
187
|
// 开发环境下,解析路由
|
|
@@ -339,3 +347,13 @@ function createRecommendRspackConfig(options) {
|
|
|
339
347
|
},
|
|
340
348
|
};
|
|
341
349
|
}
|
|
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
|
+
}
|
|
@@ -38,7 +38,7 @@ class ViewContextInjectionPlugin {
|
|
|
38
38
|
const viewContextTag = {
|
|
39
39
|
tagName: 'script',
|
|
40
40
|
voidTag: false,
|
|
41
|
-
innerHTML: getViewContextScriptContent(),
|
|
41
|
+
innerHTML: getViewContextScriptContent(this.options.environment),
|
|
42
42
|
attributes: {},
|
|
43
43
|
};
|
|
44
44
|
// 找到 main.js 的索引位置
|
|
@@ -64,10 +64,9 @@ class ViewContextInjectionPlugin {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
exports.default = ViewContextInjectionPlugin;
|
|
67
|
-
function getViewContextScriptContent() {
|
|
68
|
-
const windowEnvironment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
67
|
+
function getViewContextScriptContent(environment) {
|
|
69
68
|
return `
|
|
70
|
-
window.ENVIRONMENT = ${JSON.stringify(
|
|
69
|
+
window.ENVIRONMENT = ${JSON.stringify(environment ?? '')};
|
|
71
70
|
window.csrfToken = "{{csrfToken}}";
|
|
72
71
|
window.userId = "{{userId}}";
|
|
73
72
|
window.tenantId = "{{tenantId}}";
|
|
@@ -82,13 +81,3 @@ function getViewContextScriptContent() {
|
|
|
82
81
|
}
|
|
83
82
|
`;
|
|
84
83
|
}
|
|
85
|
-
function mapToWindowEnvironment(input) {
|
|
86
|
-
const value = (input || '').trim().toLowerCase();
|
|
87
|
-
if (value === 'boe')
|
|
88
|
-
return 'staging';
|
|
89
|
-
if (value === 'pre')
|
|
90
|
-
return 'gray';
|
|
91
|
-
if (value === 'online ')
|
|
92
|
-
return 'online';
|
|
93
|
-
return '';
|
|
94
|
-
}
|