@esmx/rspack 3.0.0-rc.11 → 3.0.0-rc.110
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/LICENSE +1 -1
- package/README.md +48 -20
- package/README.zh-CN.md +57 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +4 -4
- package/dist/module-link/config.d.ts +5 -0
- package/dist/module-link/config.mjs +100 -0
- package/dist/module-link/config1.d.ts +3 -0
- package/dist/module-link/config1.mjs +16 -0
- package/dist/module-link/config2.d.ts +3 -0
- package/dist/module-link/config2.mjs +17 -0
- package/dist/module-link/index.d.ts +4 -0
- package/dist/module-link/index.mjs +8 -0
- package/dist/module-link/manifest-plugin.d.ts +14 -0
- package/dist/module-link/manifest-plugin.mjs +141 -0
- package/dist/module-link/parse.d.ts +2 -0
- package/dist/module-link/parse.mjs +24 -0
- package/dist/module-link/types.d.ts +25 -0
- package/dist/rspack/app.d.ts +183 -0
- package/dist/{app.mjs → rspack/app.mjs} +18 -46
- package/dist/rspack/build-target.d.ts +7 -0
- package/dist/rspack/build-target.mjs +0 -0
- package/dist/{config.d.ts → rspack/chain-config.d.ts} +3 -4
- package/dist/rspack/chain-config.mjs +113 -0
- package/dist/rspack/index.d.ts +3 -0
- package/dist/rspack/index.mjs +4 -0
- package/dist/rspack/loader.d.ts +9 -0
- package/dist/{loader.mjs → rspack/loader.mjs} +2 -22
- package/dist/rspack/pack.d.ts +9 -0
- package/dist/{pack.mjs → rspack/pack.mjs} +33 -25
- package/dist/rspack/pack.test.d.ts +1 -0
- package/dist/rspack/pack.test.mjs +180 -0
- package/dist/rspack/utils/rsbuild.d.ts +6 -0
- package/dist/{utils → rspack/utils}/rsbuild.mjs +7 -37
- package/dist/rspack-html/index.d.ts +168 -0
- package/dist/rspack-html/index.mjs +160 -0
- 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 +23 -21
- package/src/index.ts +7 -6
- package/src/module-link/config.ts +157 -0
- package/src/module-link/config1.ts +24 -0
- package/src/module-link/config2.ts +28 -0
- package/src/module-link/index.ts +19 -0
- package/src/module-link/manifest-plugin.ts +179 -0
- package/src/module-link/parse.ts +31 -0
- package/src/module-link/types.ts +31 -0
- package/src/{app.ts → rspack/app.ts} +104 -107
- package/src/rspack/build-target.ts +7 -0
- package/src/rspack/chain-config.ts +165 -0
- package/src/rspack/index.ts +8 -0
- package/src/{loader.ts → rspack/loader.ts} +3 -22
- package/src/rspack/pack.test.ts +215 -0
- package/src/rspack/pack.ts +101 -0
- package/src/{utils → rspack/utils}/rsbuild.ts +11 -40
- package/src/rspack-html/index.ts +495 -0
- package/src/rspack-html/target-setting.test.ts +123 -0
- package/src/rspack-html/target-setting.ts +52 -0
- package/dist/app.d.ts +0 -160
- package/dist/build-target.d.ts +0 -8
- package/dist/config.mjs +0 -142
- package/dist/html-app.d.ts +0 -299
- package/dist/html-app.mjs +0 -214
- package/dist/loader.d.ts +0 -30
- package/dist/pack.d.ts +0 -2
- package/dist/utils/rsbuild.d.ts +0 -12
- package/src/build-target.ts +0 -8
- package/src/config.ts +0 -171
- package/src/html-app.ts +0 -560
- package/src/pack.ts +0 -79
- /package/dist/{build-target.mjs → module-link/types.mjs} +0 -0
- /package/dist/{utils → rspack/utils}/index.d.ts +0 -0
- /package/dist/{utils → rspack/utils}/index.mjs +0 -0
- /package/src/{utils → rspack/utils}/index.ts +0 -0
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { styleText } from 'node:util';
|
|
4
2
|
import {
|
|
5
3
|
type App,
|
|
4
|
+
createApp,
|
|
6
5
|
type Esmx,
|
|
7
6
|
type Middleware,
|
|
8
|
-
|
|
7
|
+
mergeMiddlewares,
|
|
9
8
|
RenderContext,
|
|
10
9
|
type RenderContextOptions,
|
|
11
|
-
type ServerRenderHandle
|
|
12
|
-
createApp,
|
|
13
|
-
mergeMiddlewares
|
|
10
|
+
type ServerRenderHandle
|
|
14
11
|
} from '@esmx/core';
|
|
15
12
|
import { createVmImport } from '@esmx/import';
|
|
16
13
|
import type { RspackOptions } from '@rspack/core';
|
|
17
14
|
import hotMiddleware from 'webpack-hot-middleware';
|
|
18
15
|
import type { BuildTarget } from './build-target';
|
|
19
|
-
import { createRspackConfig } from './config';
|
|
16
|
+
import { createRspackConfig } from './chain-config';
|
|
20
17
|
import { pack } from './pack';
|
|
21
18
|
import { createRsBuild } from './utils';
|
|
22
19
|
|
|
23
20
|
/**
|
|
24
|
-
* Rspack
|
|
21
|
+
* Rspack application configuration context interface.
|
|
25
22
|
*
|
|
26
|
-
*
|
|
27
|
-
* -
|
|
28
|
-
* -
|
|
29
|
-
* -
|
|
30
|
-
* -
|
|
23
|
+
* This interface provides context information accessible in configuration hook functions, allowing you to:
|
|
24
|
+
* - Access the Esmx framework instance
|
|
25
|
+
* - Get the current build target (client/server/node)
|
|
26
|
+
* - Modify Rspack configuration
|
|
27
|
+
* - Access application options
|
|
31
28
|
*
|
|
32
29
|
* @example
|
|
33
30
|
* ```ts
|
|
@@ -36,18 +33,9 @@ import { createRsBuild } from './utils';
|
|
|
36
33
|
* async devApp(esmx) {
|
|
37
34
|
* return import('@esmx/rspack').then((m) =>
|
|
38
35
|
* m.createRspackApp(esmx, {
|
|
39
|
-
* //
|
|
36
|
+
* // Configuration hook function
|
|
40
37
|
* config(context) {
|
|
41
|
-
* //
|
|
42
|
-
* if (context.buildTarget === 'client') {
|
|
43
|
-
* // 修改客户端构建配置
|
|
44
|
-
* context.config.optimization = {
|
|
45
|
-
* ...context.config.optimization,
|
|
46
|
-
* splitChunks: {
|
|
47
|
-
* chunks: 'all'
|
|
48
|
-
* }
|
|
49
|
-
* };
|
|
50
|
-
* }
|
|
38
|
+
* // Access build target
|
|
51
39
|
* }
|
|
52
40
|
* })
|
|
53
41
|
* );
|
|
@@ -57,37 +45,73 @@ import { createRsBuild } from './utils';
|
|
|
57
45
|
*/
|
|
58
46
|
export interface RspackAppConfigContext {
|
|
59
47
|
/**
|
|
60
|
-
* Esmx
|
|
61
|
-
*
|
|
48
|
+
* Esmx framework instance.
|
|
49
|
+
* Can be used to access framework APIs and utility functions.
|
|
62
50
|
*/
|
|
63
51
|
esmx: Esmx;
|
|
64
52
|
|
|
65
53
|
/**
|
|
66
|
-
*
|
|
67
|
-
* - 'client':
|
|
68
|
-
* - 'server':
|
|
69
|
-
* - 'node': Node.js
|
|
54
|
+
* Current build target.
|
|
55
|
+
* - 'client': Client build, generates browser-executable code
|
|
56
|
+
* - 'server': Server build, generates SSR rendering code
|
|
57
|
+
* - 'node': Node.js build, generates server entry code
|
|
70
58
|
*/
|
|
71
59
|
buildTarget: BuildTarget;
|
|
72
60
|
|
|
73
61
|
/**
|
|
74
|
-
* Rspack
|
|
75
|
-
*
|
|
62
|
+
* Rspack compilation configuration object.
|
|
63
|
+
* You can modify this object in configuration hooks to customize build behavior.
|
|
76
64
|
*/
|
|
77
65
|
config: RspackOptions;
|
|
78
66
|
|
|
79
67
|
/**
|
|
80
|
-
*
|
|
68
|
+
* Options object passed when creating the application.
|
|
69
|
+
*/
|
|
70
|
+
options: RspackAppOptions;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Rspack chain configuration context interface.
|
|
75
|
+
*
|
|
76
|
+
* This interface provides context information accessible in chain hook functions, allowing you to:
|
|
77
|
+
* - Access the Esmx framework instance
|
|
78
|
+
* - Get the current build target (client/server/node)
|
|
79
|
+
* - Modify configuration using rspack-chain
|
|
80
|
+
* - Access application options
|
|
81
|
+
*/
|
|
82
|
+
export interface RspackAppChainContext {
|
|
83
|
+
/**
|
|
84
|
+
* Esmx framework instance.
|
|
85
|
+
* Can be used to access framework APIs and utility functions.
|
|
86
|
+
*/
|
|
87
|
+
esmx: Esmx;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Current build target.
|
|
91
|
+
* - 'client': Client build, generates browser-executable code
|
|
92
|
+
* - 'server': Server build, generates SSR rendering code
|
|
93
|
+
* - 'node': Node.js build, generates server entry code
|
|
94
|
+
*/
|
|
95
|
+
buildTarget: BuildTarget;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* rspack-chain configuration object.
|
|
99
|
+
* You can use the chain API in chain hooks to modify the configuration.
|
|
100
|
+
*/
|
|
101
|
+
chain: import('rspack-chain').default;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options object passed when creating the application.
|
|
81
105
|
*/
|
|
82
106
|
options: RspackAppOptions;
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
/**
|
|
86
|
-
* Rspack
|
|
110
|
+
* Rspack application configuration options interface.
|
|
87
111
|
*
|
|
88
|
-
*
|
|
89
|
-
* -
|
|
90
|
-
* - Rspack
|
|
112
|
+
* This interface provides configuration options available when creating a Rspack application, including:
|
|
113
|
+
* - Code compression options
|
|
114
|
+
* - Rspack configuration hook functions
|
|
91
115
|
*
|
|
92
116
|
* @example
|
|
93
117
|
* ```ts
|
|
@@ -96,15 +120,10 @@ export interface RspackAppConfigContext {
|
|
|
96
120
|
* async devApp(esmx) {
|
|
97
121
|
* return import('@esmx/rspack').then((m) =>
|
|
98
122
|
* m.createRspackApp(esmx, {
|
|
99
|
-
* //
|
|
123
|
+
* // Disable code compression
|
|
100
124
|
* minimize: false,
|
|
101
|
-
* //
|
|
125
|
+
* // Custom Rspack configuration
|
|
102
126
|
* config(context) {
|
|
103
|
-
* if (context.buildTarget === 'client') {
|
|
104
|
-
* context.config.optimization.splitChunks = {
|
|
105
|
-
* chunks: 'all'
|
|
106
|
-
* };
|
|
107
|
-
* }
|
|
108
127
|
* }
|
|
109
128
|
* })
|
|
110
129
|
* );
|
|
@@ -114,37 +133,43 @@ export interface RspackAppConfigContext {
|
|
|
114
133
|
*/
|
|
115
134
|
export interface RspackAppOptions {
|
|
116
135
|
/**
|
|
117
|
-
*
|
|
136
|
+
* Whether to enable code compression.
|
|
118
137
|
*
|
|
119
|
-
* - true:
|
|
120
|
-
* - false:
|
|
121
|
-
* - undefined:
|
|
138
|
+
* - true: Enable code compression
|
|
139
|
+
* - false: Disable code compression
|
|
140
|
+
* - undefined: Automatically determine based on environment (enabled in production, disabled in development)
|
|
122
141
|
*
|
|
123
142
|
* @default undefined
|
|
124
143
|
*/
|
|
125
144
|
minimize?: boolean;
|
|
126
145
|
|
|
127
146
|
/**
|
|
128
|
-
* Rspack
|
|
147
|
+
* Called before the build starts, this function allows you to modify the Rspack compilation configuration.
|
|
148
|
+
* Supports differentiated configuration for different build targets (client/server/node).
|
|
129
149
|
*
|
|
130
|
-
*
|
|
131
|
-
* 支持针对不同的构建目标(client/server/node)进行差异化配置。
|
|
132
|
-
*
|
|
133
|
-
* @param context - 配置上下文,包含框架实例、构建目标和配置对象
|
|
150
|
+
* @param context - Configuration context, containing framework instance, build target, and configuration object
|
|
134
151
|
*/
|
|
135
152
|
config?: (context: RspackAppConfigContext) => void;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Uses rspack-chain to provide chained configuration method, allowing more flexible modification of Rspack configuration.
|
|
156
|
+
* Called after the config hook, if chain hook exists, chained configuration is preferred.
|
|
157
|
+
*
|
|
158
|
+
* @param context - Configuration context, containing framework instance, build target, and chain configuration object
|
|
159
|
+
*/
|
|
160
|
+
chain?: (context: RspackAppChainContext) => void;
|
|
136
161
|
}
|
|
137
162
|
|
|
138
163
|
/**
|
|
139
|
-
*
|
|
164
|
+
* Create Rspack application instance.
|
|
140
165
|
*
|
|
141
|
-
*
|
|
142
|
-
* -
|
|
143
|
-
* -
|
|
166
|
+
* This function creates different application instances based on the runtime environment (development/production):
|
|
167
|
+
* - Development environment: Configures hot update middleware and real-time rendering
|
|
168
|
+
* - Production environment: Configures build tasks
|
|
144
169
|
*
|
|
145
|
-
* @param esmx - Esmx
|
|
146
|
-
* @param options - Rspack
|
|
147
|
-
* @returns
|
|
170
|
+
* @param esmx - Esmx framework instance
|
|
171
|
+
* @param options - Rspack application configuration options
|
|
172
|
+
* @returns Returns application instance
|
|
148
173
|
*
|
|
149
174
|
* @example
|
|
150
175
|
* ```ts
|
|
@@ -154,7 +179,7 @@ export interface RspackAppOptions {
|
|
|
154
179
|
* return import('@esmx/rspack').then((m) =>
|
|
155
180
|
* m.createRspackApp(esmx, {
|
|
156
181
|
* config(context) {
|
|
157
|
-
* //
|
|
182
|
+
* // Configure loader to handle different file types
|
|
158
183
|
* context.config.module = {
|
|
159
184
|
* rules: [
|
|
160
185
|
* {
|
|
@@ -208,22 +233,20 @@ async function createMiddleware(
|
|
|
208
233
|
if (esmx.command !== esmx.COMMAND.dev) {
|
|
209
234
|
return [];
|
|
210
235
|
}
|
|
211
|
-
// const middlewares: Middleware[] = [];
|
|
212
|
-
|
|
213
236
|
const rsBuild = createRsBuild([
|
|
214
237
|
generateBuildConfig(esmx, options, 'client'),
|
|
215
238
|
generateBuildConfig(esmx, options, 'server')
|
|
216
239
|
]);
|
|
217
240
|
rsBuild.watch();
|
|
218
241
|
|
|
219
|
-
// @ts-
|
|
242
|
+
// @ts-expect-error
|
|
220
243
|
const hot = hotMiddleware(rsBuild.compilers[0], {
|
|
221
244
|
path: `${esmx.basePath}hot-middleware`
|
|
222
245
|
});
|
|
223
246
|
return [
|
|
224
247
|
(req, res, next) => {
|
|
225
248
|
if (req.url?.startsWith(`${esmx.basePath}hot-middleware`)) {
|
|
226
|
-
// @ts-
|
|
249
|
+
// @ts-expect-error
|
|
227
250
|
return hot(req, res, next);
|
|
228
251
|
}
|
|
229
252
|
return next();
|
|
@@ -235,11 +258,8 @@ function generateBuildConfig(
|
|
|
235
258
|
esmx: Esmx,
|
|
236
259
|
options: RspackAppOptions,
|
|
237
260
|
buildTarget: BuildTarget
|
|
238
|
-
) {
|
|
239
|
-
|
|
240
|
-
options.config?.({ esmx, options, buildTarget, config });
|
|
241
|
-
|
|
242
|
-
return config;
|
|
261
|
+
): RspackOptions {
|
|
262
|
+
return createRspackConfig(esmx, buildTarget, options);
|
|
243
263
|
}
|
|
244
264
|
|
|
245
265
|
function rewriteRender(esmx: Esmx) {
|
|
@@ -251,14 +271,7 @@ function rewriteRender(esmx: Esmx) {
|
|
|
251
271
|
const module = await vmImport(
|
|
252
272
|
`${esmx.name}/src/entry.server`,
|
|
253
273
|
import.meta.url,
|
|
254
|
-
|
|
255
|
-
console,
|
|
256
|
-
setTimeout,
|
|
257
|
-
clearTimeout,
|
|
258
|
-
process,
|
|
259
|
-
URL,
|
|
260
|
-
global
|
|
261
|
-
}
|
|
274
|
+
global
|
|
262
275
|
);
|
|
263
276
|
const serverRender: ServerRenderHandle = module[rc.entryName];
|
|
264
277
|
if (typeof serverRender === 'function') {
|
|
@@ -269,40 +282,22 @@ function rewriteRender(esmx: Esmx) {
|
|
|
269
282
|
}
|
|
270
283
|
|
|
271
284
|
function rewriteBuild(esmx: Esmx, options: RspackAppOptions = {}) {
|
|
285
|
+
const targets: BuildTarget[] = ['client', 'server'];
|
|
286
|
+
if (!esmx.moduleConfig.lib) {
|
|
287
|
+
targets.push('node');
|
|
288
|
+
}
|
|
272
289
|
return async (): Promise<boolean> => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
);
|
|
279
|
-
if (/\bexport\s+\*\s+from\b/.test(text)) {
|
|
280
|
-
console.log(
|
|
281
|
-
styleText(
|
|
282
|
-
'red',
|
|
283
|
-
`The export * syntax is used in the file '${item.exportPath}', which will cause the packaging to fail.`
|
|
284
|
-
)
|
|
285
|
-
);
|
|
286
|
-
console.log(
|
|
287
|
-
styleText(
|
|
288
|
-
'red',
|
|
289
|
-
`Please use specific export syntax, such as export { a, b } from './a';`
|
|
290
|
-
)
|
|
291
|
-
);
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
290
|
+
const ok = await createRsBuild(
|
|
291
|
+
targets.map((target) => generateBuildConfig(esmx, options, target))
|
|
292
|
+
).build();
|
|
293
|
+
if (!ok) {
|
|
294
|
+
return false;
|
|
295
295
|
}
|
|
296
|
-
await createRsBuild([
|
|
297
|
-
generateBuildConfig(esmx, options, 'client'),
|
|
298
|
-
generateBuildConfig(esmx, options, 'server'),
|
|
299
|
-
generateBuildConfig(esmx, options, 'node')
|
|
300
|
-
]).build();
|
|
301
296
|
esmx.writeSync(
|
|
302
|
-
esmx.resolvePath('dist/index.
|
|
297
|
+
esmx.resolvePath('dist/index.mjs'),
|
|
303
298
|
`
|
|
304
299
|
async function start() {
|
|
305
|
-
const options = await import('./node/src/entry.node.
|
|
300
|
+
const options = await import('./node/src/entry.node.mjs').then(
|
|
306
301
|
(mod) => mod.default
|
|
307
302
|
);
|
|
308
303
|
const { Esmx } = await import('@esmx/core');
|
|
@@ -314,6 +309,8 @@ async function start() {
|
|
|
314
309
|
start();
|
|
315
310
|
`.trim()
|
|
316
311
|
);
|
|
312
|
+
console.log('\n');
|
|
313
|
+
console.log(esmx.generateSizeReport().text);
|
|
317
314
|
return pack(esmx);
|
|
318
315
|
};
|
|
319
316
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Esmx } from '@esmx/core';
|
|
2
|
+
import type { RspackOptions } from '@rspack/core';
|
|
3
|
+
import { rspack } from '@rspack/core';
|
|
4
|
+
import RspackChain from 'rspack-chain';
|
|
5
|
+
import nodeExternals from 'webpack-node-externals';
|
|
6
|
+
import type { ModuleLinkPluginOptions } from '../module-link';
|
|
7
|
+
import { initModuleLink } from '../module-link';
|
|
8
|
+
import type { RspackAppOptions } from './app';
|
|
9
|
+
import type { BuildTarget } from './build-target';
|
|
10
|
+
|
|
11
|
+
export function createChainConfig(
|
|
12
|
+
esmx: Esmx,
|
|
13
|
+
buildTarget: BuildTarget,
|
|
14
|
+
options: RspackAppOptions
|
|
15
|
+
): RspackChain {
|
|
16
|
+
const isHot = buildTarget === 'client' && !esmx.isProd;
|
|
17
|
+
const isClient = buildTarget === 'client';
|
|
18
|
+
const isServer = buildTarget === 'server';
|
|
19
|
+
const isNode = buildTarget === 'node';
|
|
20
|
+
|
|
21
|
+
const chain = new RspackChain();
|
|
22
|
+
|
|
23
|
+
chain.context(esmx.root);
|
|
24
|
+
chain.mode(esmx.isProd ? 'production' : 'development');
|
|
25
|
+
chain.target(isClient ? 'web' : 'node24');
|
|
26
|
+
chain.cache(!esmx.isProd);
|
|
27
|
+
|
|
28
|
+
chain.output
|
|
29
|
+
.clean(esmx.isProd)
|
|
30
|
+
.filename(
|
|
31
|
+
!isNode && esmx.isProd
|
|
32
|
+
? '[name].[contenthash:8].final.mjs'
|
|
33
|
+
: '[name].mjs'
|
|
34
|
+
)
|
|
35
|
+
.chunkFilename(
|
|
36
|
+
esmx.isProd
|
|
37
|
+
? 'chunks/[name].[contenthash:8].final.mjs'
|
|
38
|
+
: 'chunks/[name].mjs'
|
|
39
|
+
)
|
|
40
|
+
.publicPath(
|
|
41
|
+
isClient ? 'auto' : `${esmx.basePathPlaceholder}${esmx.basePath}`
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
chain.output.set(
|
|
45
|
+
'cssFilename',
|
|
46
|
+
esmx.isProd ? '[name].[contenthash:8].final.css' : '[name].css'
|
|
47
|
+
);
|
|
48
|
+
chain.output.set(
|
|
49
|
+
'cssChunkFilename',
|
|
50
|
+
esmx.isProd
|
|
51
|
+
? 'chunks/[name].[contenthash:8].final.css'
|
|
52
|
+
: 'chunks/[name].css'
|
|
53
|
+
);
|
|
54
|
+
chain.output.path(esmx.resolvePath('dist', buildTarget));
|
|
55
|
+
|
|
56
|
+
chain.plugin('progress').use(rspack.ProgressPlugin, [
|
|
57
|
+
{
|
|
58
|
+
prefix: buildTarget
|
|
59
|
+
}
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
if (isHot) {
|
|
63
|
+
chain.plugin('hmr').use(rspack.HotModuleReplacementPlugin);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
chain.module.parser.set('javascript', {
|
|
67
|
+
url: isClient ? true : 'relative',
|
|
68
|
+
importMeta: false,
|
|
69
|
+
strictExportPresence: true
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
chain.module.generator.set('asset', {
|
|
73
|
+
emit: isClient
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
chain.module.generator.set('asset/resource', {
|
|
77
|
+
emit: isClient
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
chain.resolve.alias.set(esmx.name, esmx.root);
|
|
81
|
+
|
|
82
|
+
chain.optimization
|
|
83
|
+
.minimize(options.minimize ?? esmx.isProd)
|
|
84
|
+
.emitOnErrors(true);
|
|
85
|
+
|
|
86
|
+
chain.externalsPresets({
|
|
87
|
+
web: isClient,
|
|
88
|
+
node: isServer || isNode
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
chain.externalsType('module-import');
|
|
92
|
+
|
|
93
|
+
if (isNode) {
|
|
94
|
+
chain.externals([
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
nodeExternals({
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
importType: 'module-import'
|
|
99
|
+
})
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
chain.experiments({
|
|
104
|
+
...(chain.get('experiments') || {}),
|
|
105
|
+
outputModule: true,
|
|
106
|
+
nativeWatcher: true,
|
|
107
|
+
rspackFuture: {
|
|
108
|
+
bundlerInfo: { force: false }
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
chain.set('lazyCompilation', false);
|
|
113
|
+
|
|
114
|
+
initModuleLink(chain, createModuleLinkConfig(esmx, buildTarget));
|
|
115
|
+
|
|
116
|
+
return chain;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createModuleLinkConfig(
|
|
120
|
+
esmx: Esmx,
|
|
121
|
+
buildTarget: BuildTarget
|
|
122
|
+
): ModuleLinkPluginOptions {
|
|
123
|
+
const isClient = buildTarget === 'client';
|
|
124
|
+
const isServer = buildTarget === 'server';
|
|
125
|
+
const isNode = buildTarget === 'node';
|
|
126
|
+
|
|
127
|
+
if (isNode) {
|
|
128
|
+
return {
|
|
129
|
+
name: esmx.name,
|
|
130
|
+
exports: {
|
|
131
|
+
'src/entry.node': {
|
|
132
|
+
pkg: false,
|
|
133
|
+
file: './src/entry.node'
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const preEntries: string[] = [];
|
|
140
|
+
if (isClient && !esmx.isProd) {
|
|
141
|
+
preEntries.push(
|
|
142
|
+
`${import.meta.resolve('webpack-hot-middleware/client.js')}?path=/${esmx.name}/hot-middleware`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
...esmx.moduleConfig.environments[buildTarget],
|
|
148
|
+
name: esmx.name,
|
|
149
|
+
injectChunkName: isServer,
|
|
150
|
+
deps: Object.keys(esmx.moduleConfig.links),
|
|
151
|
+
preEntries
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function createRspackConfig(
|
|
156
|
+
esmx: Esmx,
|
|
157
|
+
buildTarget: BuildTarget,
|
|
158
|
+
options: RspackAppOptions
|
|
159
|
+
): RspackOptions {
|
|
160
|
+
const chain = createChainConfig(esmx, buildTarget, options);
|
|
161
|
+
options.chain?.({ esmx, options, buildTarget, chain });
|
|
162
|
+
const config = chain.toConfig();
|
|
163
|
+
options.config?.({ esmx, options, buildTarget, config });
|
|
164
|
+
return config;
|
|
165
|
+
}
|
|
@@ -1,34 +1,15 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
|
|
1
3
|
function resolve(name: string) {
|
|
2
|
-
return
|
|
4
|
+
return fileURLToPath(import.meta.resolve(name));
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
export const RSPACK_LOADER = {
|
|
6
|
-
/**
|
|
7
|
-
* Rspack 内置的 builtin:swc-loader
|
|
8
|
-
*/
|
|
9
8
|
builtinSwcLoader: 'builtin:swc-loader',
|
|
10
|
-
/**
|
|
11
|
-
* Rspack 内置的 lightningcss-loader
|
|
12
|
-
*/
|
|
13
9
|
lightningcssLoader: 'builtin:lightningcss-loader',
|
|
14
|
-
/**
|
|
15
|
-
* css-loader
|
|
16
|
-
*/
|
|
17
10
|
cssLoader: resolve('css-loader'),
|
|
18
|
-
/**
|
|
19
|
-
* style-loader
|
|
20
|
-
*/
|
|
21
11
|
styleLoader: resolve('style-loader'),
|
|
22
|
-
/**
|
|
23
|
-
* less-loader
|
|
24
|
-
*/
|
|
25
12
|
lessLoader: resolve('less-loader'),
|
|
26
|
-
/**
|
|
27
|
-
* style-resources-loader
|
|
28
|
-
*/
|
|
29
13
|
styleResourcesLoader: resolve('style-resources-loader'),
|
|
30
|
-
/**
|
|
31
|
-
* worker-rspack-loader
|
|
32
|
-
*/
|
|
33
14
|
workerRspackLoader: resolve('worker-rspack-loader')
|
|
34
15
|
} satisfies Record<string, string>;
|