@lark-apaas/fullstack-rspack-preset 1.0.33-alpha.5 → 1.0.34-beta.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
|
@@ -23,6 +23,8 @@ function sendBackendUnavailable502(_err, _req, res) {
|
|
|
23
23
|
});
|
|
24
24
|
res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
|
|
25
25
|
}
|
|
26
|
+
// 检查是否启用宽松 build 模式
|
|
27
|
+
const isLooseMode = process.env.FORCE_FRAMEWORK_BUILD_LOOSE_MODE === 'true';
|
|
26
28
|
function createRecommendRspackConfig(options) {
|
|
27
29
|
const { isDev = true, enableReactRefresh = isDev, needRoutes = true, clientBasePath = '', publicPath = '', // 静态资源路径
|
|
28
30
|
} = options;
|
|
@@ -91,6 +93,16 @@ function createRecommendRspackConfig(options) {
|
|
|
91
93
|
{
|
|
92
94
|
test: /\.tsx?$/,
|
|
93
95
|
use: [
|
|
96
|
+
...(isLooseMode ? [{
|
|
97
|
+
loader: require.resolve('babel-loader'),
|
|
98
|
+
options: {
|
|
99
|
+
plugins: [
|
|
100
|
+
[
|
|
101
|
+
require.resolve('@lark-apaas/styled-jsx/babel'),
|
|
102
|
+
]
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
}] : []),
|
|
94
106
|
{
|
|
95
107
|
loader: 'builtin:swc-loader',
|
|
96
108
|
options: {
|
|
@@ -118,7 +130,7 @@ function createRecommendRspackConfig(options) {
|
|
|
118
130
|
// 避免 wasm 出现到根目录,统一放到 node_modules/.cache 目录下
|
|
119
131
|
cacheRoot: path_1.default.join(rootDir, './node_modules/.cache/swc'),
|
|
120
132
|
// 支持 styled-jsx 语法
|
|
121
|
-
plugins: [[require.resolve('@swc/plugin-styled-jsx'), {}]],
|
|
133
|
+
plugins: [isLooseMode ? null : [require.resolve('@swc/plugin-styled-jsx'), {}]].filter(Boolean),
|
|
122
134
|
},
|
|
123
135
|
},
|
|
124
136
|
},
|
|
@@ -126,7 +138,7 @@ function createRecommendRspackConfig(options) {
|
|
|
126
138
|
...(isDev
|
|
127
139
|
? [require.resolve('@lark-apaas/miaoda-inspector-babel-plugin')]
|
|
128
140
|
: []),
|
|
129
|
-
],
|
|
141
|
+
].filter(Boolean),
|
|
130
142
|
},
|
|
131
143
|
],
|
|
132
144
|
},
|
|
@@ -12,7 +12,9 @@ class SlardarPerformanceMonitorPlugin {
|
|
|
12
12
|
let HtmlPlugin;
|
|
13
13
|
try {
|
|
14
14
|
// 尝试从 compiler 中获取 rspack
|
|
15
|
-
const rspack = compiler.webpack ||
|
|
15
|
+
const rspack = compiler.webpack ||
|
|
16
|
+
compiler.rspack ||
|
|
17
|
+
compiler.constructor.webpack;
|
|
16
18
|
if (rspack && rspack.HtmlRspackPlugin) {
|
|
17
19
|
HtmlPlugin = rspack.HtmlRspackPlugin;
|
|
18
20
|
}
|
|
@@ -34,10 +36,11 @@ class SlardarPerformanceMonitorPlugin {
|
|
|
34
36
|
const hooks = HtmlPlugin.getHooks(compilation);
|
|
35
37
|
// 使用 alterAssetTagGroups 钩子,在标签数组层面操作
|
|
36
38
|
hooks.alterAssetTagGroups.tap('SlardarPerformanceMonitorPlugin', (data) => {
|
|
37
|
-
const snippet = this.options.snippet ??
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const snippet = this.options.snippet ??
|
|
40
|
+
getSlardarScriptContent({
|
|
41
|
+
bid: this.options.bid,
|
|
42
|
+
globalName: this.options.globalName,
|
|
43
|
+
});
|
|
41
44
|
const teaSnippet = getTeaScriptContent();
|
|
42
45
|
if (!snippet) {
|
|
43
46
|
return data;
|
|
@@ -88,7 +91,7 @@ class SlardarPerformanceMonitorPlugin {
|
|
|
88
91
|
}
|
|
89
92
|
exports.default = SlardarPerformanceMonitorPlugin;
|
|
90
93
|
function getSlardarScriptContent(option = {}) {
|
|
91
|
-
const bid = option.bid || '
|
|
94
|
+
const bid = option.bid || 'apaas_miaoda';
|
|
92
95
|
const globalName = option.globalName || 'KSlardarWeb';
|
|
93
96
|
return [
|
|
94
97
|
{
|
|
@@ -65,17 +65,12 @@ class ViewContextInjectionPlugin {
|
|
|
65
65
|
}
|
|
66
66
|
exports.default = ViewContextInjectionPlugin;
|
|
67
67
|
function getViewContextScriptContent() {
|
|
68
|
-
const fallbackEnvironment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
69
68
|
return `
|
|
70
69
|
window.csrfToken = "{{csrfToken}}";
|
|
71
70
|
window.userId = "{{userId}}";
|
|
72
71
|
window.tenantId = "{{tenantId}}";
|
|
73
72
|
window.appId = "{{appId}}";
|
|
74
|
-
|
|
75
|
-
const templateValue = "{{environment}}";
|
|
76
|
-
const resolved = templateValue !== "{{environment}}" ? templateValue : ${JSON.stringify(fallbackEnvironment)};
|
|
77
|
-
window.ENVIRONMENT = resolved;
|
|
78
|
-
})();
|
|
73
|
+
window.ENVIRONMENT = "{{environment}}";
|
|
79
74
|
const appInfo = {
|
|
80
75
|
name: "{{appName}}",
|
|
81
76
|
avatar: "{{{appAvatar}}}",
|
|
@@ -86,13 +81,3 @@ function getViewContextScriptContent() {
|
|
|
86
81
|
}
|
|
87
82
|
`;
|
|
88
83
|
}
|
|
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
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-rspack-preset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34-beta.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"patches",
|
|
@@ -31,11 +31,13 @@
|
|
|
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.
|
|
34
|
+
"@lark-apaas/devtool-kits": "^1.2.15-beta.0",
|
|
35
35
|
"@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.0",
|
|
36
36
|
"@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.0",
|
|
37
|
+
"@lark-apaas/styled-jsx": "^1.0.1-beta.0",
|
|
37
38
|
"@rspack/plugin-react-refresh": "^1.5.1",
|
|
38
39
|
"@swc/plugin-styled-jsx": "^11.0.0",
|
|
40
|
+
"babel-loader": "^10.0.0",
|
|
39
41
|
"clsx": "^2.1.1",
|
|
40
42
|
"colorjs.io": "^0.5.2",
|
|
41
43
|
"dotenv": "^16.4.5",
|