@esmx/rspack 3.0.0-rc.53 → 3.0.0-rc.55
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/dist/rspack/app.d.ts +57 -61
- package/dist/rspack/build-target.d.ts +3 -4
- package/dist/rspack/config.d.ts +1 -1
- package/dist/rspack/config.mjs +1 -1
- package/dist/rspack/loader.d.ts +0 -21
- package/dist/rspack/loader.mjs +0 -21
- package/dist/rspack-html/index.d.ts +39 -56
- package/dist/rspack-html/index.mjs +18 -17
- package/dist/rspack-html/target-setting.d.ts +17 -0
- package/dist/rspack-html/target-setting.mjs +31 -0
- package/dist/rspack-html/target-setting.test.d.ts +1 -0
- package/dist/rspack-html/target-setting.test.mjs +105 -0
- package/package.json +5 -5
- package/src/rspack/app.ts +57 -63
- package/src/rspack/build-target.ts +3 -4
- package/src/rspack/config.ts +2 -2
- package/src/rspack/loader.ts +0 -21
- package/src/rspack/utils/rsbuild.ts +2 -2
- package/src/rspack-html/index.ts +64 -79
- package/src/rspack-html/target-setting.test.ts +123 -0
- package/src/rspack-html/target-setting.ts +52 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { PRESET_TARGETS, getTargetSetting } from "./target-setting.mjs";
|
|
3
|
+
describe("getTargetSetting", () => {
|
|
4
|
+
const buildTargets = ["client", "server", "node"];
|
|
5
|
+
describe("when setting is undefined", () => {
|
|
6
|
+
it("should return compatible preset for all build targets", () => {
|
|
7
|
+
buildTargets.forEach((buildTarget) => {
|
|
8
|
+
const result = getTargetSetting(void 0, buildTarget);
|
|
9
|
+
expect(result).toEqual(PRESET_TARGETS.compatible[buildTarget]);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe("when setting is a string preset", () => {
|
|
14
|
+
it("should return compatible preset for all build targets", () => {
|
|
15
|
+
buildTargets.forEach((buildTarget) => {
|
|
16
|
+
const result = getTargetSetting("compatible", buildTarget);
|
|
17
|
+
expect(result).toEqual(PRESET_TARGETS.compatible[buildTarget]);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it("should return modern preset for all build targets", () => {
|
|
21
|
+
buildTargets.forEach((buildTarget) => {
|
|
22
|
+
const result = getTargetSetting("modern", buildTarget);
|
|
23
|
+
expect(result).toEqual(PRESET_TARGETS.modern[buildTarget]);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("when setting is a custom array", () => {
|
|
28
|
+
const customTargets = ["chrome>=90", "firefox>=80", "safari>=14"];
|
|
29
|
+
it("should return the custom array for all build targets", () => {
|
|
30
|
+
buildTargets.forEach((buildTarget) => {
|
|
31
|
+
const result = getTargetSetting(customTargets, buildTarget);
|
|
32
|
+
expect(result).toEqual(customTargets);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("when setting is an object with specific build targets", () => {
|
|
37
|
+
it("should return specified preset for configured build targets", () => {
|
|
38
|
+
const setting = {
|
|
39
|
+
client: "modern",
|
|
40
|
+
server: "compatible"
|
|
41
|
+
};
|
|
42
|
+
expect(getTargetSetting(setting, "client")).toEqual(
|
|
43
|
+
PRESET_TARGETS.modern.client
|
|
44
|
+
);
|
|
45
|
+
expect(getTargetSetting(setting, "server")).toEqual(
|
|
46
|
+
PRESET_TARGETS.compatible.server
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
it("should return compatible preset for unconfigured build targets", () => {
|
|
50
|
+
const setting = {
|
|
51
|
+
client: "modern"
|
|
52
|
+
};
|
|
53
|
+
expect(getTargetSetting(setting, "client")).toEqual(
|
|
54
|
+
PRESET_TARGETS.modern.client
|
|
55
|
+
);
|
|
56
|
+
expect(getTargetSetting(setting, "server")).toEqual(
|
|
57
|
+
PRESET_TARGETS.compatible.server
|
|
58
|
+
);
|
|
59
|
+
expect(getTargetSetting(setting, "node")).toEqual(
|
|
60
|
+
PRESET_TARGETS.compatible.node
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
it("should return custom array for configured build targets", () => {
|
|
64
|
+
const customClientTargets = ["chrome>=90", "firefox>=80"];
|
|
65
|
+
const customServerTargets = ["node>=18"];
|
|
66
|
+
const setting = {
|
|
67
|
+
client: customClientTargets,
|
|
68
|
+
server: customServerTargets
|
|
69
|
+
};
|
|
70
|
+
expect(getTargetSetting(setting, "client")).toEqual(
|
|
71
|
+
customClientTargets
|
|
72
|
+
);
|
|
73
|
+
expect(getTargetSetting(setting, "server")).toEqual(
|
|
74
|
+
customServerTargets
|
|
75
|
+
);
|
|
76
|
+
expect(getTargetSetting(setting, "node")).toEqual(
|
|
77
|
+
PRESET_TARGETS.compatible.node
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
it("should handle mixed preset and custom configurations", () => {
|
|
81
|
+
const setting = {
|
|
82
|
+
client: "modern",
|
|
83
|
+
server: ["node>=18"],
|
|
84
|
+
node: "compatible"
|
|
85
|
+
};
|
|
86
|
+
expect(getTargetSetting(setting, "client")).toEqual(
|
|
87
|
+
PRESET_TARGETS.modern.client
|
|
88
|
+
);
|
|
89
|
+
expect(getTargetSetting(setting, "server")).toEqual(["node>=18"]);
|
|
90
|
+
expect(getTargetSetting(setting, "node")).toEqual(
|
|
91
|
+
PRESET_TARGETS.compatible.node
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe("edge cases", () => {
|
|
96
|
+
it("should handle empty custom array", () => {
|
|
97
|
+
const result = getTargetSetting([], "client");
|
|
98
|
+
expect(result).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
it("should handle single item custom array", () => {
|
|
101
|
+
const result = getTargetSetting(["chrome>=90"], "client");
|
|
102
|
+
expect(result).toEqual(["chrome>=90"]);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
package/package.json
CHANGED
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@esmx/import": "3.0.0-rc.
|
|
67
|
-
"@esmx/rspack-module-link-plugin": "3.0.0-rc.
|
|
66
|
+
"@esmx/import": "3.0.0-rc.55",
|
|
67
|
+
"@esmx/rspack-module-link-plugin": "3.0.0-rc.55",
|
|
68
68
|
"@npmcli/arborist": "^9.0.1",
|
|
69
69
|
"@rspack/core": "1.4.8",
|
|
70
70
|
"css-loader": "^7.1.2",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@biomejs/biome": "1.9.4",
|
|
83
|
-
"@esmx/core": "3.0.0-rc.
|
|
83
|
+
"@esmx/core": "3.0.0-rc.55",
|
|
84
84
|
"@types/node": "^24.0.0",
|
|
85
85
|
"@types/npmcli__arborist": "^6.3.1",
|
|
86
86
|
"@types/pacote": "^11.1.8",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"unbuild": "3.5.0",
|
|
92
92
|
"vitest": "3.2.4"
|
|
93
93
|
},
|
|
94
|
-
"version": "3.0.0-rc.
|
|
94
|
+
"version": "3.0.0-rc.55",
|
|
95
95
|
"type": "module",
|
|
96
96
|
"private": false,
|
|
97
97
|
"exports": {
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"template",
|
|
111
111
|
"public"
|
|
112
112
|
],
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "e7d0c88a376ad5bd3d88a48240e4ed4891c0b275"
|
|
114
114
|
}
|
package/src/rspack/app.ts
CHANGED
|
@@ -26,13 +26,13 @@ const hotFixCode = fs.readFileSync(
|
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* Rspack
|
|
29
|
+
* Rspack application configuration context interface.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
* -
|
|
34
|
-
* -
|
|
35
|
-
* -
|
|
31
|
+
* This interface provides context information accessible in configuration hook functions, allowing you to:
|
|
32
|
+
* - Access the Esmx framework instance
|
|
33
|
+
* - Get the current build target (client/server/node)
|
|
34
|
+
* - Modify Rspack configuration
|
|
35
|
+
* - Access application options
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```ts
|
|
@@ -41,11 +41,11 @@ const hotFixCode = fs.readFileSync(
|
|
|
41
41
|
* async devApp(esmx) {
|
|
42
42
|
* return import('@esmx/rspack').then((m) =>
|
|
43
43
|
* m.createRspackApp(esmx, {
|
|
44
|
-
* //
|
|
44
|
+
* // Configuration hook function
|
|
45
45
|
* config(context) {
|
|
46
|
-
* //
|
|
46
|
+
* // Access build target
|
|
47
47
|
* if (context.buildTarget === 'client') {
|
|
48
|
-
* //
|
|
48
|
+
* // Modify client build configuration
|
|
49
49
|
* context.config.optimization = {
|
|
50
50
|
* ...context.config.optimization,
|
|
51
51
|
* splitChunks: {
|
|
@@ -62,73 +62,73 @@ const hotFixCode = fs.readFileSync(
|
|
|
62
62
|
*/
|
|
63
63
|
export interface RspackAppConfigContext {
|
|
64
64
|
/**
|
|
65
|
-
* Esmx
|
|
66
|
-
*
|
|
65
|
+
* Esmx framework instance.
|
|
66
|
+
* Can be used to access framework APIs and utility functions.
|
|
67
67
|
*/
|
|
68
68
|
esmx: Esmx;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* - 'client':
|
|
73
|
-
* - 'server':
|
|
74
|
-
* - 'node': Node.js
|
|
71
|
+
* Current build target.
|
|
72
|
+
* - 'client': Client build, generates browser-executable code
|
|
73
|
+
* - 'server': Server build, generates SSR rendering code
|
|
74
|
+
* - 'node': Node.js build, generates server entry code
|
|
75
75
|
*/
|
|
76
76
|
buildTarget: BuildTarget;
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* Rspack
|
|
80
|
-
*
|
|
79
|
+
* Rspack compilation configuration object.
|
|
80
|
+
* You can modify this object in configuration hooks to customize build behavior.
|
|
81
81
|
*/
|
|
82
82
|
config: RspackOptions;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Options object passed when creating the application.
|
|
86
86
|
*/
|
|
87
87
|
options: RspackAppOptions;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Rspack
|
|
91
|
+
* Rspack chain configuration context interface.
|
|
92
92
|
*
|
|
93
|
-
*
|
|
94
|
-
* -
|
|
95
|
-
* -
|
|
96
|
-
* -
|
|
97
|
-
* -
|
|
93
|
+
* This interface provides context information accessible in chain hook functions, allowing you to:
|
|
94
|
+
* - Access the Esmx framework instance
|
|
95
|
+
* - Get the current build target (client/server/node)
|
|
96
|
+
* - Modify configuration using rspack-chain
|
|
97
|
+
* - Access application options
|
|
98
98
|
*/
|
|
99
99
|
export interface RspackAppChainContext {
|
|
100
100
|
/**
|
|
101
|
-
* Esmx
|
|
102
|
-
*
|
|
101
|
+
* Esmx framework instance.
|
|
102
|
+
* Can be used to access framework APIs and utility functions.
|
|
103
103
|
*/
|
|
104
104
|
esmx: Esmx;
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
108
|
-
* - 'client':
|
|
109
|
-
* - 'server':
|
|
110
|
-
* - 'node': Node.js
|
|
107
|
+
* Current build target.
|
|
108
|
+
* - 'client': Client build, generates browser-executable code
|
|
109
|
+
* - 'server': Server build, generates SSR rendering code
|
|
110
|
+
* - 'node': Node.js build, generates server entry code
|
|
111
111
|
*/
|
|
112
112
|
buildTarget: BuildTarget;
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* rspack-chain
|
|
116
|
-
*
|
|
115
|
+
* rspack-chain configuration object.
|
|
116
|
+
* You can use the chain API in chain hooks to modify the configuration.
|
|
117
117
|
*/
|
|
118
118
|
chain: import('rspack-chain');
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Options object passed when creating the application.
|
|
122
122
|
*/
|
|
123
123
|
options: RspackAppOptions;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* Rspack
|
|
127
|
+
* Rspack application configuration options interface.
|
|
128
128
|
*
|
|
129
|
-
*
|
|
130
|
-
* -
|
|
131
|
-
* - Rspack
|
|
129
|
+
* This interface provides configuration options available when creating a Rspack application, including:
|
|
130
|
+
* - Code compression options
|
|
131
|
+
* - Rspack configuration hook functions
|
|
132
132
|
*
|
|
133
133
|
* @example
|
|
134
134
|
* ```ts
|
|
@@ -137,9 +137,9 @@ export interface RspackAppChainContext {
|
|
|
137
137
|
* async devApp(esmx) {
|
|
138
138
|
* return import('@esmx/rspack').then((m) =>
|
|
139
139
|
* m.createRspackApp(esmx, {
|
|
140
|
-
* //
|
|
140
|
+
* // Disable code compression
|
|
141
141
|
* minimize: false,
|
|
142
|
-
* //
|
|
142
|
+
* // Custom Rspack configuration
|
|
143
143
|
* config(context) {
|
|
144
144
|
* if (context.buildTarget === 'client') {
|
|
145
145
|
* context.config.optimization.splitChunks = {
|
|
@@ -155,47 +155,43 @@ export interface RspackAppChainContext {
|
|
|
155
155
|
*/
|
|
156
156
|
export interface RspackAppOptions {
|
|
157
157
|
/**
|
|
158
|
-
*
|
|
158
|
+
* Whether to enable code compression.
|
|
159
159
|
*
|
|
160
|
-
* - true:
|
|
161
|
-
* - false:
|
|
162
|
-
* - undefined:
|
|
160
|
+
* - true: Enable code compression
|
|
161
|
+
* - false: Disable code compression
|
|
162
|
+
* - undefined: Automatically determine based on environment (enabled in production, disabled in development)
|
|
163
163
|
*
|
|
164
164
|
* @default undefined
|
|
165
165
|
*/
|
|
166
166
|
minimize?: boolean;
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Rspack
|
|
169
|
+
* Called before the build starts, this function allows you to modify the Rspack compilation configuration.
|
|
170
|
+
* Supports differentiated configuration for different build targets (client/server/node).
|
|
170
171
|
*
|
|
171
|
-
*
|
|
172
|
-
* 支持针对不同的构建目标(client/server/node)进行差异化配置。
|
|
173
|
-
*
|
|
174
|
-
* @param context - 配置上下文,包含框架实例、构建目标和配置对象
|
|
172
|
+
* @param context - Configuration context, containing framework instance, build target, and configuration object
|
|
175
173
|
*/
|
|
176
174
|
config?: (context: RspackAppConfigContext) => void;
|
|
177
175
|
|
|
178
176
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* 使用 rspack-chain 提供链式配置方式,可以更灵活地修改 Rspack 配置。
|
|
182
|
-
* 在 config 钩子之后调用,如果有 chain 钩子则优先使用链式配置。
|
|
177
|
+
* Uses rspack-chain to provide chained configuration method, allowing more flexible modification of Rspack configuration.
|
|
178
|
+
* Called after the config hook, if chain hook exists, chained configuration is preferred.
|
|
183
179
|
*
|
|
184
|
-
* @param context -
|
|
180
|
+
* @param context - Configuration context, containing framework instance, build target, and chain configuration object
|
|
185
181
|
*/
|
|
186
182
|
chain?: (context: RspackAppChainContext) => void;
|
|
187
183
|
}
|
|
188
184
|
|
|
189
185
|
/**
|
|
190
|
-
*
|
|
186
|
+
* Create Rspack application instance.
|
|
191
187
|
*
|
|
192
|
-
*
|
|
193
|
-
* -
|
|
194
|
-
* -
|
|
188
|
+
* This function creates different application instances based on the runtime environment (development/production):
|
|
189
|
+
* - Development environment: Configures hot update middleware and real-time rendering
|
|
190
|
+
* - Production environment: Configures build tasks
|
|
195
191
|
*
|
|
196
|
-
* @param esmx - Esmx
|
|
197
|
-
* @param options - Rspack
|
|
198
|
-
* @returns
|
|
192
|
+
* @param esmx - Esmx framework instance
|
|
193
|
+
* @param options - Rspack application configuration options
|
|
194
|
+
* @returns Returns application instance
|
|
199
195
|
*
|
|
200
196
|
* @example
|
|
201
197
|
* ```ts
|
|
@@ -205,7 +201,7 @@ export interface RspackAppOptions {
|
|
|
205
201
|
* return import('@esmx/rspack').then((m) =>
|
|
206
202
|
* m.createRspackApp(esmx, {
|
|
207
203
|
* config(context) {
|
|
208
|
-
* //
|
|
204
|
+
* // Configure loader to handle different file types
|
|
209
205
|
* context.config.module = {
|
|
210
206
|
* rules: [
|
|
211
207
|
* {
|
|
@@ -259,8 +255,6 @@ async function createMiddleware(
|
|
|
259
255
|
if (esmx.command !== esmx.COMMAND.dev) {
|
|
260
256
|
return [];
|
|
261
257
|
}
|
|
262
|
-
// const middlewares: Middleware[] = [];
|
|
263
|
-
|
|
264
258
|
const rsBuild = createRsBuild([
|
|
265
259
|
generateBuildConfig(esmx, options, 'client'),
|
|
266
260
|
generateBuildConfig(esmx, options, 'server')
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Build target environment type
|
|
3
|
-
*
|
|
4
|
-
* -
|
|
5
|
-
* -
|
|
6
|
-
* - server: Build code to run in server environment
|
|
3
|
+
* - node: Node.js environment build
|
|
4
|
+
* - client: Browser environment build
|
|
5
|
+
* - server: Server-side rendering build
|
|
7
6
|
*/
|
|
8
7
|
export type BuildTarget = 'node' | 'client' | 'server';
|
package/src/rspack/config.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { BuildTarget } from './build-target';
|
|
|
13
13
|
import { HMR_DIR, HMR_JSONP } from './hmr-config';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Base configuration for building Client, Server, and Node targets
|
|
17
17
|
*/
|
|
18
18
|
export function createRspackConfig(
|
|
19
19
|
esmx: Esmx,
|
|
@@ -23,7 +23,7 @@ export function createRspackConfig(
|
|
|
23
23
|
const isHot = buildTarget === 'client' && !esmx.isProd;
|
|
24
24
|
return {
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Project root directory, cannot be modified
|
|
27
27
|
*/
|
|
28
28
|
context: esmx.root,
|
|
29
29
|
output: {
|
package/src/rspack/loader.ts
CHANGED
|
@@ -5,32 +5,11 @@ function resolve(name: string) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export const RSPACK_LOADER = {
|
|
8
|
-
/**
|
|
9
|
-
* Rspack 内置的 builtin:swc-loader
|
|
10
|
-
*/
|
|
11
8
|
builtinSwcLoader: 'builtin:swc-loader',
|
|
12
|
-
/**
|
|
13
|
-
* Rspack 内置的 lightningcss-loader
|
|
14
|
-
*/
|
|
15
9
|
lightningcssLoader: 'builtin:lightningcss-loader',
|
|
16
|
-
/**
|
|
17
|
-
* css-loader
|
|
18
|
-
*/
|
|
19
10
|
cssLoader: resolve('css-loader'),
|
|
20
|
-
/**
|
|
21
|
-
* style-loader
|
|
22
|
-
*/
|
|
23
11
|
styleLoader: resolve('style-loader'),
|
|
24
|
-
/**
|
|
25
|
-
* less-loader
|
|
26
|
-
*/
|
|
27
12
|
lessLoader: resolve('less-loader'),
|
|
28
|
-
/**
|
|
29
|
-
* style-resources-loader
|
|
30
|
-
*/
|
|
31
13
|
styleResourcesLoader: resolve('style-resources-loader'),
|
|
32
|
-
/**
|
|
33
|
-
* worker-rspack-loader
|
|
34
|
-
*/
|
|
35
14
|
workerRspackLoader: resolve('worker-rspack-loader')
|
|
36
15
|
} satisfies Record<string, string>;
|
|
@@ -51,7 +51,7 @@ export function createRsBuild(options: RspackOptions[]) {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
//
|
|
54
|
+
// Listen to process signals to ensure graceful shutdown
|
|
55
55
|
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] satisfies string[];
|
|
56
56
|
signals.forEach((signal) => {
|
|
57
57
|
process.on(signal, () => {
|
|
@@ -61,7 +61,7 @@ export function createRsBuild(options: RspackOptions[]) {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
//
|
|
64
|
+
// Listen to uncaught exceptions and Promise rejections
|
|
65
65
|
process.on('uncaughtException', handleExit);
|
|
66
66
|
process.on('unhandledRejection', handleExit);
|
|
67
67
|
|