@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.
@@ -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
- * - 访问 Esmx 框架实例
9
- * - 获取当前的构建目标(client/server/node
10
- * - 修改 Rspack 配置
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
- * 可用于访问框架提供的 API 和工具函数。
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': 服务端构建,生成 SSR 渲染代码
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
- * 该接口提供了在 chain 钩子函数中可以访问的上下文信息,允许你:
66
- * - 访问 Esmx 框架实例
67
- * - 获取当前的构建目标(client/server/node
68
- * - 使用 rspack-chain 修改配置
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
- * 可用于访问框架提供的 API 和工具函数。
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': 服务端构建,生成 SSR 渲染代码
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
- * 你可以在 chain 钩子中使用链式 API 修改配置。
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
- * 该接口提供了创建 Rspack 应用时可以使用的配置选项,包括:
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
- * // 自定义 Rspack 配置
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
- * 在构建开始前调用,可以通过该函数修改 Rspack 的编译配置。
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
- * Rspack chain 配置钩子函数。
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 - 配置上下文,包含框架实例、构建目标和 chain 配置对象
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
- * 创建 Rspack 应用实例。
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
- * // 配置 loader 处理不同类型的文件
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
- * @description Defines the build target environment for the application, used to configure specific optimizations and features during the build process
4
- * - node: Build code to run in Node.js environment
5
- * - client: Build code to run in browser environment
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.inputTarget[buildTarget]) {
105
+ if (item.entryPoints[buildTarget]) {
106
106
  exports[name] = {
107
107
  rewrite: item.rewrite,
108
- file: item.inputTarget[buildTarget]
108
+ file: item.entryPoints[buildTarget]
109
109
  };
110
110
  }
111
111
  }
@@ -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
- * 构建 ClientServerNode 的基础配置
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;
@@ -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.inputTarget[buildTarget]) {
113
+ if (item.entryPoints[buildTarget]) {
114
114
  exports[name] = {
115
115
  rewrite: item.rewrite,
116
- file: item.inputTarget[buildTarget]
116
+ file: item.entryPoints[buildTarget]
117
117
  };
118
118
  }
119
119
  }
@@ -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
  };
@@ -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
- * - 生产环境: 'css',将CSS输出到独立文件中,有利于缓存和并行加载
10
- * - 开发环境: 'js',将CSS打包到JS中以支持热更新(HMR),实现样式的即时更新
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': CSS 输出到独立的 CSS 文件中
13
- * - 'js': CSS 打包到 JS 文件中,运行时动态插入样式
14
- * - false: 关闭默认的 CSS 处理配置,需要手动配置 loader 规则
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
- * // 强制输出到独立的 CSS 文件
23
+ * // Force output to separate CSS files
22
24
  * css: 'css'
23
25
  *
24
- * // 强制打包到 JS
26
+ * // Force bundle into JS
25
27
  * css: 'js'
26
28
  *
27
- * // 自定义 CSS 处理
29
+ * // Custom CSS processing
28
30
  * css: false
29
31
  * ```
30
32
  */
31
33
  css?: 'css' | 'js' | false;
32
34
  /**
33
- * 自定义 loader 配置
35
+ * Custom loader configuration
34
36
  *
35
- * 允许替换默认的 loader 实现,可用于切换到特定框架的 loader
37
+ * Allows replacing default loader implementations, useful for switching to framework-specific loaders
36
38
  *
37
39
  * @example
38
40
  * ```ts
39
- * // 使用 Vue style-loader
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-loader 配置项
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
- * css-loader 配置项
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
- * less-loader 配置项
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-resources-loader 配置项
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
- * SWC loader 配置项
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
- * DefinePlugin 配置项
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
- * web: ['chrome>=87', 'firefox>=78', 'safari>=14'],
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(/\.(jpe?g|png|gif|bmp|webp|svg)$/i).type("asset/resource").set("generator", {
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|mp3|wav|flac|aac)$/i).type("asset/resource").set("generator", {
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("fonts").test(/\.(woff|woff2|eot|ttf|otf)(\?.*)?$/i).type("asset/resource").set("generator", {
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: buildTarget === "client" ? options?.target?.web : options?.target?.node,
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.target?.web,
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 || {}).end().use("css-loader").loader(options.loaders?.cssLoader ?? RSPACK_LOADER.cssLoader).options(options.cssLoader || {}).end().use("lightning-css-loader").loader(
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.target?.web ?? [],
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 || {}).end().use("css-loader").loader(options.loaders?.cssLoader ?? RSPACK_LOADER.cssLoader).options(options.cssLoader || {}).end().use("lightning-css-loader").loader(
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.target?.web ?? [],
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 || {}).end();
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 || {}).end();
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[];