@esmx/rspack 3.0.0-rc.44 → 3.0.0-rc.46
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/index.d.ts +2 -4
- package/dist/index.mjs +4 -4
- package/dist/{app.d.ts → rspack/app.d.ts} +41 -0
- package/dist/{app.mjs → rspack/app.mjs} +2 -4
- package/dist/rspack/build-target.d.ts +8 -0
- package/dist/rspack/chain-config.d.ts +7 -0
- package/dist/rspack/chain-config.mjs +133 -0
- package/dist/rspack/index.d.ts +3 -0
- package/dist/rspack/index.mjs +4 -0
- package/dist/{html-app.d.ts → rspack-html/index.d.ts} +1 -114
- package/dist/rspack-html/index.mjs +158 -0
- package/package.json +7 -6
- package/src/index.ts +6 -5
- package/src/{app.ts → rspack/app.ts} +49 -6
- package/src/rspack/build-target.ts +8 -0
- package/src/rspack/chain-config.ts +193 -0
- package/src/rspack/index.ts +8 -0
- package/src/rspack-html/index.ts +510 -0
- package/dist/build-target.d.ts +0 -8
- package/dist/html-app.mjs +0 -214
- package/src/build-target.ts +0 -8
- package/src/html-app.ts +0 -559
- /package/dist/{build-target.mjs → rspack/build-target.mjs} +0 -0
- /package/dist/{config.d.ts → rspack/config.d.ts} +0 -0
- /package/dist/{config.mjs → rspack/config.mjs} +0 -0
- /package/dist/{hmr-config.d.ts → rspack/hmr-config.d.ts} +0 -0
- /package/dist/{hmr-config.mjs → rspack/hmr-config.mjs} +0 -0
- /package/dist/{hot-fix.d.ts → rspack/hot-fix.d.ts} +0 -0
- /package/dist/{hot-fix.mjs → rspack/hot-fix.mjs} +0 -0
- /package/dist/{loader.d.ts → rspack/loader.d.ts} +0 -0
- /package/dist/{loader.mjs → rspack/loader.mjs} +0 -0
- /package/dist/{pack.d.ts → rspack/pack.d.ts} +0 -0
- /package/dist/{pack.mjs → rspack/pack.mjs} +0 -0
- /package/dist/{utils → rspack/utils}/index.d.ts +0 -0
- /package/dist/{utils → rspack/utils}/index.mjs +0 -0
- /package/dist/{utils → rspack/utils}/rsbuild.d.ts +0 -0
- /package/dist/{utils → rspack/utils}/rsbuild.mjs +0 -0
- /package/src/{config.ts → rspack/config.ts} +0 -0
- /package/src/{hmr-config.ts → rspack/hmr-config.ts} +0 -0
- /package/src/{hot-fix.ts → rspack/hot-fix.ts} +0 -0
- /package/src/{loader.ts → rspack/loader.ts} +0 -0
- /package/src/{pack.ts → rspack/pack.ts} +0 -0
- /package/src/{utils → rspack/utils}/index.ts +0 -0
- /package/src/{utils → rspack/utils}/rsbuild.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { type RspackAppConfigContext, type RspackAppOptions, createRspackApp } from './
|
|
2
|
-
export { createRspackHtmlApp, type RspackHtmlAppOptions } from './html
|
|
3
|
-
export type { BuildTarget } from './build-target';
|
|
4
|
-
export { RSPACK_LOADER } from './loader';
|
|
1
|
+
export { type RspackAppConfigContext, type RspackAppChainContext, type RspackAppOptions, type BuildTarget, createRspackApp, RSPACK_LOADER } from './rspack';
|
|
2
|
+
export { createRspackHtmlApp, type RspackHtmlAppOptions } from './rspack-html';
|
|
5
3
|
import * as rspack from '@rspack/core';
|
|
6
4
|
export { rspack };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
|
-
createRspackApp
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
2
|
+
createRspackApp,
|
|
3
|
+
RSPACK_LOADER
|
|
4
|
+
} from "./rspack/index.mjs";
|
|
5
|
+
export { createRspackHtmlApp } from "./rspack-html/index.mjs";
|
|
6
6
|
import * as rspack from "@rspack/core";
|
|
7
7
|
export { rspack };
|
|
@@ -59,6 +59,38 @@ export interface RspackAppConfigContext {
|
|
|
59
59
|
*/
|
|
60
60
|
options: RspackAppOptions;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Rspack 链式配置上下文接口。
|
|
64
|
+
*
|
|
65
|
+
* 该接口提供了在 chain 钩子函数中可以访问的上下文信息,允许你:
|
|
66
|
+
* - 访问 Esmx 框架实例
|
|
67
|
+
* - 获取当前的构建目标(client/server/node)
|
|
68
|
+
* - 使用 rspack-chain 修改配置
|
|
69
|
+
* - 访问应用选项
|
|
70
|
+
*/
|
|
71
|
+
export interface RspackAppChainContext {
|
|
72
|
+
/**
|
|
73
|
+
* Esmx 框架实例。
|
|
74
|
+
* 可用于访问框架提供的 API 和工具函数。
|
|
75
|
+
*/
|
|
76
|
+
esmx: Esmx;
|
|
77
|
+
/**
|
|
78
|
+
* 当前的构建目标。
|
|
79
|
+
* - 'client': 客户端构建,生成浏览器可执行的代码
|
|
80
|
+
* - 'server': 服务端构建,生成 SSR 渲染代码
|
|
81
|
+
* - 'node': Node.js 构建,生成服务器入口代码
|
|
82
|
+
*/
|
|
83
|
+
buildTarget: BuildTarget;
|
|
84
|
+
/**
|
|
85
|
+
* rspack-chain 配置对象。
|
|
86
|
+
* 你可以在 chain 钩子中使用链式 API 修改配置。
|
|
87
|
+
*/
|
|
88
|
+
chain: import('rspack-chain');
|
|
89
|
+
/**
|
|
90
|
+
* 创建应用时传入的选项对象。
|
|
91
|
+
*/
|
|
92
|
+
options: RspackAppOptions;
|
|
93
|
+
}
|
|
62
94
|
/**
|
|
63
95
|
* Rspack 应用配置选项接口。
|
|
64
96
|
*
|
|
@@ -109,6 +141,15 @@ export interface RspackAppOptions {
|
|
|
109
141
|
* @param context - 配置上下文,包含框架实例、构建目标和配置对象
|
|
110
142
|
*/
|
|
111
143
|
config?: (context: RspackAppConfigContext) => void;
|
|
144
|
+
/**
|
|
145
|
+
* Rspack chain 配置钩子函数。
|
|
146
|
+
*
|
|
147
|
+
* 使用 rspack-chain 提供链式配置方式,可以更灵活地修改 Rspack 配置。
|
|
148
|
+
* 在 config 钩子之后调用,如果有 chain 钩子则优先使用链式配置。
|
|
149
|
+
*
|
|
150
|
+
* @param context - 配置上下文,包含框架实例、构建目标和 chain 配置对象
|
|
151
|
+
*/
|
|
152
|
+
chain?: (context: RspackAppChainContext) => void;
|
|
112
153
|
}
|
|
113
154
|
/**
|
|
114
155
|
* 创建 Rspack 应用实例。
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@esmx/core";
|
|
9
9
|
import { createVmImport } from "@esmx/import";
|
|
10
10
|
import hotMiddleware from "webpack-hot-middleware";
|
|
11
|
-
import { createRspackConfig } from "./config.mjs";
|
|
11
|
+
import { createRspackConfig } from "./chain-config.mjs";
|
|
12
12
|
import { pack } from "./pack.mjs";
|
|
13
13
|
import { createRsBuild } from "./utils/index.mjs";
|
|
14
14
|
const extension = path.extname(fileURLToPath(import.meta.url));
|
|
@@ -54,9 +54,7 @@ async function createMiddleware(esmx, options = {}) {
|
|
|
54
54
|
];
|
|
55
55
|
}
|
|
56
56
|
function generateBuildConfig(esmx, options, buildTarget) {
|
|
57
|
-
|
|
58
|
-
options.config?.({ esmx, options, buildTarget, config });
|
|
59
|
-
return config;
|
|
57
|
+
return createRspackConfig(esmx, buildTarget, options);
|
|
60
58
|
}
|
|
61
59
|
function rewriteRender(esmx) {
|
|
62
60
|
return async (options) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
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
|
|
7
|
+
*/
|
|
8
|
+
export type BuildTarget = 'node' | 'client' | 'server';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Esmx } from '@esmx/core';
|
|
2
|
+
import type { RspackOptions } from '@rspack/core';
|
|
3
|
+
import RspackChain from 'rspack-chain';
|
|
4
|
+
import type { RspackAppOptions } from './app';
|
|
5
|
+
import type { BuildTarget } from './build-target';
|
|
6
|
+
export declare function createChainConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackChain;
|
|
7
|
+
export declare function createRspackConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackOptions;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { moduleLinkPlugin } from "@esmx/rspack-module-link-plugin";
|
|
2
|
+
import { rspack } from "@rspack/core";
|
|
3
|
+
import RspackChain from "rspack-chain";
|
|
4
|
+
import nodeExternals from "webpack-node-externals";
|
|
5
|
+
import { HMR_DIR, HMR_JSONP } from "./hmr-config.mjs";
|
|
6
|
+
export function createChainConfig(esmx, buildTarget, options) {
|
|
7
|
+
const isHot = buildTarget === "client" && !esmx.isProd;
|
|
8
|
+
const isClient = buildTarget === "client";
|
|
9
|
+
const isServer = buildTarget === "server";
|
|
10
|
+
const isNode = buildTarget === "node";
|
|
11
|
+
const config = new RspackChain();
|
|
12
|
+
config.context(esmx.root);
|
|
13
|
+
config.mode(esmx.isProd ? "production" : "development");
|
|
14
|
+
config.target(isClient ? "web" : "node24");
|
|
15
|
+
config.cache(!esmx.isProd);
|
|
16
|
+
config.output.clean(esmx.isProd).filename(
|
|
17
|
+
!isNode && esmx.isProd ? "exports/[name].[contenthash:8].final.mjs" : "exports/[name].mjs"
|
|
18
|
+
).chunkFilename(
|
|
19
|
+
esmx.isProd ? "chunks/[name].[contenthash:8].final.mjs" : "chunks/[name].mjs"
|
|
20
|
+
).publicPath(
|
|
21
|
+
isClient ? "auto" : `${esmx.basePathPlaceholder}${esmx.basePath}`
|
|
22
|
+
).uniqueName(esmx.varName).hotUpdateGlobal(HMR_JSONP).chunkLoadingGlobal(`${HMR_JSONP}_chunk`).hotUpdateChunkFilename(`${HMR_DIR}/[id].[fullhash].hot-update.mjs`).hotUpdateMainFilename(
|
|
23
|
+
`${HMR_DIR}/[runtime].[fullhash].hot-update.json`
|
|
24
|
+
);
|
|
25
|
+
config.output.set(
|
|
26
|
+
"cssFilename",
|
|
27
|
+
esmx.isProd ? "exports/[name].[contenthash:8].final.css" : "exports/[name].css"
|
|
28
|
+
);
|
|
29
|
+
config.output.set(
|
|
30
|
+
"cssChunkFilename",
|
|
31
|
+
esmx.isProd ? "chunks/[name].[contenthash:8].final.css" : "chunks/[name].css"
|
|
32
|
+
);
|
|
33
|
+
const outputPath = (() => {
|
|
34
|
+
switch (buildTarget) {
|
|
35
|
+
case "client":
|
|
36
|
+
return esmx.resolvePath("dist/client");
|
|
37
|
+
case "server":
|
|
38
|
+
return esmx.resolvePath("dist/server");
|
|
39
|
+
case "node":
|
|
40
|
+
return esmx.resolvePath("dist/node");
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
config.output.path(outputPath);
|
|
44
|
+
config.plugin("progress").use(rspack.ProgressPlugin, [
|
|
45
|
+
{
|
|
46
|
+
prefix: buildTarget
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
config.plugin("module-link").use(moduleLinkPlugin, [createModuleLinkConfig(esmx, buildTarget)]);
|
|
50
|
+
if (isHot) {
|
|
51
|
+
config.plugin("hmr").use(rspack.HotModuleReplacementPlugin);
|
|
52
|
+
}
|
|
53
|
+
config.module.parser.set("javascript", {
|
|
54
|
+
dynamicImportMode: "lazy",
|
|
55
|
+
url: isClient ? true : "relative"
|
|
56
|
+
});
|
|
57
|
+
config.module.generator.set("asset", {
|
|
58
|
+
emit: isClient
|
|
59
|
+
});
|
|
60
|
+
config.module.generator.set("asset/resource", {
|
|
61
|
+
emit: isClient
|
|
62
|
+
});
|
|
63
|
+
config.resolve.alias.set(esmx.name, esmx.root);
|
|
64
|
+
config.optimization.minimize(options.minimize ?? esmx.isProd).emitOnErrors(true);
|
|
65
|
+
config.externalsPresets({
|
|
66
|
+
web: isClient,
|
|
67
|
+
node: isServer || isNode
|
|
68
|
+
});
|
|
69
|
+
config.externalsType("module-import");
|
|
70
|
+
if (isNode) {
|
|
71
|
+
config.externals([
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
nodeExternals({
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
importType: "module-import"
|
|
76
|
+
})
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
if (!esmx.isProd) {
|
|
80
|
+
config.optimization.splitChunks(false).runtimeChunk(false);
|
|
81
|
+
config.module.parser.set("javascript", {
|
|
82
|
+
...config.module.parser.get("javascript"),
|
|
83
|
+
dynamicImportMode: "eager"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return config;
|
|
87
|
+
}
|
|
88
|
+
function createModuleLinkConfig(esmx, buildTarget) {
|
|
89
|
+
const isClient = buildTarget === "client";
|
|
90
|
+
const isServer = buildTarget === "server";
|
|
91
|
+
const isNode = buildTarget === "node";
|
|
92
|
+
if (isNode) {
|
|
93
|
+
return {
|
|
94
|
+
name: esmx.name,
|
|
95
|
+
exports: {
|
|
96
|
+
"src/entry.node": {
|
|
97
|
+
rewrite: false,
|
|
98
|
+
file: "./src/entry.node"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const exports = {};
|
|
104
|
+
for (const [name, item] of Object.entries(esmx.moduleConfig.exports)) {
|
|
105
|
+
if (item.inputTarget[buildTarget]) {
|
|
106
|
+
exports[name] = {
|
|
107
|
+
rewrite: item.rewrite,
|
|
108
|
+
file: item.inputTarget[buildTarget]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const preEntries = [];
|
|
113
|
+
if (isClient && !esmx.isProd) {
|
|
114
|
+
preEntries.push(
|
|
115
|
+
`${import.meta.resolve("webpack-hot-middleware/client.js")}?path=/${esmx.name}/hot-middleware`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
name: esmx.name,
|
|
120
|
+
injectChunkName: isServer,
|
|
121
|
+
imports: esmx.moduleConfig.imports,
|
|
122
|
+
deps: Object.keys(esmx.moduleConfig.links),
|
|
123
|
+
exports,
|
|
124
|
+
preEntries
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function createRspackConfig(esmx, buildTarget, options) {
|
|
128
|
+
const chain = createChainConfig(esmx, buildTarget, options);
|
|
129
|
+
options.chain?.({ esmx, options, buildTarget, chain });
|
|
130
|
+
const config = chain.toConfig();
|
|
131
|
+
options.config?.({ esmx, options, buildTarget, config });
|
|
132
|
+
return config;
|
|
133
|
+
}
|
|
@@ -1,45 +1,6 @@
|
|
|
1
1
|
import type { Esmx } from '@esmx/core';
|
|
2
2
|
import { type SwcLoaderOptions } from '@rspack/core';
|
|
3
|
-
import { type RspackAppOptions } from '
|
|
4
|
-
import type { BuildTarget } from './build-target';
|
|
5
|
-
import { RSPACK_LOADER } from './loader';
|
|
6
|
-
/**
|
|
7
|
-
* Rspack HTML 应用配置选项接口
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // entry.node.ts
|
|
12
|
-
* export default {
|
|
13
|
-
* async devApp(esmx) {
|
|
14
|
-
* return import('@esmx/rspack').then((m) =>
|
|
15
|
-
* m.createRspackHtmlApp(esmx, {
|
|
16
|
-
* // 将 CSS 输出到独立的 CSS 文件中
|
|
17
|
-
* css: 'css',
|
|
18
|
-
* // 自定义 loader
|
|
19
|
-
* loaders: {
|
|
20
|
-
* styleLoader: 'vue-style-loader'
|
|
21
|
-
* },
|
|
22
|
-
* // 配置 CSS 相关 loader
|
|
23
|
-
* styleLoader: {
|
|
24
|
-
* injectType: 'singletonStyleTag'
|
|
25
|
-
* },
|
|
26
|
-
* cssLoader: {
|
|
27
|
-
* modules: true
|
|
28
|
-
* },
|
|
29
|
-
* // 配置构建目标
|
|
30
|
-
* target: {
|
|
31
|
-
* web: ['chrome>=87'],
|
|
32
|
-
* node: ['node>=16']
|
|
33
|
-
* },
|
|
34
|
-
* // 定义全局常量
|
|
35
|
-
* definePlugin: {
|
|
36
|
-
* 'process.env.APP_ENV': JSON.stringify('production')
|
|
37
|
-
* }
|
|
38
|
-
* })
|
|
39
|
-
* );
|
|
40
|
-
* }
|
|
41
|
-
* };
|
|
42
|
-
*/
|
|
3
|
+
import { type BuildTarget, RSPACK_LOADER, type RspackAppOptions } from '../rspack';
|
|
43
4
|
export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
44
5
|
/**
|
|
45
6
|
* CSS 输出模式配置
|
|
@@ -221,78 +182,4 @@ export interface RspackHtmlAppOptions extends RspackAppOptions {
|
|
|
221
182
|
node?: string[];
|
|
222
183
|
};
|
|
223
184
|
}
|
|
224
|
-
/**
|
|
225
|
-
* 创建 Rspack HTML 应用实例。
|
|
226
|
-
*
|
|
227
|
-
* 该函数提供了完整的 Web 应用构建配置,支持以下资源类型的处理:
|
|
228
|
-
* - TypeScript/JavaScript
|
|
229
|
-
* - Web Worker
|
|
230
|
-
* - JSON
|
|
231
|
-
* - CSS/Less
|
|
232
|
-
* - 视频/图片
|
|
233
|
-
* - 字体文件
|
|
234
|
-
*
|
|
235
|
-
* @param esmx - Esmx 框架实例
|
|
236
|
-
* @param options - Rspack HTML 应用配置选项
|
|
237
|
-
* @returns 返回应用实例,包含中间件、渲染函数和构建函数
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```ts
|
|
241
|
-
* // 开发环境配置
|
|
242
|
-
* // entry.node.ts
|
|
243
|
-
* export default {
|
|
244
|
-
* async devApp(esmx) {
|
|
245
|
-
* return import('@esmx/rspack').then((m) =>
|
|
246
|
-
* m.createRspackHtmlApp(esmx, {
|
|
247
|
-
* // 配置 CSS 输出模式
|
|
248
|
-
* css: 'css',
|
|
249
|
-
* // 配置 TypeScript 编译选项
|
|
250
|
-
* swcLoader: {
|
|
251
|
-
* jsc: {
|
|
252
|
-
* parser: {
|
|
253
|
-
* syntax: 'typescript',
|
|
254
|
-
* decorators: true
|
|
255
|
-
* }
|
|
256
|
-
* }
|
|
257
|
-
* },
|
|
258
|
-
* // 配置构建目标
|
|
259
|
-
* target: {
|
|
260
|
-
* web: ['chrome>=87'],
|
|
261
|
-
* node: ['node>=16']
|
|
262
|
-
* },
|
|
263
|
-
* // 自定义 Rspack 配置
|
|
264
|
-
* config({ config }) {
|
|
265
|
-
* // 添加自定义 loader
|
|
266
|
-
* config.module.rules.push({
|
|
267
|
-
* test: /\.vue$/,
|
|
268
|
-
* loader: 'vue-loader'
|
|
269
|
-
* });
|
|
270
|
-
* }
|
|
271
|
-
* })
|
|
272
|
-
* );
|
|
273
|
-
* }
|
|
274
|
-
* };
|
|
275
|
-
*
|
|
276
|
-
* // 生产环境配置
|
|
277
|
-
* // entry.node.ts
|
|
278
|
-
* export default {
|
|
279
|
-
* async buildApp(esmx) {
|
|
280
|
-
* return import('@esmx/rspack').then((m) =>
|
|
281
|
-
* m.createRspackHtmlApp(esmx, {
|
|
282
|
-
* // 启用代码压缩
|
|
283
|
-
* minimize: true,
|
|
284
|
-
* // 配置全局常量
|
|
285
|
-
* definePlugin: {
|
|
286
|
-
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
287
|
-
* 'process.env.IS_SERVER': {
|
|
288
|
-
* server: 'true',
|
|
289
|
-
* client: 'false'
|
|
290
|
-
* }
|
|
291
|
-
* }
|
|
292
|
-
* })
|
|
293
|
-
* );
|
|
294
|
-
* }
|
|
295
|
-
* };
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
185
|
export declare function createRspackHtmlApp(esmx: Esmx, options?: RspackHtmlAppOptions): Promise<import("@esmx/core").App>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rspack
|
|
3
|
+
} from "@rspack/core";
|
|
4
|
+
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
|
|
5
|
+
import {
|
|
6
|
+
RSPACK_LOADER,
|
|
7
|
+
createRspackApp
|
|
8
|
+
} from "../rspack/index.mjs";
|
|
9
|
+
export async function createRspackHtmlApp(esmx, options) {
|
|
10
|
+
options = {
|
|
11
|
+
...options,
|
|
12
|
+
target: {
|
|
13
|
+
web: ["chrome>=64", "edge>=79", "firefox>=67", "safari>=11.1"],
|
|
14
|
+
node: ["node>=24"],
|
|
15
|
+
...options?.target
|
|
16
|
+
},
|
|
17
|
+
css: options?.css ? options.css : esmx.isProd ? "css" : "js"
|
|
18
|
+
};
|
|
19
|
+
return createRspackApp(esmx, {
|
|
20
|
+
...options,
|
|
21
|
+
chain(context) {
|
|
22
|
+
const { chain, buildTarget, esmx: esmx2 } = context;
|
|
23
|
+
chain.stats("errors-warnings");
|
|
24
|
+
chain.devtool(false);
|
|
25
|
+
chain.cache(false);
|
|
26
|
+
configureAssetRules(chain, esmx2);
|
|
27
|
+
chain.module.rule("json").test(/\.json$/i).type("json");
|
|
28
|
+
configureWorkerRule(chain, esmx2, options);
|
|
29
|
+
configureTypeScriptRule(chain, buildTarget, options);
|
|
30
|
+
configureOptimization(chain, options);
|
|
31
|
+
chain.plugin("node-polyfill").use(NodePolyfillPlugin);
|
|
32
|
+
configureDefinePlugin(chain, buildTarget, options);
|
|
33
|
+
chain.resolve.extensions.clear().add("...").add(".ts");
|
|
34
|
+
configureCssRules(chain, esmx2, options);
|
|
35
|
+
options?.chain?.(context);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function configureAssetRules(chain, esmx) {
|
|
40
|
+
chain.module.rule("images").test(/\.(jpe?g|png|gif|bmp|webp|svg)$/i).type("asset/resource").set("generator", {
|
|
41
|
+
filename: filename(esmx, "images")
|
|
42
|
+
});
|
|
43
|
+
chain.module.rule("media").test(/\.(mp4|webm|ogg|mp3|wav|flac|aac)$/i).type("asset/resource").set("generator", {
|
|
44
|
+
filename: filename(esmx, "media")
|
|
45
|
+
});
|
|
46
|
+
chain.module.rule("fonts").test(/\.(woff|woff2|eot|ttf|otf)(\?.*)?$/i).type("asset/resource").set("generator", {
|
|
47
|
+
filename: filename(esmx, "fonts")
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function configureWorkerRule(chain, esmx, options) {
|
|
51
|
+
chain.module.rule("worker").test(/\.worker\.(c|m)?(t|j)s$/i).use("worker-loader").loader(
|
|
52
|
+
options.loaders?.workerRspackLoader ?? RSPACK_LOADER.workerRspackLoader
|
|
53
|
+
).options({
|
|
54
|
+
esModule: false,
|
|
55
|
+
filename: `${esmx.name}/workers/[name].[contenthash]${esmx.isProd ? ".final" : ""}.js`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function configureTypeScriptRule(chain, buildTarget, options) {
|
|
59
|
+
chain.module.rule("typescript").test(/\.(ts|mts)$/i).use("swc-loader").loader(
|
|
60
|
+
options.loaders?.builtinSwcLoader ?? RSPACK_LOADER.builtinSwcLoader
|
|
61
|
+
).options({
|
|
62
|
+
env: {
|
|
63
|
+
targets: buildTarget === "client" ? options?.target?.web : options?.target?.node,
|
|
64
|
+
...options?.swcLoader?.env
|
|
65
|
+
},
|
|
66
|
+
jsc: {
|
|
67
|
+
parser: {
|
|
68
|
+
syntax: "typescript",
|
|
69
|
+
...options?.swcLoader?.jsc?.parser
|
|
70
|
+
},
|
|
71
|
+
...options?.swcLoader?.jsc
|
|
72
|
+
},
|
|
73
|
+
...options?.swcLoader
|
|
74
|
+
}).end().type("javascript/auto");
|
|
75
|
+
}
|
|
76
|
+
function configureOptimization(chain, options) {
|
|
77
|
+
chain.optimization.minimizer("swc-js-minimizer").use(rspack.SwcJsMinimizerRspackPlugin, [
|
|
78
|
+
{
|
|
79
|
+
minimizerOptions: {
|
|
80
|
+
format: {
|
|
81
|
+
comments: false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
chain.optimization.minimizer("lightningcss-minimizer").use(rspack.LightningCssMinimizerRspackPlugin, [
|
|
87
|
+
{
|
|
88
|
+
minimizerOptions: {
|
|
89
|
+
targets: options.target?.web,
|
|
90
|
+
errorRecovery: false
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
function configureDefinePlugin(chain, buildTarget, options) {
|
|
96
|
+
if (options.definePlugin) {
|
|
97
|
+
const defineOptions = {};
|
|
98
|
+
Object.entries(options.definePlugin).forEach(([name, value]) => {
|
|
99
|
+
const targetValue = typeof value === "string" ? value : value[buildTarget];
|
|
100
|
+
if (typeof targetValue === "string" && name !== targetValue) {
|
|
101
|
+
defineOptions[name] = targetValue;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (Object.keys(defineOptions).length) {
|
|
105
|
+
chain.plugin("define").use(rspack.DefinePlugin, [defineOptions]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function configureCssRules(chain, esmx, options) {
|
|
110
|
+
if (options.css === false) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (options.css === "js") {
|
|
114
|
+
configureCssInJS(chain, esmx, options);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
configureCssExtract(chain, esmx, options);
|
|
118
|
+
}
|
|
119
|
+
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
|
+
options.loaders?.lightningcssLoader ?? RSPACK_LOADER.lightningcssLoader
|
|
122
|
+
).options({
|
|
123
|
+
targets: options.target?.web ?? [],
|
|
124
|
+
minify: esmx.isProd
|
|
125
|
+
}).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
|
+
options.loaders?.lightningcssLoader ?? RSPACK_LOADER.lightningcssLoader
|
|
128
|
+
).options({
|
|
129
|
+
targets: options.target?.web ?? [],
|
|
130
|
+
minify: esmx.isProd
|
|
131
|
+
}).end().use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader || {}).end();
|
|
132
|
+
if (options.styleResourcesLoader) {
|
|
133
|
+
lessRule.use("style-resources-loader").loader(
|
|
134
|
+
options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader
|
|
135
|
+
).options(options.styleResourcesLoader);
|
|
136
|
+
}
|
|
137
|
+
lessRule.type("javascript/auto");
|
|
138
|
+
}
|
|
139
|
+
function configureCssExtract(chain, esmx, options) {
|
|
140
|
+
chain.set("experiments", {
|
|
141
|
+
...chain.get("experiments") || {},
|
|
142
|
+
css: true
|
|
143
|
+
});
|
|
144
|
+
const experiments = chain.get("experiments");
|
|
145
|
+
if (!experiments || !experiments.css) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const lessRule = chain.module.rule("less").test(/\.less$/).use("less-loader").loader(options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader).options(options.lessLoader || {}).end();
|
|
149
|
+
if (options.styleResourcesLoader) {
|
|
150
|
+
lessRule.use("style-resources-loader").loader(
|
|
151
|
+
options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader
|
|
152
|
+
).options(options.styleResourcesLoader);
|
|
153
|
+
}
|
|
154
|
+
lessRule.type("css");
|
|
155
|
+
}
|
|
156
|
+
function filename(esmx, name, ext = "[ext]") {
|
|
157
|
+
return esmx.isProd ? `${name}/[name].[contenthash:8].final${ext}` : `${name}/[path][name]${ext}`;
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -63,14 +63,15 @@
|
|
|
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.46",
|
|
67
|
+
"@esmx/rspack-module-link-plugin": "3.0.0-rc.46",
|
|
68
68
|
"@npmcli/arborist": "^9.0.1",
|
|
69
69
|
"@rspack/core": "1.4.8",
|
|
70
70
|
"css-loader": "^7.1.2",
|
|
71
71
|
"less-loader": "^12.2.0",
|
|
72
72
|
"node-polyfill-webpack-plugin": "^4.1.0",
|
|
73
73
|
"pacote": "^21.0.0",
|
|
74
|
+
"rspack-chain": "^1.1.1",
|
|
74
75
|
"style-loader": "^4.0.0",
|
|
75
76
|
"style-resources-loader": "^1.5.0",
|
|
76
77
|
"webpack-hot-middleware": "^2.26.1",
|
|
@@ -79,8 +80,8 @@
|
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
82
|
"@biomejs/biome": "1.9.4",
|
|
82
|
-
"@esmx/core": "3.0.0-rc.
|
|
83
|
-
"@esmx/lint": "3.0.0-rc.
|
|
83
|
+
"@esmx/core": "3.0.0-rc.46",
|
|
84
|
+
"@esmx/lint": "3.0.0-rc.46",
|
|
84
85
|
"@types/node": "^24.0.0",
|
|
85
86
|
"@types/npmcli__arborist": "^6.3.1",
|
|
86
87
|
"@types/pacote": "^11.1.8",
|
|
@@ -92,7 +93,7 @@
|
|
|
92
93
|
"unbuild": "3.5.0",
|
|
93
94
|
"vitest": "3.2.4"
|
|
94
95
|
},
|
|
95
|
-
"version": "3.0.0-rc.
|
|
96
|
+
"version": "3.0.0-rc.46",
|
|
96
97
|
"type": "module",
|
|
97
98
|
"private": false,
|
|
98
99
|
"exports": {
|
|
@@ -111,5 +112,5 @@
|
|
|
111
112
|
"template",
|
|
112
113
|
"public"
|
|
113
114
|
],
|
|
114
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "dcac010017466e95e1c7db78094d4925c27d54b9"
|
|
115
116
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export {
|
|
2
2
|
type RspackAppConfigContext,
|
|
3
|
+
type RspackAppChainContext,
|
|
3
4
|
type RspackAppOptions,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {
|
|
5
|
+
type BuildTarget,
|
|
6
|
+
createRspackApp,
|
|
7
|
+
RSPACK_LOADER
|
|
8
|
+
} from './rspack';
|
|
9
|
+
export { createRspackHtmlApp, type RspackHtmlAppOptions } from './rspack-html';
|
|
9
10
|
|
|
10
11
|
import * as rspack from '@rspack/core';
|
|
11
12
|
|