@lark-apaas/fullstack-rspack-preset 1.0.37 → 1.0.38-alpha.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
@@ -165,8 +165,6 @@ function createRecommendRspackConfig(options) {
165
165
  'process.env.CWD': JSON.stringify(''),
166
166
  // runtime 注入标志位,用于 client-toolkit 兼容性判断
167
167
  'process.env.__RUNTIME_INJECTED__': JSON.stringify('true'),
168
- // 构建工具标识,用于 source map 处理逻辑判断
169
- 'process.env.BUILD_TOOL': JSON.stringify('rspack'),
170
168
  // 解决 window 未定义问题
171
169
  'typeof window': JSON.stringify('object'),
172
170
  window: 'globalThis',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.37",
3
+ "version": "1.0.38-alpha.0",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",
@@ -31,9 +31,9 @@
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.17",
34
+ "@lark-apaas/devtool-kits": "1.2.17-alpha.20",
35
35
  "@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.0",
36
- "@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.1",
36
+ "@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.0",
37
37
  "@lark-apaas/styled-jsx": "^1.0.1",
38
38
  "@rspack/plugin-react-refresh": "^1.5.1",
39
39
  "@swc/plugin-styled-jsx": "^11.0.0",
@@ -55,6 +55,7 @@
55
55
  "vitest": "^2.1.8"
56
56
  },
57
57
  "peerDependencies": {
58
+ "@lark-apaas/client-toolkit": "^1.2.8",
58
59
  "@rspack/core": "^1.5.5",
59
60
  "react": ">=16.14.0",
60
61
  "react-dom": ">=16.14.0"
@@ -1,9 +0,0 @@
1
- interface EnvironmentInjectionPluginOptions {
2
- environment?: string;
3
- }
4
- declare class EnvironmentInjectionPlugin {
5
- private options;
6
- constructor(options?: EnvironmentInjectionPluginOptions);
7
- apply(compiler: unknown): void;
8
- }
9
- export default EnvironmentInjectionPlugin;
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class EnvironmentInjectionPlugin {
4
- constructor(options) {
5
- this.options = options || {};
6
- }
7
- apply(compiler) {
8
- const compilerLike = getCompilerLike(compiler);
9
- if (!compilerLike)
10
- return;
11
- compilerLike.hooks.compilation.tap('EnvironmentInjectionPlugin', (compilation) => {
12
- try {
13
- const HtmlPlugin = resolveHtmlPlugin(compilerLike);
14
- if (!HtmlPlugin) {
15
- console.warn('EnvironmentInjectionPlugin: HtmlRspackPlugin not found');
16
- return;
17
- }
18
- const hooks = HtmlPlugin.getHooks(compilation);
19
- hooks.alterAssetTagGroups.tap('EnvironmentInjectionPlugin', (data) => {
20
- const mapped = mapToWindowEnvironment(this.options.environment ??
21
- process.env.FORCE_FRAMEWORK_ENVIRONMENT);
22
- const envTag = {
23
- tagName: 'script',
24
- voidTag: false,
25
- innerHTML: `(() => {
26
- const templateValue = '{{environment}}';
27
- const resolved =
28
- templateValue && templateValue !== '{{environment}}'
29
- ? templateValue
30
- : ${JSON.stringify(mapped)};
31
- window.ENVIRONMENT = resolved;
32
- })();`,
33
- attributes: {},
34
- };
35
- const headIndex = findMainJsIndex(data.headTags);
36
- if (headIndex !== -1) {
37
- data.headTags.splice(headIndex, 0, envTag);
38
- return data;
39
- }
40
- const bodyIndex = findMainJsIndex(data.bodyTags);
41
- if (bodyIndex !== -1) {
42
- data.bodyTags.splice(bodyIndex, 0, envTag);
43
- return data;
44
- }
45
- data.headTags.unshift(envTag);
46
- return data;
47
- });
48
- }
49
- catch (error) {
50
- console.error('Error in EnvironmentInjectionPlugin:', error);
51
- }
52
- });
53
- }
54
- }
55
- exports.default = EnvironmentInjectionPlugin;
56
- function mapToWindowEnvironment(input) {
57
- const value = (input || '').trim().toLowerCase();
58
- if (value === 'boe')
59
- return 'staging';
60
- if (value === 'pre')
61
- return 'gray';
62
- if (value === 'online')
63
- return 'online';
64
- return '';
65
- }
66
- function findMainJsIndex(tags) {
67
- if (!Array.isArray(tags))
68
- return -1;
69
- return tags.findIndex((tag) => {
70
- if (!tag || tag.tagName !== 'script')
71
- return false;
72
- const src = tag.attributes?.src;
73
- return typeof src === 'string' && src.includes('main.js');
74
- });
75
- }
76
- function getCompilerLike(input) {
77
- if (!input || typeof input !== 'object')
78
- return;
79
- const hooks = input.hooks;
80
- if (!hooks || typeof hooks !== 'object')
81
- return;
82
- const compilation = hooks.compilation;
83
- if (!compilation || typeof compilation !== 'object')
84
- return;
85
- const tap = compilation.tap;
86
- if (typeof tap !== 'function')
87
- return;
88
- return input;
89
- }
90
- function resolveHtmlPlugin(compiler) {
91
- const fromWebpack = getHtmlPluginLike(compiler.webpack?.HtmlRspackPlugin);
92
- if (fromWebpack)
93
- return fromWebpack;
94
- const fromRspack = getHtmlPluginLike(compiler.rspack?.HtmlRspackPlugin);
95
- if (fromRspack)
96
- return fromRspack;
97
- const fromCtor = getHtmlPluginLike(compiler.constructor?.webpack?.HtmlRspackPlugin);
98
- if (fromCtor)
99
- return fromCtor;
100
- return;
101
- }
102
- function getHtmlPluginLike(value) {
103
- if (!value)
104
- return;
105
- const type = typeof value;
106
- if (type !== 'function' && type !== 'object')
107
- return;
108
- const getHooks = value.getHooks;
109
- if (typeof getHooks !== 'function')
110
- return;
111
- return value;
112
- }