@esmx/rspack 3.0.0-rc.10
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/README.md +29 -0
- package/dist/app.d.ts +160 -0
- package/dist/app.mjs +130 -0
- package/dist/build-target.d.ts +8 -0
- package/dist/build-target.mjs +0 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.mjs +142 -0
- package/dist/html-app.d.ts +299 -0
- package/dist/html-app.mjs +214 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +7 -0
- package/dist/loader.d.ts +30 -0
- package/dist/loader.mjs +33 -0
- package/dist/pack.d.ts +2 -0
- package/dist/pack.mjs +69 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/rsbuild.d.ts +12 -0
- package/dist/utils/rsbuild.mjs +97 -0
- package/package.json +108 -0
- package/src/app.ts +319 -0
- package/src/build-target.ts +8 -0
- package/src/config.ts +171 -0
- package/src/html-app.ts +560 -0
- package/src/index.ts +12 -0
- package/src/loader.ts +34 -0
- package/src/pack.ts +79 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/rsbuild.ts +105 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { type Compiler, type RspackOptions, rspack } from '@rspack/core';
|
|
3
|
+
|
|
4
|
+
export function createRsBuild(options: RspackOptions[]) {
|
|
5
|
+
const multiCompiler = rspack(options);
|
|
6
|
+
return {
|
|
7
|
+
get compilers() {
|
|
8
|
+
return multiCompiler.compilers;
|
|
9
|
+
},
|
|
10
|
+
build() {
|
|
11
|
+
return new Promise<boolean>((resolve) => {
|
|
12
|
+
multiCompiler.run((err, stats) => {
|
|
13
|
+
if (err) {
|
|
14
|
+
return resolve(false);
|
|
15
|
+
}
|
|
16
|
+
if (stats?.hasErrors()) {
|
|
17
|
+
stats
|
|
18
|
+
.toJson({ errors: true })
|
|
19
|
+
?.errors?.forEach((err) => {
|
|
20
|
+
console.log(styleText('red', err.message));
|
|
21
|
+
});
|
|
22
|
+
return resolve(false);
|
|
23
|
+
}
|
|
24
|
+
multiCompiler.close((err) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
console.log(styleText('red', err.message));
|
|
27
|
+
return resolve(false);
|
|
28
|
+
}
|
|
29
|
+
process.nextTick(() => {
|
|
30
|
+
resolve(true);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
watch() {
|
|
37
|
+
const watching = multiCompiler.watch({}, (err, stats) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (stats?.hasErrors()) {
|
|
43
|
+
stats.toJson({ errors: true })?.errors?.forEach((err) => {
|
|
44
|
+
console.log(styleText('red', err.message));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 监听进程信号,确保优雅退出
|
|
50
|
+
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] satisfies string[];
|
|
51
|
+
signals.forEach((signal) => {
|
|
52
|
+
process.on(signal, () => {
|
|
53
|
+
watching.close(() => {
|
|
54
|
+
process.exit();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// 监听未捕获的异常和 Promise 拒绝
|
|
60
|
+
process.on('uncaughtException', handleExit);
|
|
61
|
+
process.on('unhandledRejection', handleExit);
|
|
62
|
+
|
|
63
|
+
function handleExit(err: Error) {
|
|
64
|
+
console.error(err);
|
|
65
|
+
watching.close(() => {
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class RsBuild {
|
|
74
|
+
private compiler: Compiler;
|
|
75
|
+
public constructor(options: RspackOptions) {
|
|
76
|
+
this.compiler = rspack(options);
|
|
77
|
+
}
|
|
78
|
+
public async build() {
|
|
79
|
+
return new Promise<boolean>((resolve) => {
|
|
80
|
+
this.compiler.run((err, stats) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
return resolve(false);
|
|
83
|
+
}
|
|
84
|
+
if (stats?.hasErrors()) {
|
|
85
|
+
stats.toJson({ errors: true })?.errors?.forEach((err) => {
|
|
86
|
+
console.error(err);
|
|
87
|
+
});
|
|
88
|
+
return resolve(false);
|
|
89
|
+
}
|
|
90
|
+
this.compiler.close((err) => {
|
|
91
|
+
if (err) {
|
|
92
|
+
console.error(err);
|
|
93
|
+
return resolve(false);
|
|
94
|
+
}
|
|
95
|
+
process.nextTick(() => {
|
|
96
|
+
resolve(true);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
public watch() {
|
|
103
|
+
const watching = this.compiler.watch({}, () => {});
|
|
104
|
+
}
|
|
105
|
+
}
|