@lark-apaas/fullstack-rspack-preset 1.0.31 → 1.0.32-alpha.1
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/overlay/index.js +1 -6
- package/lib/preset.js +23 -3
- package/lib/rspack-plugins/slardar-performance-monitor-plugin.js +9 -6
- package/lib/rspack-plugins/source-map-upload-plugin.d.ts +10 -0
- package/lib/rspack-plugins/source-map-upload-plugin.js +94 -0
- package/lib/rspack-plugins/view-context-injection-plugin.js +1 -0
- package/package.json +6 -5
package/lib/overlay/index.js
CHANGED
|
@@ -129,11 +129,6 @@ function removeAllChildren(element, skip) {
|
|
|
129
129
|
element.removeChild(childList[i]);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
function getEnvOrigin() {
|
|
133
|
-
return typeof process !== 'undefined' && process.env
|
|
134
|
-
? process.env.FORCE_FRAMEWORK_DOMAIN_MAIN
|
|
135
|
-
: undefined;
|
|
136
|
-
}
|
|
137
132
|
function getLegacyParentOrigin() {
|
|
138
133
|
const currentOrigin = window.location?.origin || '';
|
|
139
134
|
if (currentOrigin.includes('force.feishuapp.net')) {
|
|
@@ -155,7 +150,7 @@ function getLegacyParentOrigin() {
|
|
|
155
150
|
}
|
|
156
151
|
function sendPostMessage(message, targetOrigin) {
|
|
157
152
|
try {
|
|
158
|
-
const parentOrigin =
|
|
153
|
+
const parentOrigin = process?.env?.FORCE_FRAMEWORK_DOMAIN_MAIN || getLegacyParentOrigin();
|
|
159
154
|
const origin = targetOrigin || parentOrigin;
|
|
160
155
|
window.parent.postMessage(message, origin);
|
|
161
156
|
}
|
package/lib/preset.js
CHANGED
|
@@ -13,6 +13,7 @@ const route_parser_plugin_1 = __importDefault(require("./rspack-plugins/route-pa
|
|
|
13
13
|
const slardar_performance_monitor_plugin_1 = __importDefault(require("./rspack-plugins/slardar-performance-monitor-plugin"));
|
|
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
|
+
const source_map_upload_plugin_1 = __importDefault(require("./rspack-plugins/source-map-upload-plugin"));
|
|
16
17
|
const dev_server_snapdom_proxy_1 = require("./utils/dev-server-snapdom-proxy");
|
|
17
18
|
function sendBackendUnavailable502(_err, _req, res) {
|
|
18
19
|
if (res.headersSent)
|
|
@@ -23,12 +24,16 @@ function sendBackendUnavailable502(_err, _req, res) {
|
|
|
23
24
|
});
|
|
24
25
|
res.end(JSON.stringify({ error: 'Bad Gateway', message: 'Backend service is not running' }));
|
|
25
26
|
}
|
|
27
|
+
// 检查是否启用宽松 build 模式
|
|
28
|
+
const isLooseMode = process.env.FORCE_FRAMEWORK_BUILD_LOOSE_MODE === 'true';
|
|
26
29
|
function createRecommendRspackConfig(options) {
|
|
27
30
|
const { isDev = true, enableReactRefresh = isDev, needRoutes = true, clientBasePath = '', publicPath = '', // 静态资源路径
|
|
28
31
|
} = options;
|
|
29
32
|
const assetsCDNPath = publicPath + '/';
|
|
30
33
|
const rootDir = process.cwd();
|
|
31
34
|
const serverPort = process.env.SERVER_PORT || '3000';
|
|
35
|
+
// 优先从环境变量获取 RELEASE_ID,否则使用时间戳作为兜底
|
|
36
|
+
const releaseId = process.env.RELEASE_ID || new Date().toISOString();
|
|
32
37
|
return {
|
|
33
38
|
mode: isDev ? 'development' : 'production',
|
|
34
39
|
cache: false,
|
|
@@ -91,6 +96,16 @@ function createRecommendRspackConfig(options) {
|
|
|
91
96
|
{
|
|
92
97
|
test: /\.tsx?$/,
|
|
93
98
|
use: [
|
|
99
|
+
...(isLooseMode ? [{
|
|
100
|
+
loader: require.resolve('babel-loader'),
|
|
101
|
+
options: {
|
|
102
|
+
plugins: [
|
|
103
|
+
[
|
|
104
|
+
require.resolve('@lark-apaas/styled-jsx/babel'),
|
|
105
|
+
]
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
}] : []),
|
|
94
109
|
{
|
|
95
110
|
loader: 'builtin:swc-loader',
|
|
96
111
|
options: {
|
|
@@ -118,7 +133,7 @@ function createRecommendRspackConfig(options) {
|
|
|
118
133
|
// 避免 wasm 出现到根目录,统一放到 node_modules/.cache 目录下
|
|
119
134
|
cacheRoot: path_1.default.join(rootDir, './node_modules/.cache/swc'),
|
|
120
135
|
// 支持 styled-jsx 语法
|
|
121
|
-
plugins: [[require.resolve('@swc/plugin-styled-jsx'), {}]],
|
|
136
|
+
plugins: [isLooseMode ? null : [require.resolve('@swc/plugin-styled-jsx'), {}]].filter(Boolean),
|
|
122
137
|
},
|
|
123
138
|
},
|
|
124
139
|
},
|
|
@@ -126,7 +141,7 @@ function createRecommendRspackConfig(options) {
|
|
|
126
141
|
...(isDev
|
|
127
142
|
? [require.resolve('@lark-apaas/miaoda-inspector-babel-plugin')]
|
|
128
143
|
: []),
|
|
129
|
-
],
|
|
144
|
+
].filter(Boolean),
|
|
130
145
|
},
|
|
131
146
|
],
|
|
132
147
|
},
|
|
@@ -148,6 +163,7 @@ function createRecommendRspackConfig(options) {
|
|
|
148
163
|
'process.env.CLIENT_BASE_PATH': JSON.stringify(clientBasePath),
|
|
149
164
|
'process.env.FORCE_FRAMEWORK_DOMAIN_MAIN': JSON.stringify(process.env.FORCE_FRAMEWORK_DOMAIN_MAIN ?? ''),
|
|
150
165
|
'process.env.CWD': JSON.stringify(''),
|
|
166
|
+
'window.__APP_VERSION__': JSON.stringify(releaseId),
|
|
151
167
|
// 解决 window 未定义问题
|
|
152
168
|
'typeof window': JSON.stringify('object'),
|
|
153
169
|
window: 'globalThis',
|
|
@@ -188,6 +204,10 @@ function createRecommendRspackConfig(options) {
|
|
|
188
204
|
module: path_1.default.resolve(__dirname, 'overlay/index.js'),
|
|
189
205
|
},
|
|
190
206
|
}),
|
|
207
|
+
// 生产环境下,收集 sourcemap
|
|
208
|
+
!isDev && new source_map_upload_plugin_1.default({
|
|
209
|
+
outputDir: path_1.default.resolve(rootDir, 'dist/sourcemaps'),
|
|
210
|
+
}),
|
|
191
211
|
],
|
|
192
212
|
optimization: isDev
|
|
193
213
|
? {}
|
|
@@ -232,7 +252,7 @@ function createRecommendRspackConfig(options) {
|
|
|
232
252
|
mergeDuplicateChunks: true,
|
|
233
253
|
splitChunks: false, // 禁用代码分割,保持单文件输出
|
|
234
254
|
},
|
|
235
|
-
devtool: isDev ? 'source-map' :
|
|
255
|
+
devtool: isDev ? 'source-map' : 'hidden-source-map', // 对应vite的sourcemap配置
|
|
236
256
|
devServer: {
|
|
237
257
|
port: process.env.CLIENT_DEV_PORT || 8080,
|
|
238
258
|
host: process.env.CLIENT_DEV_HOST || 'localhost',
|
|
@@ -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
|
{
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Compiler } from '@rspack/core';
|
|
2
|
+
interface SourceMapUploadPluginOptions {
|
|
3
|
+
outputDir: string;
|
|
4
|
+
}
|
|
5
|
+
declare class SourceMapUploadPlugin {
|
|
6
|
+
private options;
|
|
7
|
+
constructor(options: SourceMapUploadPluginOptions);
|
|
8
|
+
apply(compiler: Compiler): void;
|
|
9
|
+
}
|
|
10
|
+
export default SourceMapUploadPlugin;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const core_1 = __importDefault(require("@rspack/core"));
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
class SourceMapUploadPlugin {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
if (!options.outputDir) {
|
|
45
|
+
throw new Error('SourceMapUploadPlugin: outputDir is required');
|
|
46
|
+
}
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
apply(compiler) {
|
|
50
|
+
compiler.hooks.afterEmit.tapPromise('SourceMapUploadPlugin', async (compilation) => {
|
|
51
|
+
console.log('SourceMapUploadPlugin: Starting sourcemap consolidation process...');
|
|
52
|
+
const outputPath = compiler.options.output.path;
|
|
53
|
+
if (!outputPath) {
|
|
54
|
+
compilation.warnings.push(new core_1.default.WebpackError('SourceMapUploadPlugin: compiler.options.output.path is not defined. Skipping sourcemap consolidation.'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const assets = compilation.getAssets();
|
|
58
|
+
const sourceMaps = assets.filter(asset => asset.name.endsWith('.map'));
|
|
59
|
+
if (sourceMaps.length === 0) {
|
|
60
|
+
console.log('SourceMapUploadPlugin: No sourcemaps found to consolidate.');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const outputBaseDir = path.basename(outputPath); // e.g., 'client'
|
|
64
|
+
const sourcemapTargetDir = path.join(this.options.outputDir, outputBaseDir); // e.g., 'dist/sourcemaps/client'
|
|
65
|
+
for (const sourceMap of sourceMaps) {
|
|
66
|
+
const assetName = sourceMap.name;
|
|
67
|
+
const destinationPath = path.join(sourcemapTargetDir, assetName);
|
|
68
|
+
try {
|
|
69
|
+
// Ensure the destination directory for the specific file exists.
|
|
70
|
+
const destinationDir = path.dirname(destinationPath);
|
|
71
|
+
if (!fs.existsSync(destinationDir)) {
|
|
72
|
+
fs.mkdirSync(destinationDir, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
// The asset source may be a Buffer or a string.
|
|
75
|
+
const source = sourceMap.source.source();
|
|
76
|
+
const sourceBuffer = Buffer.isBuffer(source) ? source : Buffer.from(source, 'utf-8');
|
|
77
|
+
fs.writeFileSync(destinationPath, sourceBuffer);
|
|
78
|
+
console.log(`SourceMapUploadPlugin: Consolidated ${assetName} to ${destinationPath}`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const errorMessage = `SourceMapUploadPlugin: Failed to consolidate ${assetName}.`;
|
|
82
|
+
console.error(errorMessage, error);
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
compilation.errors.push(new Error(`${errorMessage} Error: ${error.message}`));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
compilation.errors.push(new Error(`${errorMessage} Error: ${String(error)}`));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.default = SourceMapUploadPlugin;
|
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.32-alpha.1",
|
|
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",
|
|
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",
|
|
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",
|
|
@@ -56,6 +58,5 @@
|
|
|
56
58
|
"@rspack/core": "^1.5.5",
|
|
57
59
|
"react": ">=16.14.0",
|
|
58
60
|
"react-dom": ">=16.14.0"
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
|
+
}
|