@esmx/rspack 3.0.0-rc.54 → 3.0.0-rc.56
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/chain-config.mjs +2 -2
- package/dist/rspack/config.d.ts +1 -1
- package/dist/rspack/config.mjs +3 -3
- 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 +8 -8
- package/src/rspack/app.ts +57 -63
- package/src/rspack/build-target.ts +3 -4
- package/src/rspack/chain-config.ts +2 -2
- package/src/rspack/config.ts +4 -4
- 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
package/dist/rspack/app.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { type App, type Esmx } from '@esmx/core';
|
|
|
2
2
|
import type { RspackOptions } from '@rspack/core';
|
|
3
3
|
import type { BuildTarget } from './build-target';
|
|
4
4
|
/**
|
|
5
|
-
* Rspack
|
|
5
|
+
* Rspack application configuration context interface.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
7
|
+
* This interface provides context information accessible in configuration hook functions, allowing you to:
|
|
8
|
+
* - Access the Esmx framework instance
|
|
9
|
+
* - Get the current build target (client/server/node)
|
|
10
|
+
* - Modify Rspack configuration
|
|
11
|
+
* - Access application options
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
@@ -17,11 +17,11 @@ import type { BuildTarget } from './build-target';
|
|
|
17
17
|
* async devApp(esmx) {
|
|
18
18
|
* return import('@esmx/rspack').then((m) =>
|
|
19
19
|
* m.createRspackApp(esmx, {
|
|
20
|
-
* //
|
|
20
|
+
* // Configuration hook function
|
|
21
21
|
* config(context) {
|
|
22
|
-
* //
|
|
22
|
+
* // Access build target
|
|
23
23
|
* if (context.buildTarget === 'client') {
|
|
24
|
-
* //
|
|
24
|
+
* // Modify client build configuration
|
|
25
25
|
* context.config.optimization = {
|
|
26
26
|
* ...context.config.optimization,
|
|
27
27
|
* splitChunks: {
|
|
@@ -38,65 +38,65 @@ import type { BuildTarget } from './build-target';
|
|
|
38
38
|
*/
|
|
39
39
|
export interface RspackAppConfigContext {
|
|
40
40
|
/**
|
|
41
|
-
* Esmx
|
|
42
|
-
*
|
|
41
|
+
* Esmx framework instance.
|
|
42
|
+
* Can be used to access framework APIs and utility functions.
|
|
43
43
|
*/
|
|
44
44
|
esmx: Esmx;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
* - 'client':
|
|
48
|
-
* - 'server':
|
|
49
|
-
* - 'node': Node.js
|
|
46
|
+
* Current build target.
|
|
47
|
+
* - 'client': Client build, generates browser-executable code
|
|
48
|
+
* - 'server': Server build, generates SSR rendering code
|
|
49
|
+
* - 'node': Node.js build, generates server entry code
|
|
50
50
|
*/
|
|
51
51
|
buildTarget: BuildTarget;
|
|
52
52
|
/**
|
|
53
|
-
* Rspack
|
|
54
|
-
*
|
|
53
|
+
* Rspack compilation configuration object.
|
|
54
|
+
* You can modify this object in configuration hooks to customize build behavior.
|
|
55
55
|
*/
|
|
56
56
|
config: RspackOptions;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Options object passed when creating the application.
|
|
59
59
|
*/
|
|
60
60
|
options: RspackAppOptions;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Rspack
|
|
63
|
+
* Rspack chain configuration context interface.
|
|
64
64
|
*
|
|
65
|
-
*
|
|
66
|
-
* -
|
|
67
|
-
* -
|
|
68
|
-
* -
|
|
69
|
-
* -
|
|
65
|
+
* This interface provides context information accessible in chain hook functions, allowing you to:
|
|
66
|
+
* - Access the Esmx framework instance
|
|
67
|
+
* - Get the current build target (client/server/node)
|
|
68
|
+
* - Modify configuration using rspack-chain
|
|
69
|
+
* - Access application options
|
|
70
70
|
*/
|
|
71
71
|
export interface RspackAppChainContext {
|
|
72
72
|
/**
|
|
73
|
-
* Esmx
|
|
74
|
-
*
|
|
73
|
+
* Esmx framework instance.
|
|
74
|
+
* Can be used to access framework APIs and utility functions.
|
|
75
75
|
*/
|
|
76
76
|
esmx: Esmx;
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* - 'client':
|
|
80
|
-
* - 'server':
|
|
81
|
-
* - 'node': Node.js
|
|
78
|
+
* Current build target.
|
|
79
|
+
* - 'client': Client build, generates browser-executable code
|
|
80
|
+
* - 'server': Server build, generates SSR rendering code
|
|
81
|
+
* - 'node': Node.js build, generates server entry code
|
|
82
82
|
*/
|
|
83
83
|
buildTarget: BuildTarget;
|
|
84
84
|
/**
|
|
85
|
-
* rspack-chain
|
|
86
|
-
*
|
|
85
|
+
* rspack-chain configuration object.
|
|
86
|
+
* You can use the chain API in chain hooks to modify the configuration.
|
|
87
87
|
*/
|
|
88
88
|
chain: import('rspack-chain');
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
90
|
+
* Options object passed when creating the application.
|
|
91
91
|
*/
|
|
92
92
|
options: RspackAppOptions;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* Rspack
|
|
95
|
+
* Rspack application configuration options interface.
|
|
96
96
|
*
|
|
97
|
-
*
|
|
98
|
-
* -
|
|
99
|
-
* - Rspack
|
|
97
|
+
* This interface provides configuration options available when creating a Rspack application, including:
|
|
98
|
+
* - Code compression options
|
|
99
|
+
* - Rspack configuration hook functions
|
|
100
100
|
*
|
|
101
101
|
* @example
|
|
102
102
|
* ```ts
|
|
@@ -105,9 +105,9 @@ export interface RspackAppChainContext {
|
|
|
105
105
|
* async devApp(esmx) {
|
|
106
106
|
* return import('@esmx/rspack').then((m) =>
|
|
107
107
|
* m.createRspackApp(esmx, {
|
|
108
|
-
* //
|
|
108
|
+
* // Disable code compression
|
|
109
109
|
* minimize: false,
|
|
110
|
-
* //
|
|
110
|
+
* // Custom Rspack configuration
|
|
111
111
|
* config(context) {
|
|
112
112
|
* if (context.buildTarget === 'client') {
|
|
113
113
|
* context.config.optimization.splitChunks = {
|
|
@@ -123,44 +123,40 @@ export interface RspackAppChainContext {
|
|
|
123
123
|
*/
|
|
124
124
|
export interface RspackAppOptions {
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
126
|
+
* Whether to enable code compression.
|
|
127
127
|
*
|
|
128
|
-
* - true:
|
|
129
|
-
* - false:
|
|
130
|
-
* - undefined:
|
|
128
|
+
* - true: Enable code compression
|
|
129
|
+
* - false: Disable code compression
|
|
130
|
+
* - undefined: Automatically determine based on environment (enabled in production, disabled in development)
|
|
131
131
|
*
|
|
132
132
|
* @default undefined
|
|
133
133
|
*/
|
|
134
134
|
minimize?: boolean;
|
|
135
135
|
/**
|
|
136
|
-
* Rspack
|
|
136
|
+
* Called before the build starts, this function allows you to modify the Rspack compilation configuration.
|
|
137
|
+
* Supports differentiated configuration for different build targets (client/server/node).
|
|
137
138
|
*
|
|
138
|
-
*
|
|
139
|
-
* 支持针对不同的构建目标(client/server/node)进行差异化配置。
|
|
140
|
-
*
|
|
141
|
-
* @param context - 配置上下文,包含框架实例、构建目标和配置对象
|
|
139
|
+
* @param context - Configuration context, containing framework instance, build target, and configuration object
|
|
142
140
|
*/
|
|
143
141
|
config?: (context: RspackAppConfigContext) => void;
|
|
144
142
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* 使用 rspack-chain 提供链式配置方式,可以更灵活地修改 Rspack 配置。
|
|
148
|
-
* 在 config 钩子之后调用,如果有 chain 钩子则优先使用链式配置。
|
|
143
|
+
* Uses rspack-chain to provide chained configuration method, allowing more flexible modification of Rspack configuration.
|
|
144
|
+
* Called after the config hook, if chain hook exists, chained configuration is preferred.
|
|
149
145
|
*
|
|
150
|
-
* @param context -
|
|
146
|
+
* @param context - Configuration context, containing framework instance, build target, and chain configuration object
|
|
151
147
|
*/
|
|
152
148
|
chain?: (context: RspackAppChainContext) => void;
|
|
153
149
|
}
|
|
154
150
|
/**
|
|
155
|
-
*
|
|
151
|
+
* Create Rspack application instance.
|
|
156
152
|
*
|
|
157
|
-
*
|
|
158
|
-
* -
|
|
159
|
-
* -
|
|
153
|
+
* This function creates different application instances based on the runtime environment (development/production):
|
|
154
|
+
* - Development environment: Configures hot update middleware and real-time rendering
|
|
155
|
+
* - Production environment: Configures build tasks
|
|
160
156
|
*
|
|
161
|
-
* @param esmx - Esmx
|
|
162
|
-
* @param options - Rspack
|
|
163
|
-
* @returns
|
|
157
|
+
* @param esmx - Esmx framework instance
|
|
158
|
+
* @param options - Rspack application configuration options
|
|
159
|
+
* @returns Returns application instance
|
|
164
160
|
*
|
|
165
161
|
* @example
|
|
166
162
|
* ```ts
|
|
@@ -170,7 +166,7 @@ export interface RspackAppOptions {
|
|
|
170
166
|
* return import('@esmx/rspack').then((m) =>
|
|
171
167
|
* m.createRspackApp(esmx, {
|
|
172
168
|
* config(context) {
|
|
173
|
-
* //
|
|
169
|
+
* // Configure loader to handle different file types
|
|
174
170
|
* context.config.module = {
|
|
175
171
|
* rules: [
|
|
176
172
|
* {
|
|
@@ -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';
|
|
@@ -102,10 +102,10 @@ function createModuleLinkConfig(esmx, buildTarget) {
|
|
|
102
102
|
}
|
|
103
103
|
const exports = {};
|
|
104
104
|
for (const [name, item] of Object.entries(esmx.moduleConfig.exports)) {
|
|
105
|
-
if (item.
|
|
105
|
+
if (item.entryPoints[buildTarget]) {
|
|
106
106
|
exports[name] = {
|
|
107
107
|
rewrite: item.rewrite,
|
|
108
|
-
file: item.
|
|
108
|
+
file: item.entryPoints[buildTarget]
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
}
|
package/dist/rspack/config.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { type RspackOptions } from '@rspack/core';
|
|
|
3
3
|
import type { RspackAppOptions } from './app';
|
|
4
4
|
import type { BuildTarget } from './build-target';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Base configuration for building Client, Server, and Node targets
|
|
7
7
|
*/
|
|
8
8
|
export declare function createRspackConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackOptions;
|
package/dist/rspack/config.mjs
CHANGED
|
@@ -8,7 +8,7 @@ export function createRspackConfig(esmx, buildTarget, options) {
|
|
|
8
8
|
const isHot = buildTarget === "client" && !esmx.isProd;
|
|
9
9
|
return {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Project root directory, cannot be modified
|
|
12
12
|
*/
|
|
13
13
|
context: esmx.root,
|
|
14
14
|
output: {
|
|
@@ -110,10 +110,10 @@ function createModuleLinkPlugin(esmx, buildTarget) {
|
|
|
110
110
|
}
|
|
111
111
|
const exports = {};
|
|
112
112
|
for (const [name, item] of Object.entries(esmx.moduleConfig.exports)) {
|
|
113
|
-
if (item.
|
|
113
|
+
if (item.entryPoints[buildTarget]) {
|
|
114
114
|
exports[name] = {
|
|
115
115
|
rewrite: item.rewrite,
|
|
116
|
-
file: item.
|
|
116
|
+
file: item.entryPoints[buildTarget]
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
}
|
package/dist/rspack/loader.d.ts
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
export declare const RSPACK_LOADER: {
|
|
2
|
-
/**
|
|
3
|
-
* Rspack 内置的 builtin:swc-loader
|
|
4
|
-
*/
|
|
5
2
|
builtinSwcLoader: string;
|
|
6
|
-
/**
|
|
7
|
-
* Rspack 内置的 lightningcss-loader
|
|
8
|
-
*/
|
|
9
3
|
lightningcssLoader: string;
|
|
10
|
-
/**
|
|
11
|
-
* css-loader
|
|
12
|
-
*/
|
|
13
4
|
cssLoader: string;
|
|
14
|
-
/**
|
|
15
|
-
* style-loader
|
|
16
|
-
*/
|
|
17
5
|
styleLoader: string;
|
|
18
|
-
/**
|
|
19
|
-
* less-loader
|
|
20
|
-
*/
|
|
21
6
|
lessLoader: string;
|
|
22
|
-
/**
|
|
23
|
-
* style-resources-loader
|
|
24
|
-
*/
|
|
25
7
|
styleResourcesLoader: string;
|
|
26
|
-
/**
|
|
27
|
-
* worker-rspack-loader
|
|
28
|
-
*/
|
|
29
8
|
workerRspackLoader: string;
|
|
30
9
|
};
|
package/dist/rspack/loader.mjs
CHANGED
|
@@ -3,32 +3,11 @@ function resolve(name) {
|
|
|
3
3
|
return fileURLToPath(import.meta.resolve(name));
|
|
4
4
|
}
|
|
5
5
|
export const RSPACK_LOADER = {
|
|
6
|
-
/**
|
|
7
|
-
* Rspack 内置的 builtin:swc-loader
|
|
8
|
-
*/
|
|
9
6
|
builtinSwcLoader: "builtin:swc-loader",
|
|
10
|
-
/**
|
|
11
|
-
* Rspack 内置的 lightningcss-loader
|
|
12
|
-
*/
|
|
13
7
|
lightningcssLoader: "builtin:lightningcss-loader",
|
|
14
|
-
/**
|
|
15
|
-
* css-loader
|
|
16
|
-
*/
|
|
17
8
|
cssLoader: resolve("css-loader"),
|
|
18
|
-
/**
|
|
19
|
-
* style-loader
|
|
20
|
-
*/
|
|
21
9
|
styleLoader: resolve("style-loader"),
|
|
22
|
-
/**
|
|
23
|
-
* less-loader
|
|
24
|
-
*/
|
|
25
10
|
lessLoader: resolve("less-loader"),
|
|
26
|
-
/**
|
|
27
|
-
* style-resources-loader
|
|
28
|
-
*/
|
|
29
11
|
styleResourcesLoader: resolve("style-resources-loader"),
|
|
30
|
-
/**
|
|
31
|
-
* worker-rspack-loader
|
|
32
|
-
*/
|
|
33
12
|
workerRspackLoader: resolve("worker-rspack-loader")
|
|
34
13
|
};
|
|
@@ -1,42 +1,44 @@
|
|
|
1
1
|
import type { Esmx } from '@esmx/core';
|
|
2
2
|
import { type SwcLoaderOptions } from '@rspack/core';
|
|
3
3
|
import { type BuildTarget, RSPACK_LOADER, type RspackAppOptions } from '../rspack';
|
|
4
|
+
import type { TargetSetting } from './target-setting';
|
|
5
|
+
export type { TargetSetting };
|
|
4
6
|
export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
5
7
|
/**
|
|
6
|
-
* CSS
|
|
8
|
+
* CSS output mode configuration
|
|
7
9
|
*
|
|
8
|
-
* @default
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
10
|
+
* @default Automatically selected based on environment:
|
|
11
|
+
* - Production: 'css', outputs CSS to separate files for better caching and parallel loading
|
|
12
|
+
* - Development: 'js', bundles CSS into JS to support hot module replacement (HMR) for instant style updates
|
|
11
13
|
*
|
|
12
|
-
* - 'css':
|
|
13
|
-
* - 'js':
|
|
14
|
-
* - false:
|
|
14
|
+
* - 'css': Output CSS to separate CSS files
|
|
15
|
+
* - 'js': Bundle CSS into JS files and dynamically inject styles at runtime
|
|
16
|
+
* - false: Disable default CSS processing configuration, requires manual loader rule configuration
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* ```ts
|
|
18
|
-
* //
|
|
20
|
+
* // Use environment default configuration
|
|
19
21
|
* css: undefined
|
|
20
22
|
*
|
|
21
|
-
* //
|
|
23
|
+
* // Force output to separate CSS files
|
|
22
24
|
* css: 'css'
|
|
23
25
|
*
|
|
24
|
-
* //
|
|
26
|
+
* // Force bundle into JS
|
|
25
27
|
* css: 'js'
|
|
26
28
|
*
|
|
27
|
-
* //
|
|
29
|
+
* // Custom CSS processing
|
|
28
30
|
* css: false
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
33
|
css?: 'css' | 'js' | false;
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* Custom loader configuration
|
|
34
36
|
*
|
|
35
|
-
*
|
|
37
|
+
* Allows replacing default loader implementations, useful for switching to framework-specific loaders
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
39
|
-
* //
|
|
41
|
+
* // Use Vue's style-loader
|
|
40
42
|
* loaders: {
|
|
41
43
|
* styleLoader: 'vue-style-loader'
|
|
42
44
|
* }
|
|
@@ -44,9 +46,7 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
44
46
|
*/
|
|
45
47
|
loaders?: Partial<Record<keyof typeof RSPACK_LOADER, string>>;
|
|
46
48
|
/**
|
|
47
|
-
* style
|
|
48
|
-
*
|
|
49
|
-
* 用于配置样式注入方式,完整选项参考:
|
|
49
|
+
* Configure style injection method. For complete options, see:
|
|
50
50
|
* https://github.com/webpack-contrib/style-loader
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
@@ -59,9 +59,7 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
59
59
|
*/
|
|
60
60
|
styleLoader?: Record<string, any>;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* 用于配置 CSS 模块化、URL 解析等,完整选项参考:
|
|
62
|
+
* Configure CSS modules, URL resolution, etc. For complete options, see:
|
|
65
63
|
* https://github.com/webpack-contrib/css-loader
|
|
66
64
|
*
|
|
67
65
|
* @example
|
|
@@ -74,9 +72,7 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
74
72
|
*/
|
|
75
73
|
cssLoader?: Record<string, any>;
|
|
76
74
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* 用于配置 Less 编译选项,完整选项参考:
|
|
75
|
+
* Configure Less compilation options. For complete options, see:
|
|
80
76
|
* https://github.com/webpack-contrib/less-loader
|
|
81
77
|
*
|
|
82
78
|
* @example
|
|
@@ -91,9 +87,7 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
91
87
|
*/
|
|
92
88
|
lessLoader?: Record<string, any>;
|
|
93
89
|
/**
|
|
94
|
-
* style
|
|
95
|
-
*
|
|
96
|
-
* 用于自动注入全局的样式资源,完整选项参考:
|
|
90
|
+
* Automatically inject global style resources. For complete options, see:
|
|
97
91
|
* https://github.com/yenshih/style-resources-loader
|
|
98
92
|
*
|
|
99
93
|
* @example
|
|
@@ -108,9 +102,7 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
108
102
|
*/
|
|
109
103
|
styleResourcesLoader?: Record<string, any>;
|
|
110
104
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* 用于配置 TypeScript/JavaScript 编译选项,完整选项参考:
|
|
105
|
+
* Configure TypeScript/JavaScript compilation options. For complete options, see:
|
|
114
106
|
* https://rspack.dev/guide/features/builtin-swc-loader
|
|
115
107
|
*
|
|
116
108
|
* @example
|
|
@@ -130,19 +122,17 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
130
122
|
*/
|
|
131
123
|
swcLoader?: SwcLoaderOptions;
|
|
132
124
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* 用于定义编译时的全局常量,支持针对不同构建目标设置不同的值
|
|
136
|
-
* 完整说明参考: https://rspack.dev/plugins/webpack/define-plugin
|
|
125
|
+
* Define compile-time global constants, supports setting different values for different build targets
|
|
126
|
+
* For complete documentation, see: https://rspack.dev/plugins/webpack/define-plugin
|
|
137
127
|
*
|
|
138
128
|
* @example
|
|
139
129
|
* ```ts
|
|
140
|
-
* //
|
|
130
|
+
* // Unified value
|
|
141
131
|
* definePlugin: {
|
|
142
132
|
* 'process.env.APP_ENV': JSON.stringify('production')
|
|
143
133
|
* }
|
|
144
134
|
*
|
|
145
|
-
* //
|
|
135
|
+
* // Values for different build targets
|
|
146
136
|
* definePlugin: {
|
|
147
137
|
* 'process.env.IS_SERVER': {
|
|
148
138
|
* server: 'true',
|
|
@@ -153,33 +143,26 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
153
143
|
*/
|
|
154
144
|
definePlugin?: Record<string, string | Partial<Record<BuildTarget, string>>>;
|
|
155
145
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* 用于设置代码的目标运行环境,影响代码的编译降级和 polyfill 注入
|
|
146
|
+
* Set the target runtime environment for the code, affecting code compilation downgrading and polyfill injection
|
|
159
147
|
*
|
|
160
148
|
* @example
|
|
161
149
|
* ```ts
|
|
150
|
+
* // Global compatible mode
|
|
151
|
+
* target: 'compatible'
|
|
152
|
+
*
|
|
153
|
+
* // Global modern mode
|
|
154
|
+
* target: 'modern'
|
|
155
|
+
*
|
|
156
|
+
* // Global custom targets
|
|
157
|
+
* target: ['chrome>=89', 'edge>=89', 'firefox>=108', 'safari>=16.4', 'node>=24']
|
|
158
|
+
*
|
|
159
|
+
* // Per-build-target configuration
|
|
162
160
|
* target: {
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* // Node.js 构建目标
|
|
166
|
-
* node: ['node>=16']
|
|
161
|
+
* client: 'modern',
|
|
162
|
+
* server: ['node>=18']
|
|
167
163
|
* }
|
|
168
164
|
* ```
|
|
169
165
|
*/
|
|
170
|
-
target?:
|
|
171
|
-
/**
|
|
172
|
-
* 浏览器构建目标
|
|
173
|
-
*
|
|
174
|
-
* @default ['chrome>=64', 'edge>=79', 'firefox>=67', 'safari>=11.1']
|
|
175
|
-
*/
|
|
176
|
-
web?: string[];
|
|
177
|
-
/**
|
|
178
|
-
* Node.js 构建目标
|
|
179
|
-
*
|
|
180
|
-
* @default ['node>=24']
|
|
181
|
-
*/
|
|
182
|
-
node?: string[];
|
|
183
|
-
};
|
|
166
|
+
target?: TargetSetting;
|
|
184
167
|
}
|
|
185
168
|
export declare function createRspackHtmlApp(esmx: Esmx, options?: RspackHtmlAppOptions): Promise<import("@esmx/core").App>;
|
|
@@ -6,14 +6,10 @@ import {
|
|
|
6
6
|
RSPACK_LOADER,
|
|
7
7
|
createRspackApp
|
|
8
8
|
} from "../rspack/index.mjs";
|
|
9
|
+
import { getTargetSetting } from "./target-setting.mjs";
|
|
9
10
|
export async function createRspackHtmlApp(esmx, options) {
|
|
10
11
|
options = {
|
|
11
12
|
...options,
|
|
12
|
-
target: {
|
|
13
|
-
web: ["chrome>=64", "edge>=79", "firefox>=67", "safari>=11.1"],
|
|
14
|
-
node: ["node>=24"],
|
|
15
|
-
...options?.target
|
|
16
|
-
},
|
|
17
13
|
css: options?.css ? options.css : esmx.isProd ? "css" : "js"
|
|
18
14
|
};
|
|
19
15
|
return createRspackApp(esmx, {
|
|
@@ -37,13 +33,18 @@ export async function createRspackHtmlApp(esmx, options) {
|
|
|
37
33
|
});
|
|
38
34
|
}
|
|
39
35
|
function configureAssetRules(chain, esmx) {
|
|
40
|
-
chain.module.rule("images").test(
|
|
36
|
+
chain.module.rule("images").test(
|
|
37
|
+
/\.(png|jpg|jpeg|gif|svg|bmp|webp|ico|apng|avif|tif|tiff|jfif|pjpeg|pjp|cur)$/i
|
|
38
|
+
).type("asset/resource").set("generator", {
|
|
41
39
|
filename: filename(esmx, "images")
|
|
42
40
|
});
|
|
43
|
-
chain.module.rule("media").test(/\.(mp4|webm|ogg|
|
|
41
|
+
chain.module.rule("media").test(/\.(mp4|webm|ogg|mov)$/i).type("asset/resource").set("generator", {
|
|
44
42
|
filename: filename(esmx, "media")
|
|
45
43
|
});
|
|
46
|
-
chain.module.rule("
|
|
44
|
+
chain.module.rule("audio").test(/\.(mp3|wav|flac|aac|m4a|opus)$/i).type("asset/resource").set("generator", {
|
|
45
|
+
filename: filename(esmx, "audio")
|
|
46
|
+
});
|
|
47
|
+
chain.module.rule("fonts").test(/\.(woff|woff2|eot|ttf|otf|ttc)(\?.*)?$/i).type("asset/resource").set("generator", {
|
|
47
48
|
filename: filename(esmx, "fonts")
|
|
48
49
|
});
|
|
49
50
|
}
|
|
@@ -60,7 +61,7 @@ function configureTypeScriptRule(chain, buildTarget, options) {
|
|
|
60
61
|
options.loaders?.builtinSwcLoader ?? RSPACK_LOADER.builtinSwcLoader
|
|
61
62
|
).options({
|
|
62
63
|
env: {
|
|
63
|
-
targets:
|
|
64
|
+
targets: getTargetSetting(options?.target, buildTarget),
|
|
64
65
|
...options?.swcLoader?.env
|
|
65
66
|
},
|
|
66
67
|
jsc: {
|
|
@@ -86,7 +87,7 @@ function configureOptimization(chain, options) {
|
|
|
86
87
|
chain.optimization.minimizer("lightningcss-minimizer").use(rspack.LightningCssMinimizerRspackPlugin, [
|
|
87
88
|
{
|
|
88
89
|
minimizerOptions: {
|
|
89
|
-
targets: options
|
|
90
|
+
targets: getTargetSetting(options?.target, "client"),
|
|
90
91
|
errorRecovery: false
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -117,18 +118,18 @@ function configureCssRules(chain, esmx, options) {
|
|
|
117
118
|
configureCssExtract(chain, esmx, options);
|
|
118
119
|
}
|
|
119
120
|
function configureCssInJS(chain, esmx, options) {
|
|
120
|
-
chain.module.rule("css").test(/\.css$/).use("style-loader").loader(options.loaders?.styleLoader ?? RSPACK_LOADER.styleLoader).options(options.styleLoader
|
|
121
|
+
chain.module.rule("css").test(/\.css$/).use("style-loader").loader(options.loaders?.styleLoader ?? RSPACK_LOADER.styleLoader).options(options.styleLoader ?? {}).end().use("css-loader").loader(options.loaders?.cssLoader ?? RSPACK_LOADER.cssLoader).options(options.cssLoader ?? {}).end().use("lightning-css-loader").loader(
|
|
121
122
|
options.loaders?.lightningcssLoader ?? RSPACK_LOADER.lightningcssLoader
|
|
122
123
|
).options({
|
|
123
|
-
targets: options
|
|
124
|
+
targets: getTargetSetting(options?.target, "client"),
|
|
124
125
|
minify: esmx.isProd
|
|
125
126
|
}).end().type("javascript/auto");
|
|
126
|
-
const lessRule = chain.module.rule("less").test(/\.less$/).use("style-loader").loader(options.loaders?.styleLoader ?? RSPACK_LOADER.styleLoader).options(options.styleLoader
|
|
127
|
+
const lessRule = chain.module.rule("less").test(/\.less$/).use("style-loader").loader(options.loaders?.styleLoader ?? RSPACK_LOADER.styleLoader).options(options.styleLoader ?? {}).end().use("css-loader").loader(options.loaders?.cssLoader ?? RSPACK_LOADER.cssLoader).options(options.cssLoader ?? {}).end().use("lightning-css-loader").loader(
|
|
127
128
|
options.loaders?.lightningcssLoader ?? RSPACK_LOADER.lightningcssLoader
|
|
128
129
|
).options({
|
|
129
|
-
targets: options
|
|
130
|
+
targets: getTargetSetting(options?.target, "client"),
|
|
130
131
|
minify: esmx.isProd
|
|
131
|
-
}).end().use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader
|
|
132
|
+
}).end().use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader ?? {}).end();
|
|
132
133
|
if (options.styleResourcesLoader) {
|
|
133
134
|
lessRule.use("style-resources-loader").loader(
|
|
134
135
|
options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader
|
|
@@ -138,14 +139,14 @@ function configureCssInJS(chain, esmx, options) {
|
|
|
138
139
|
}
|
|
139
140
|
function configureCssExtract(chain, esmx, options) {
|
|
140
141
|
chain.set("experiments", {
|
|
141
|
-
...chain.get("experiments")
|
|
142
|
+
...chain.get("experiments") ?? {},
|
|
142
143
|
css: true
|
|
143
144
|
});
|
|
144
145
|
const experiments = chain.get("experiments");
|
|
145
146
|
if (!experiments || !experiments.css) {
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
|
-
const lessRule = chain.module.rule("less").test(/\.less$/).use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader
|
|
149
|
+
const lessRule = chain.module.rule("less").test(/\.less$/).use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader ?? {}).end();
|
|
149
150
|
if (options.styleResourcesLoader) {
|
|
150
151
|
lessRule.use("style-resources-loader").loader(
|
|
151
152
|
options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BuildTarget } from '../rspack/build-target';
|
|
2
|
+
export type TargetPreset = 'compatible' | 'modern';
|
|
3
|
+
export type TargetSpec = TargetPreset | string[];
|
|
4
|
+
export type TargetSetting = TargetSpec | Partial<Record<BuildTarget, TargetSpec>>;
|
|
5
|
+
export declare const PRESET_TARGETS: {
|
|
6
|
+
readonly compatible: {
|
|
7
|
+
readonly client: readonly ["chrome>=64", "edge>=79", "firefox>=67", "safari>=11.1"];
|
|
8
|
+
readonly server: readonly ["node>=24"];
|
|
9
|
+
readonly node: readonly ["node>=24"];
|
|
10
|
+
};
|
|
11
|
+
readonly modern: {
|
|
12
|
+
readonly client: readonly ["chrome>=89", "edge>=89", "firefox>=108", "safari>=16.4"];
|
|
13
|
+
readonly server: readonly ["node>=24"];
|
|
14
|
+
readonly node: readonly ["node>=24"];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare function getTargetSetting(setting: TargetSetting | undefined, buildTarget: BuildTarget): string[];
|