@lark-apaas/fullstack-rspack-preset 1.0.45 → 1.0.47
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
CHANGED
|
@@ -129,6 +129,25 @@ function removeAllChildren(element, skip) {
|
|
|
129
129
|
element.removeChild(childList[i]);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
function getParentOriginFromParams() {
|
|
133
|
+
try {
|
|
134
|
+
var params = new URLSearchParams(window.location.search);
|
|
135
|
+
var origin = params.get('__parentOrigin');
|
|
136
|
+
if (origin) {
|
|
137
|
+
sessionStorage.setItem('__parentOrigin', origin);
|
|
138
|
+
return origin;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
// ignore
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
return sessionStorage.getItem('__parentOrigin') || '';
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
return '';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
132
151
|
function getLegacyParentOrigin() {
|
|
133
152
|
const currentOrigin = window.location?.origin || '';
|
|
134
153
|
if (currentOrigin.includes('force.feishuapp.net')) {
|
|
@@ -150,7 +169,7 @@ function getLegacyParentOrigin() {
|
|
|
150
169
|
}
|
|
151
170
|
function sendPostMessage(message, targetOrigin) {
|
|
152
171
|
try {
|
|
153
|
-
const parentOrigin = process?.env?.FORCE_FRAMEWORK_DOMAIN_MAIN || getLegacyParentOrigin();
|
|
172
|
+
const parentOrigin = getParentOriginFromParams() || process?.env?.FORCE_FRAMEWORK_DOMAIN_MAIN || getLegacyParentOrigin();
|
|
154
173
|
const origin = targetOrigin || parentOrigin;
|
|
155
174
|
window.parent.postMessage(message, origin);
|
|
156
175
|
}
|
package/lib/preset.js
CHANGED
|
@@ -18,6 +18,7 @@ const runtime_injection_plugin_1 = __importDefault(require("./rspack-plugins/run
|
|
|
18
18
|
const css_legacy_plugin_1 = __importDefault(require("./rspack-plugins/css-legacy-plugin"));
|
|
19
19
|
const polyfill_plugin_1 = __importDefault(require("./rspack-plugins/polyfill-plugin"));
|
|
20
20
|
const static_assets_plugin_1 = __importDefault(require("./rspack-plugins/static-assets-plugin"));
|
|
21
|
+
const source_map_upload_plugin_1 = __importDefault(require("./rspack-plugins/source-map-upload-plugin"));
|
|
21
22
|
const dev_server_snapdom_proxy_1 = require("./utils/dev-server-snapdom-proxy");
|
|
22
23
|
function sendBackendUnavailable502(_err, _req, res) {
|
|
23
24
|
if (res.headersSent)
|
|
@@ -47,6 +48,8 @@ function createRecommendRspackConfig(options) {
|
|
|
47
48
|
const appFlags = readAppFlags(rootDir);
|
|
48
49
|
// 提前创建实例,以便在 plugins 和 setupMiddlewares 中复用
|
|
49
50
|
const staticAssetsPlugin = new static_assets_plugin_1.default({ clientBasePath, rootDir });
|
|
51
|
+
// 优先从环境变量获取 RELEASE_ID,否则使用时间戳作为兜底
|
|
52
|
+
const releaseId = process.env.RELEASE_ID || new Date().toISOString();
|
|
50
53
|
return {
|
|
51
54
|
mode: isDev ? 'development' : 'production',
|
|
52
55
|
cache: false,
|
|
@@ -167,6 +170,10 @@ function createRecommendRspackConfig(options) {
|
|
|
167
170
|
plugins: [
|
|
168
171
|
// 运行时注入插件 - 自动将 @lark-apaas/client-toolkit/runtime 注入到所有入口之前
|
|
169
172
|
new runtime_injection_plugin_1.default(),
|
|
173
|
+
new core_1.default.BannerPlugin({
|
|
174
|
+
banner: `window.__RELEASE_COMMIT_ID__ = '${releaseId}';`,
|
|
175
|
+
raw: true,
|
|
176
|
+
}),
|
|
170
177
|
// 针对 clsx/echarts/echarts-for-react 等包,让其默认好用
|
|
171
178
|
new core_1.default.NormalModuleReplacementPlugin(/^(clsx|echarts|echarts-for-react)$/, function (resource) {
|
|
172
179
|
if (!resource.context.endsWith('module-alias')) {
|
|
@@ -240,6 +247,10 @@ function createRecommendRspackConfig(options) {
|
|
|
240
247
|
module: path_1.default.resolve(__dirname, 'overlay/index.js'),
|
|
241
248
|
},
|
|
242
249
|
}),
|
|
250
|
+
// 生产环境下,收集 sourcemap
|
|
251
|
+
!isDev && new source_map_upload_plugin_1.default({
|
|
252
|
+
outputDir: path_1.default.resolve(rootDir, 'dist/sourcemaps'),
|
|
253
|
+
}),
|
|
243
254
|
],
|
|
244
255
|
optimization: isDev
|
|
245
256
|
? {}
|
|
@@ -288,7 +299,7 @@ function createRecommendRspackConfig(options) {
|
|
|
288
299
|
mergeDuplicateChunks: true,
|
|
289
300
|
splitChunks: false, // 禁用代码分割,保持单文件输出
|
|
290
301
|
},
|
|
291
|
-
devtool: isDev ? 'source-map' :
|
|
302
|
+
devtool: isDev ? 'source-map' : 'hidden-source-map', // 对应vite的sourcemap配置
|
|
292
303
|
devServer: {
|
|
293
304
|
port: process.env.CLIENT_DEV_PORT || 8080,
|
|
294
305
|
host: process.env.CLIENT_DEV_HOST || 'localhost',
|
|
@@ -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,104 @@
|
|
|
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
|
+
const originalPath = path.join(outputPath, assetName);
|
|
69
|
+
try {
|
|
70
|
+
// Ensure the destination directory for the specific file exists.
|
|
71
|
+
const destinationDir = path.dirname(destinationPath);
|
|
72
|
+
if (!fs.existsSync(destinationDir)) {
|
|
73
|
+
fs.mkdirSync(destinationDir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
// The asset source may be a Buffer or a string.
|
|
76
|
+
const source = sourceMap.source.source();
|
|
77
|
+
const sourceBuffer = Buffer.isBuffer(source) ? source : Buffer.from(source, 'utf-8');
|
|
78
|
+
fs.writeFileSync(destinationPath, sourceBuffer);
|
|
79
|
+
console.log(`SourceMapUploadPlugin: Consolidated ${assetName} to ${destinationPath}`);
|
|
80
|
+
// Delete the original sourcemap file.
|
|
81
|
+
try {
|
|
82
|
+
fs.unlinkSync(originalPath);
|
|
83
|
+
console.log(`SourceMapUploadPlugin: Deleted original sourcemap ${originalPath}`);
|
|
84
|
+
}
|
|
85
|
+
catch (deleteError) {
|
|
86
|
+
const deleteErrorMessage = `SourceMapUploadPlugin: Failed to delete original sourcemap ${originalPath}.`;
|
|
87
|
+
compilation.warnings.push(new core_1.default.WebpackError(`${deleteErrorMessage} Error: ${String(deleteError)}`));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const errorMessage = `SourceMapUploadPlugin: Failed to consolidate ${assetName}.`;
|
|
92
|
+
console.error(errorMessage, error);
|
|
93
|
+
if (error instanceof Error) {
|
|
94
|
+
compilation.errors.push(new Error(`${errorMessage} Error: ${error.message}`));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
compilation.errors.push(new Error(`${errorMessage} Error: ${String(error)}`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.default = SourceMapUploadPlugin;
|
|
@@ -171,8 +171,12 @@ class StaticAssetsPlugin {
|
|
|
171
171
|
return `export default window.__STATIC_JSON__['${key}'];`;
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
const
|
|
175
|
-
|
|
174
|
+
const envBaseUrl = typeof process !== 'undefined' ? process.env?.STATIC_ASSETS_BASE_URL : undefined;
|
|
175
|
+
// envBaseUrl (downloadURLPrefix) 已指向 static 目录,无需再拼 /static/
|
|
176
|
+
const staticUrl = envBaseUrl
|
|
177
|
+
? `${envBaseUrl.replace(/\/+$/, '')}/${relativePath}`
|
|
178
|
+
: `${this.options.clientBasePath}/static/${relativePath}`;
|
|
179
|
+
return `export default ${JSON.stringify(staticUrl)};`;
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
182
|
/**
|
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.47",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"patches",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/traverse": "^7.28.0",
|
|
33
33
|
"@babel/types": "^7.28.2",
|
|
34
34
|
"@lark-apaas/devtool-kits": "^1.2.18",
|
|
35
|
-
"@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.
|
|
35
|
+
"@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.1",
|
|
36
36
|
"@lark-apaas/styled-jsx": "^1.0.1",
|
|
37
37
|
"@rspack/plugin-react-refresh": "^1.5.1",
|
|
38
38
|
"@swc/plugin-styled-jsx": "^11.0.0",
|