@winner-fed/bundler-rsbuild2 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 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, _c;
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, _c2;
63
- const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c2 = (_b2 = params.stats) == null ? void 0 : _b2.stats) == null ? void 0 : _c2[0] : params.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({ all: true, assets: true });
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: false
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;
@@ -81,6 +81,8 @@ function getOutConfig(opts) {
81
81
  copy,
82
82
  cssModules: cssLoaderModules,
83
83
  dataUriLimit: inlineLimit,
84
+ // dev 默认内联样式(无 FOUC、规避历史 win.css 404 问题——如今 stats 已为真实值,
85
+ // 关闭后 dev 会产出 win.css 并被正确注入);如需覆盖可透传 rsbuild2.config.output.injectStyles
84
86
  injectStyles: isDev,
85
87
  distPath: {
86
88
  root: outputPath,
package/dist/dev.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import type { IWinMiddleware } from '@winner-fed/bundler-utils';
1
2
  import type { RequestHandler } from '@winner-fed/bundler-utils/compiled/express';
2
3
  import { IBabelPlugin, IConfig, MultiStats, Stats } from './types';
3
4
  type IOpts = {
4
5
  beforeBabelPlugins?: IBabelPlugin[];
5
6
  beforeBabelPresets?: IBabelPlugin[];
6
- afterMiddlewares?: RequestHandler[];
7
+ afterMiddlewares?: IWinMiddleware[];
7
8
  beforeMiddlewares?: RequestHandler[];
8
9
  onDevCompileDone?: (opts: {
9
10
  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
+ });
@@ -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?: any[];
12
+ afterMiddlewares?: IWinMiddleware[];
12
13
  onDevCompileDone?: Function;
13
14
  onBeforeMiddleware?: Function;
14
15
  }
@@ -37,8 +37,14 @@ 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) {
42
+ var _a;
41
43
  const { userConfig, rsbuildConfig } = opts;
44
+ console.log(
45
+ "[debug] merged injectStyles =",
46
+ (_a = rsbuildConfig == null ? void 0 : rsbuildConfig.output) == null ? void 0 : _a.injectStyles
47
+ );
42
48
  const rsbuild = await (0, import_core.createRsbuild)({
43
49
  cwd: opts.cwd,
44
50
  rsbuildConfig
@@ -53,8 +59,9 @@ async function createServer(opts) {
53
59
  if (userConfig.proxy) {
54
60
  (0, import_bundler_utils.createProxy)(userConfig.proxy, app);
55
61
  }
62
+ const compilerLike = (0, import_compilerAdapter.createCompilerLike)(rsbuild);
56
63
  (opts.afterMiddlewares || []).forEach((m) => {
57
- app.use(m.toString().includes("{ compiler }") ? m({}) : m);
64
+ app.use((0, import_bundler_utils.resolveMiddleware)(m, { compiler: compilerLike }));
58
65
  });
59
66
  const httpServer = app.listen(rsbuildServer.port, async () => {
60
67
  await rsbuildServer.afterListen();
@@ -75,9 +82,9 @@ async function createServer(opts) {
75
82
  });
76
83
  }
77
84
  rsbuild.onAfterDevCompile((params) => {
78
- var _a, _b, _c, _d, _e, _f, _g, _h;
85
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
79
86
  if (opts.onDevCompileDone) {
80
- const s = ((_a = params.stats) == null ? void 0 : _a.stats) ? (_c = (_b = params.stats) == null ? void 0 : _b.stats) == null ? void 0 : _c[0] : params.stats;
87
+ const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c = (_b = params.stats) == null ? void 0 : _b.stats) == null ? void 0 : _c[0] : params.stats;
81
88
  (_h = opts.onDevCompileDone) == null ? void 0 : _h.call(opts, {
82
89
  isFirstCompile: params.isFirstCompile,
83
90
  stats: params.stats,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winner-fed/bundler-rsbuild2",
3
- "version": "0.19.3",
3
+ "version": "0.19.4",
4
4
  "description": "@winner-fed/bundler-rsbuild2, based on Rsbuild 2.x (Rspack 2.x). External bundler for winjs, not a dependency of preset-win.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,8 +20,8 @@
20
20
  "@rsbuild/plugin-sass": "2.0.1",
21
21
  "@rsbuild/plugin-stylus": "2.0.1",
22
22
  "@rsbuild/plugin-type-check": "1.6.0",
23
- "@winner-fed/bundler-utils": "0.19.3",
24
- "@winner-fed/utils": "0.19.3"
23
+ "@winner-fed/bundler-utils": "0.19.4",
24
+ "@winner-fed/utils": "0.19.4"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">=20.19"
@@ -32,6 +32,7 @@
32
32
  "scripts": {
33
33
  "build": "win-scripts father build",
34
34
  "build:deps": "win-scripts bundleDeps",
35
- "dev": "win-scripts father dev"
35
+ "dev": "win-scripts father dev",
36
+ "test": "win-scripts jest-turbo"
36
37
  }
37
38
  }