@winner-fed/bundler-rsbuild 0.19.3 → 0.19.4
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/build.js +34 -19
- package/dist/dev.d.ts +2 -1
- package/dist/server/compilerAdapter.d.ts +16 -0
- package/dist/server/compilerAdapter.js +39 -0
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.js +3 -1
- package/package.json +5 -4
package/dist/build.js
CHANGED
|
@@ -42,7 +42,7 @@ var configModule = (0, import_utils.importLazy)(
|
|
|
42
42
|
);
|
|
43
43
|
var statsJson = {};
|
|
44
44
|
async function build(opts) {
|
|
45
|
-
var _a, _b
|
|
45
|
+
var _a, _b;
|
|
46
46
|
(0, import_assert.default)(opts, "opts should be supplied");
|
|
47
47
|
(0, import_checkConfig.checkConfig)(opts);
|
|
48
48
|
const { cwd, onBuildComplete, config } = opts;
|
|
@@ -57,14 +57,41 @@ async function build(opts) {
|
|
|
57
57
|
cwd,
|
|
58
58
|
rsbuildConfig
|
|
59
59
|
});
|
|
60
|
+
const isWatch = opts.watch ?? false;
|
|
61
|
+
let isFirstCompile = true;
|
|
62
|
+
const makeStats = () => {
|
|
63
|
+
var _a2;
|
|
64
|
+
return {
|
|
65
|
+
compilation: {
|
|
66
|
+
...statsJson,
|
|
67
|
+
// convert assets to [key: value] for compilation data
|
|
68
|
+
assets: (_a2 = statsJson == null ? void 0 : statsJson.assets) == null ? void 0 : _a2.reduce(
|
|
69
|
+
(acc, asset) => ({
|
|
70
|
+
...acc,
|
|
71
|
+
[asset.name]: { size: asset.size }
|
|
72
|
+
}),
|
|
73
|
+
{}
|
|
74
|
+
)
|
|
75
|
+
},
|
|
76
|
+
hasErrors: () => false
|
|
77
|
+
};
|
|
78
|
+
};
|
|
60
79
|
try {
|
|
61
80
|
rsbuild.onAfterBuild((params) => {
|
|
62
|
-
var _a2, _b2,
|
|
63
|
-
const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (
|
|
81
|
+
var _a2, _b2, _c;
|
|
82
|
+
const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c = (_b2 = params.stats) == null ? void 0 : _b2.stats) == null ? void 0 : _c[0] : params.stats;
|
|
64
83
|
statsJson = s == null ? void 0 : s.toJson();
|
|
84
|
+
if (isWatch && !isFirstCompile && onBuildComplete) {
|
|
85
|
+
onBuildComplete({
|
|
86
|
+
err: null,
|
|
87
|
+
stats: makeStats(),
|
|
88
|
+
isFirstCompile: false
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
isFirstCompile = false;
|
|
65
92
|
});
|
|
66
93
|
await rsbuild.build({
|
|
67
|
-
watch:
|
|
94
|
+
watch: isWatch
|
|
68
95
|
});
|
|
69
96
|
} catch (e) {
|
|
70
97
|
console.error(e == null ? void 0 : e.message);
|
|
@@ -79,24 +106,12 @@ async function build(opts) {
|
|
|
79
106
|
writeToDisk: true
|
|
80
107
|
});
|
|
81
108
|
}
|
|
82
|
-
const stats =
|
|
83
|
-
compilation: {
|
|
84
|
-
...statsJson,
|
|
85
|
-
// convert assets to [key: value] for compilation data
|
|
86
|
-
assets: (_c = statsJson == null ? void 0 : statsJson.assets) == null ? void 0 : _c.reduce(
|
|
87
|
-
(acc, asset) => ({
|
|
88
|
-
...acc,
|
|
89
|
-
[asset.name]: { size: asset.size }
|
|
90
|
-
}),
|
|
91
|
-
{}
|
|
92
|
-
)
|
|
93
|
-
},
|
|
94
|
-
hasErrors: () => false
|
|
95
|
-
};
|
|
109
|
+
const stats = makeStats();
|
|
96
110
|
if (onBuildComplete) {
|
|
97
111
|
await onBuildComplete({
|
|
98
112
|
err: null,
|
|
99
|
-
stats
|
|
113
|
+
stats,
|
|
114
|
+
isFirstCompile: true
|
|
100
115
|
});
|
|
101
116
|
}
|
|
102
117
|
return stats;
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { MaybePromise } from '@rsbuild/core/dist-types/types';
|
|
2
|
+
import type { IWinMiddleware } from '@winner-fed/bundler-utils';
|
|
2
3
|
import { Express, RequestHandler } from '@winner-fed/bundler-utils/compiled/express';
|
|
3
4
|
import { IBabelPlugin, IConfig, MultiStats, Stats } from './types';
|
|
4
5
|
type IOpts = {
|
|
5
6
|
beforeBabelPlugins?: IBabelPlugin[];
|
|
6
7
|
beforeBabelPresets?: IBabelPlugin[];
|
|
7
|
-
afterMiddlewares?:
|
|
8
|
+
afterMiddlewares?: IWinMiddleware[];
|
|
8
9
|
beforeMiddlewares?: RequestHandler[];
|
|
9
10
|
onDevCompileDone?: (opts: {
|
|
10
11
|
isFirstCompile: boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 rsbuild 的 onAfterDevCompile 适配成 webpack 风格的 compiler.hooks.done,
|
|
3
|
+
* 供 dev server 中间件工厂(如 createRouteMiddleware)消费真实 stats。
|
|
4
|
+
*/
|
|
5
|
+
export interface ICompilerLike {
|
|
6
|
+
hooks: {
|
|
7
|
+
done: {
|
|
8
|
+
tap: (name: string, cb: (stats: any) => void) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function createCompilerLike(rsbuild: {
|
|
13
|
+
onAfterDevCompile: (fn: (params: {
|
|
14
|
+
stats: any;
|
|
15
|
+
}) => void) => void;
|
|
16
|
+
}): ICompilerLike;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/server/compilerAdapter.ts
|
|
20
|
+
var compilerAdapter_exports = {};
|
|
21
|
+
__export(compilerAdapter_exports, {
|
|
22
|
+
createCompilerLike: () => createCompilerLike
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(compilerAdapter_exports);
|
|
25
|
+
function createCompilerLike(rsbuild) {
|
|
26
|
+
return {
|
|
27
|
+
hooks: {
|
|
28
|
+
done: {
|
|
29
|
+
tap: (_name, cb) => {
|
|
30
|
+
rsbuild.onAfterDevCompile(({ stats }) => cb(stats));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
createCompilerLike
|
|
39
|
+
});
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
import type { IWinMiddleware } from '@winner-fed/bundler-utils';
|
|
2
3
|
import { IConfig } from '../types';
|
|
3
4
|
interface IOpts {
|
|
4
5
|
cwd: string;
|
|
@@ -8,7 +9,7 @@ interface IOpts {
|
|
|
8
9
|
userConfig: IConfig;
|
|
9
10
|
rsbuildConfig: RsbuildConfig;
|
|
10
11
|
beforeMiddlewares?: any[];
|
|
11
|
-
afterMiddlewares?:
|
|
12
|
+
afterMiddlewares?: IWinMiddleware[];
|
|
12
13
|
onDevCompileDone?: Function;
|
|
13
14
|
onBeforeMiddleware?: Function;
|
|
14
15
|
}
|
package/dist/server/server.js
CHANGED
|
@@ -37,6 +37,7 @@ var import_bundler_utils = require("@winner-fed/bundler-utils");
|
|
|
37
37
|
var import_express = __toESM(require("@winner-fed/bundler-utils/compiled/express"));
|
|
38
38
|
var import_utils = require("@winner-fed/utils");
|
|
39
39
|
var import_types = require("../types");
|
|
40
|
+
var import_compilerAdapter = require("./compilerAdapter");
|
|
40
41
|
async function createServer(opts) {
|
|
41
42
|
const { userConfig, rsbuildConfig } = opts;
|
|
42
43
|
const rsbuild = await (0, import_core.createRsbuild)({
|
|
@@ -53,8 +54,9 @@ async function createServer(opts) {
|
|
|
53
54
|
if (userConfig.proxy) {
|
|
54
55
|
(0, import_bundler_utils.createProxy)(userConfig.proxy, app);
|
|
55
56
|
}
|
|
57
|
+
const compilerLike = (0, import_compilerAdapter.createCompilerLike)(rsbuild);
|
|
56
58
|
(opts.afterMiddlewares || []).forEach((m) => {
|
|
57
|
-
app.use(
|
|
59
|
+
app.use((0, import_bundler_utils.resolveMiddleware)(m, { compiler: compilerLike }));
|
|
58
60
|
});
|
|
59
61
|
const httpServer = app.listen(rsbuildServer.port, async () => {
|
|
60
62
|
await rsbuildServer.afterListen();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@winner-fed/bundler-rsbuild",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"description": "@winner-fed/bundler-rsbuild",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"@rsbuild/plugin-sass": "1.5.1",
|
|
20
20
|
"@rsbuild/plugin-stylus": "1.3.1",
|
|
21
21
|
"@rsbuild/plugin-type-check": "1.3.4",
|
|
22
|
-
"@winner-fed/bundler-utils": "0.19.
|
|
23
|
-
"@winner-fed/utils": "0.19.
|
|
22
|
+
"@winner-fed/bundler-utils": "0.19.4",
|
|
23
|
+
"@winner-fed/utils": "0.19.4"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "win-scripts father build",
|
|
30
30
|
"build:deps": "win-scripts bundleDeps",
|
|
31
|
-
"dev": "win-scripts father dev"
|
|
31
|
+
"dev": "win-scripts father dev",
|
|
32
|
+
"test": "win-scripts jest-turbo"
|
|
32
33
|
}
|
|
33
34
|
}
|