@rsbuild/core 0.4.14 → 0.5.0

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.
Files changed (47) hide show
  1. package/dist/cli/commands.js +1 -1
  2. package/dist/cli/prepare.js +2 -2
  3. package/dist/client/hmr.mjs +449 -230
  4. package/dist/createRsbuild.js +2 -2
  5. package/dist/index.js +1 -1
  6. package/dist/loadEnv.js +7 -7
  7. package/dist/mergeConfig.js +2 -2
  8. package/dist/pluginManager.js +19 -15
  9. package/dist/plugins/basic.js +2 -0
  10. package/dist/plugins/entry.js +2 -2
  11. package/dist/plugins/externals.js +2 -2
  12. package/dist/plugins/fileSize.js +2 -2
  13. package/dist/plugins/html.d.ts +1 -2
  14. package/dist/plugins/html.js +18 -38
  15. package/dist/plugins/moduleFederation.js +2 -2
  16. package/dist/plugins/rsdoctor.js +2 -2
  17. package/dist/plugins/splitChunks.js +4 -4
  18. package/dist/plugins/target.js +10 -12
  19. package/dist/provider/config.js +0 -1
  20. package/dist/provider/createContext.js +1 -1
  21. package/dist/provider/plugins/less.js +2 -2
  22. package/dist/provider/plugins/minimize.js +1 -2
  23. package/dist/provider/plugins/resolve.js +1 -4
  24. package/dist/provider/plugins/sass.js +2 -2
  25. package/dist/provider/plugins/transition.js +9 -1
  26. package/dist/provider/provider.js +6 -9
  27. package/dist/rspack/HtmlBasicPlugin.d.ts +25 -2
  28. package/dist/rspack/HtmlBasicPlugin.js +155 -25
  29. package/dist/rspack/HtmlCrossOriginPlugin.js +4 -8
  30. package/dist/rspack/HtmlNoncePlugin.js +2 -2
  31. package/dist/rspack/InlineChunkHtmlPlugin.js +2 -2
  32. package/dist/rspack/RemoveCssSourcemapPlugin.js +2 -2
  33. package/dist/server/devServer.d.ts +3 -10
  34. package/dist/server/devServer.js +108 -115
  35. package/dist/server/getDevMiddlewares.js +9 -7
  36. package/dist/server/helper.js +2 -2
  37. package/dist/server/index.d.ts +1 -1
  38. package/dist/server/index.js +2 -4
  39. package/dist/server/prodServer.js +2 -2
  40. package/dist/server/socketServer.js +6 -6
  41. package/package.json +5 -5
  42. package/dist/plugins/toml.d.ts +0 -0
  43. package/dist/plugins/toml.js +0 -1
  44. package/dist/plugins/yaml.d.ts +0 -0
  45. package/dist/plugins/yaml.js +0 -1
  46. package/dist/rspack/HtmlTagsPlugin.d.ts +0 -24
  47. package/dist/rspack/HtmlTagsPlugin.js +0 -186
@@ -23,12 +23,158 @@ var __publicField = (obj, key, value) => {
23
23
  };
24
24
  var HtmlBasicPlugin_exports = {};
25
25
  __export(HtmlBasicPlugin_exports, {
26
+ FILE_ATTRS: () => FILE_ATTRS,
27
+ HEAD_TAGS: () => HEAD_TAGS,
26
28
  HtmlBasicPlugin: () => HtmlBasicPlugin,
29
+ VOID_TAGS: () => VOID_TAGS,
27
30
  hasTitle: () => hasTitle
28
31
  });
29
32
  module.exports = __toCommonJS(HtmlBasicPlugin_exports);
33
+ var import_shared = require("@rsbuild/shared");
30
34
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
35
+ const VOID_TAGS = [
36
+ "area",
37
+ "base",
38
+ "br",
39
+ "col",
40
+ "embed",
41
+ "hr",
42
+ "img",
43
+ "input",
44
+ "keygen",
45
+ "link",
46
+ "meta",
47
+ "param",
48
+ "source",
49
+ "track",
50
+ "wbr"
51
+ ];
52
+ const HEAD_TAGS = [
53
+ "title",
54
+ "base",
55
+ "link",
56
+ "style",
57
+ "meta",
58
+ "script",
59
+ "noscript",
60
+ "template"
61
+ ];
62
+ const FILE_ATTRS = {
63
+ link: "href",
64
+ script: "src"
65
+ };
31
66
  const hasTitle = (html) => html ? /<title/i.test(html) && /<\/title/i.test(html) : false;
67
+ const getTagPriority = (tag, tagConfig) => {
68
+ const head = tag.head ?? HEAD_TAGS.includes(tag.tag);
69
+ let priority = head ? -2 : 2;
70
+ const append = tag.append ?? tagConfig.append;
71
+ if (typeof append === "boolean") {
72
+ priority += append ? 1 : -1;
73
+ }
74
+ return priority;
75
+ };
76
+ const formatTags = (tags, override) => tags.map((tag) => ({
77
+ tag: tag.tagName,
78
+ attrs: tag.attributes,
79
+ children: tag.innerHTML,
80
+ publicPath: false,
81
+ ...override
82
+ }));
83
+ const modifyTags = (data, tagConfig, compilationHash, entryName) => {
84
+ if (!tagConfig.tags?.length) {
85
+ return data;
86
+ }
87
+ const fromInjectTags = (tags2) => {
88
+ const ret = [];
89
+ for (const tag of tags2) {
90
+ const attrs = { ...tag.attrs };
91
+ const filenameTag = FILE_ATTRS[tag.tag];
92
+ let filename = attrs[filenameTag];
93
+ if (typeof filename === "string") {
94
+ const optPublicPath = tag.publicPath ?? tagConfig.publicPath;
95
+ if (typeof optPublicPath === "function") {
96
+ filename = optPublicPath(filename, data.publicPath);
97
+ } else if (typeof optPublicPath === "string") {
98
+ filename = (0, import_shared.withPublicPath)(filename, optPublicPath);
99
+ } else if (optPublicPath !== false) {
100
+ filename = (0, import_shared.withPublicPath)(filename, data.publicPath);
101
+ }
102
+ const optHash = tag.hash ?? tagConfig.hash;
103
+ if (typeof optHash === "function") {
104
+ if (compilationHash.length) {
105
+ filename = optHash(filename, compilationHash);
106
+ }
107
+ } else if (typeof optHash === "string") {
108
+ if (optHash.length) {
109
+ filename = `${filename}?${optHash}`;
110
+ }
111
+ } else if (optHash === true) {
112
+ if (compilationHash.length) {
113
+ filename = `${filename}?${compilationHash}`;
114
+ }
115
+ }
116
+ attrs[filenameTag] = filename;
117
+ }
118
+ ret.push({
119
+ meta: {},
120
+ tagName: tag.tag,
121
+ attributes: attrs,
122
+ voidTag: VOID_TAGS.includes(tag.tag),
123
+ innerHTML: tag.children
124
+ });
125
+ }
126
+ return ret;
127
+ };
128
+ let tags = [
129
+ ...formatTags(data.headTags, { head: true }),
130
+ ...formatTags(data.bodyTags, { head: false })
131
+ ];
132
+ const utils = {
133
+ hash: compilationHash,
134
+ entryName,
135
+ outputName: data.outputName,
136
+ publicPath: data.publicPath
137
+ };
138
+ for (const item of tagConfig.tags) {
139
+ if ((0, import_shared.isFunction)(item)) {
140
+ tags = item(tags, utils) || tags;
141
+ } else {
142
+ tags.push(item);
143
+ }
144
+ tags = tags.sort(
145
+ (tag1, tag2) => getTagPriority(tag1, tagConfig) - getTagPriority(tag2, tagConfig)
146
+ );
147
+ }
148
+ const [headTags, bodyTags] = (0, import_shared.partition)(
149
+ tags,
150
+ (tag) => tag.head ?? HEAD_TAGS.includes(tag.tag)
151
+ );
152
+ data.headTags = fromInjectTags(headTags);
153
+ data.bodyTags = fromInjectTags(bodyTags);
154
+ return data;
155
+ };
156
+ const addTitleTag = (headTags, title = "") => {
157
+ headTags.unshift({
158
+ tagName: "title",
159
+ innerHTML: title,
160
+ attributes: {},
161
+ voidTag: false,
162
+ meta: {}
163
+ });
164
+ };
165
+ const addFavicon = (headTags, favicon) => {
166
+ if (favicon) {
167
+ headTags.unshift({
168
+ tagName: "link",
169
+ voidTag: true,
170
+ attributes: {
171
+ rel: "icon",
172
+ href: favicon
173
+ },
174
+ meta: {}
175
+ });
176
+ }
177
+ };
32
178
  class HtmlBasicPlugin {
33
179
  constructor(options) {
34
180
  __publicField(this, "name");
@@ -37,29 +183,6 @@ class HtmlBasicPlugin {
37
183
  this.options = options;
38
184
  }
39
185
  apply(compiler) {
40
- const addTitleTag = (headTags, title = "") => {
41
- headTags.unshift({
42
- tagName: "title",
43
- innerHTML: title,
44
- attributes: {},
45
- voidTag: false,
46
- meta: {}
47
- });
48
- };
49
- const addFavicon = (headTags, entryName) => {
50
- const { favicon } = this.options.info[entryName];
51
- if (favicon) {
52
- headTags.unshift({
53
- tagName: "link",
54
- voidTag: true,
55
- attributes: {
56
- rel: "icon",
57
- href: favicon
58
- },
59
- meta: {}
60
- });
61
- }
62
- };
63
186
  compiler.hooks.compilation.tap(this.name, (compilation) => {
64
187
  (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
65
188
  const entryName = data.plugin.options?.entryName;
@@ -67,11 +190,15 @@ class HtmlBasicPlugin {
67
190
  return data;
68
191
  }
69
192
  const { headTags } = data;
70
- const { templateContent } = this.options.info[entryName];
193
+ const { favicon, tagConfig, templateContent } = this.options[entryName];
71
194
  if (!hasTitle(templateContent)) {
72
195
  addTitleTag(headTags, data.plugin.options?.title);
73
196
  }
74
- addFavicon(headTags, entryName);
197
+ addFavicon(headTags, favicon);
198
+ if (tagConfig) {
199
+ const hash = compilation.hash ?? "";
200
+ modifyTags(data, tagConfig, hash, entryName);
201
+ }
75
202
  return data;
76
203
  });
77
204
  });
@@ -79,6 +206,9 @@ class HtmlBasicPlugin {
79
206
  }
80
207
  // Annotate the CommonJS export names for ESM import in node:
81
208
  0 && (module.exports = {
209
+ FILE_ATTRS,
210
+ HEAD_TAGS,
82
211
  HtmlBasicPlugin,
212
+ VOID_TAGS,
83
213
  hasTitle
84
214
  });
@@ -48,17 +48,13 @@ class HtmlCrossOriginPlugin {
48
48
  }
49
49
  compiler.hooks.compilation.tap(this.name, (compilation) => {
50
50
  (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation).alterAssetTags.tap(this.name, (alterAssetTags) => {
51
+ var _a;
51
52
  const {
52
53
  assetTags: { scripts, styles }
53
54
  } = alterAssetTags;
54
- scripts.forEach((script) => {
55
- var _a;
56
- (_a = script.attributes).crossorigin ?? (_a.crossorigin = this.crossOrigin);
57
- });
58
- styles.forEach((style) => {
59
- var _a;
60
- (_a = style.attributes).crossorigin ?? (_a.crossorigin = this.crossOrigin);
61
- });
55
+ for (const tag of [...scripts, ...styles]) {
56
+ (_a = tag.attributes).crossorigin ?? (_a.crossorigin = this.crossOrigin);
57
+ }
62
58
  return alterAssetTags;
63
59
  });
64
60
  });
@@ -44,9 +44,9 @@ class HtmlNoncePlugin {
44
44
  const {
45
45
  assetTags: { scripts }
46
46
  } = alterAssetTags;
47
- scripts.forEach((script) => {
47
+ for (const script of scripts) {
48
48
  script.attributes.nonce = this.nonce;
49
- });
49
+ }
50
50
  return alterAssetTags;
51
51
  });
52
52
  });
@@ -177,13 +177,13 @@ class InlineChunkHtmlPlugin {
177
177
  },
178
178
  () => {
179
179
  const { devtool } = compiler.options;
180
- this.inlinedAssets.forEach((name) => {
180
+ for (const name of this.inlinedAssets) {
181
181
  if (devtool === "hidden-source-map") {
182
182
  compilation.deleteAsset(name);
183
183
  } else {
184
184
  delete compilation.assets[name];
185
185
  }
186
- });
186
+ }
187
187
  this.inlinedAssets.clear();
188
188
  }
189
189
  );
@@ -39,11 +39,11 @@ class RemoveCssSourcemapPlugin {
39
39
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
40
40
  },
41
41
  () => {
42
- Object.keys(compilation.assets).forEach((name) => {
42
+ for (const name of Object.keys(compilation.assets)) {
43
43
  if (name.endsWith(".css.map")) {
44
44
  compilation.deleteAsset(name);
45
45
  }
46
- });
46
+ }
47
47
  }
48
48
  );
49
49
  });
@@ -1,12 +1,5 @@
1
- import { type DevServerAPIs, type StartServerResult, type StartDevServerOptions, type CreateDevMiddlewareReturns } from '@rsbuild/shared';
1
+ import { type RsbuildDevServer, type CreateDevServerOptions, type StartDevServerOptions, type CreateDevMiddlewareReturns } from '@rsbuild/shared';
2
2
  import type { InternalContext } from '../types';
3
- export declare function getServerAPIs<Options extends {
3
+ export declare function createDevServer<Options extends {
4
4
  context: InternalContext;
5
- }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, { compiler: customCompiler, getPortSilently, }?: StartDevServerOptions & {
6
- defaultPort?: number;
7
- }): Promise<DevServerAPIs>;
8
- export declare function startDevServer<Options extends {
9
- context: InternalContext;
10
- }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, { compiler, getPortSilently, }?: StartDevServerOptions & {
11
- defaultPort?: number;
12
- }): Promise<StartServerResult>;
5
+ }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, { compiler: customCompiler, getPortSilently, runCompile, }?: CreateDevServerOptions): Promise<RsbuildDevServer>;
@@ -28,8 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var devServer_exports = {};
30
30
  __export(devServer_exports, {
31
- getServerAPIs: () => getServerAPIs,
32
- startDevServer: () => startDevServer
31
+ createDevServer: () => createDevServer
33
32
  });
34
33
  module.exports = __toCommonJS(devServer_exports);
35
34
  var import_shared = require("@rsbuild/shared");
@@ -39,19 +38,21 @@ var import_restart = require("./restart");
39
38
  var import_httpServer = require("./httpServer");
40
39
  var import_getDevMiddlewares = require("./getDevMiddlewares");
41
40
  var import_middlewares = require("./middlewares");
42
- async function getServerAPIs(options, createDevMiddleware, {
41
+ async function createDevServer(options, createDevMiddleware, {
43
42
  compiler: customCompiler,
44
- getPortSilently
43
+ getPortSilently,
44
+ runCompile = true
45
45
  } = {}) {
46
46
  if (!(0, import_shared.getNodeEnv)()) {
47
47
  (0, import_shared.setNodeEnv)("development");
48
48
  }
49
+ (0, import_shared.debug)("create dev server");
49
50
  const rsbuildConfig = options.context.config;
50
51
  const { devServerConfig, port, host, https } = await (0, import_helper.getDevOptions)({
51
52
  rsbuildConfig,
52
53
  getPortSilently
53
54
  });
54
- const defaultRoutes = (0, import_helper.formatRoutes)(
55
+ const routes = (0, import_helper.formatRoutes)(
55
56
  options.context.entry,
56
57
  rsbuildConfig.output?.distPath?.html,
57
58
  rsbuildConfig.html?.outputStructure
@@ -61,128 +62,120 @@ async function getServerAPIs(options, createDevMiddleware, {
61
62
  port,
62
63
  https
63
64
  };
64
- return {
65
- config: { devServerConfig, port, host, https, defaultRoutes },
66
- beforeStart: async () => {
67
- await options.context.hooks.onBeforeStartDevServer.call();
68
- },
69
- afterStart: async (params = {}) => {
70
- await options.context.hooks.onAfterStartDevServer.call({
71
- port: params.port || port,
72
- routes: params.routes || defaultRoutes
73
- });
74
- },
75
- startCompile: async () => {
76
- const { devMiddleware, compiler } = await createDevMiddleware(
77
- options,
78
- customCompiler
79
- );
80
- const { CompilerDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./compilerDevMiddleware")));
81
- const publicPaths = (0, import_shared.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
82
- const compilerDevMiddleware = new CompilerDevMiddleware({
83
- dev: devServerConfig,
84
- publicPaths,
85
- devMiddleware
86
- });
87
- compilerDevMiddleware.init();
88
- return {
89
- middleware: compilerDevMiddleware.middleware,
90
- sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
91
- onUpgrade: (...args) => compilerDevMiddleware.upgrade(...args),
92
- close: () => compilerDevMiddleware?.close()
93
- };
94
- },
95
- getMiddlewares: async (params = {}) => {
96
- const { compileMiddlewareAPI, overrides = {} } = params;
97
- return (0, import_getDevMiddlewares.getMiddlewares)({
98
- pwd: options.context.rootPath,
99
- compileMiddlewareAPI,
100
- dev: {
101
- ...devServerConfig,
102
- ...overrides
103
- },
104
- output: {
105
- distPath: rsbuildConfig.output?.distPath?.root || import_shared.ROOT_DIST_DIR
106
- }
107
- });
108
- }
65
+ const startCompile = async () => {
66
+ const { devMiddleware, compiler } = await createDevMiddleware(
67
+ options,
68
+ customCompiler
69
+ );
70
+ const { CompilerDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./compilerDevMiddleware")));
71
+ const publicPaths = (0, import_shared.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
72
+ const compilerDevMiddleware = new CompilerDevMiddleware({
73
+ dev: devServerConfig,
74
+ publicPaths,
75
+ devMiddleware
76
+ });
77
+ compilerDevMiddleware.init();
78
+ return {
79
+ middleware: compilerDevMiddleware.middleware,
80
+ sockWrite: (...args) => compilerDevMiddleware.sockWrite(...args),
81
+ onUpgrade: (...args) => compilerDevMiddleware.upgrade(...args),
82
+ close: () => compilerDevMiddleware?.close()
83
+ };
109
84
  };
110
- }
111
- async function startDevServer(options, createDevMiddleware, {
112
- compiler,
113
- getPortSilently
114
- } = {}) {
115
- (0, import_shared.debug)("create dev server");
116
- const serverAPIs = await getServerAPIs(options, createDevMiddleware, {
117
- compiler,
118
- getPortSilently
119
- });
120
- const {
121
- config: { devServerConfig, port, host, https, defaultRoutes }
122
- } = serverAPIs;
123
- const middlewares = (0, import_connect.default)();
124
- const httpServer = await (0, import_httpServer.createHttpServer)({
125
- https: devServerConfig.https,
126
- middlewares
127
- });
128
- (0, import_shared.debug)("create dev server done");
129
85
  const protocol = https ? "https" : "http";
130
86
  const urls = (0, import_shared.getAddressUrls)({ protocol, port, host });
131
- options.context.hooks.onBeforeCreateCompiler.tap(() => {
87
+ await options.context.hooks.onBeforeStartDevServer.call();
88
+ if (runCompile) {
89
+ options.context.hooks.onBeforeCreateCompiler.tap(() => {
90
+ (0, import_helper.printServerURLs)({
91
+ urls,
92
+ port,
93
+ routes,
94
+ protocol,
95
+ printUrls: devServerConfig.printUrls
96
+ });
97
+ });
98
+ } else {
132
99
  (0, import_helper.printServerURLs)({
133
100
  urls,
134
101
  port,
135
- routes: defaultRoutes,
102
+ routes,
136
103
  protocol,
137
104
  printUrls: devServerConfig.printUrls
138
105
  });
106
+ }
107
+ const compileMiddlewareAPI = runCompile ? await startCompile() : void 0;
108
+ const devMiddlewares = await (0, import_getDevMiddlewares.getMiddlewares)({
109
+ pwd: options.context.rootPath,
110
+ compileMiddlewareAPI,
111
+ dev: devServerConfig,
112
+ output: {
113
+ distPath: rsbuildConfig.output?.distPath?.root || import_shared.ROOT_DIST_DIR
114
+ }
139
115
  });
140
- await serverAPIs.beforeStart();
141
- (0, import_shared.debug)("listen dev server");
142
- return new Promise((resolve) => {
143
- httpServer.listen(
144
- {
145
- host,
146
- port
147
- },
148
- async (err) => {
149
- if (err) {
150
- throw err;
151
- }
152
- const compileMiddlewareAPI = await serverAPIs.startCompile();
153
- const devMiddlewares = await serverAPIs.getMiddlewares({
154
- compileMiddlewareAPI
155
- });
156
- devMiddlewares.middlewares.forEach((item) => {
157
- if (Array.isArray(item)) {
158
- middlewares.use(...item);
159
- } else {
160
- middlewares.use(item);
161
- }
162
- });
163
- middlewares.use(import_middlewares.notFoundMiddleware);
164
- httpServer.on("upgrade", devMiddlewares.onUpgrade);
165
- (0, import_shared.debug)("listen dev server done");
166
- await serverAPIs.afterStart();
167
- const closeServer = async () => {
168
- await options.context.hooks.onCloseDevServer.call();
169
- await devMiddlewares.close();
170
- httpServer.close();
171
- };
172
- (0, import_restart.onBeforeRestartServer)(closeServer);
173
- resolve({
174
- port,
175
- urls: urls.map((item) => item.url),
176
- server: {
177
- close: closeServer
116
+ const middlewares = (0, import_connect.default)();
117
+ for (const item of devMiddlewares.middlewares) {
118
+ if (Array.isArray(item)) {
119
+ middlewares.use(...item);
120
+ } else {
121
+ middlewares.use(item);
122
+ }
123
+ }
124
+ const server = {
125
+ port,
126
+ middlewares,
127
+ listen: async () => {
128
+ const httpServer = await (0, import_httpServer.createHttpServer)({
129
+ https: devServerConfig.https,
130
+ middlewares
131
+ });
132
+ (0, import_shared.debug)("listen dev server");
133
+ return new Promise((resolve) => {
134
+ httpServer.listen(
135
+ {
136
+ host,
137
+ port
138
+ },
139
+ async (err) => {
140
+ if (err) {
141
+ throw err;
142
+ }
143
+ middlewares.use(import_middlewares.notFoundMiddleware);
144
+ httpServer.on("upgrade", devMiddlewares.onUpgrade);
145
+ (0, import_shared.debug)("listen dev server done");
146
+ await server.afterListen();
147
+ const closeServer = async () => {
148
+ await server.close();
149
+ httpServer.close();
150
+ };
151
+ (0, import_restart.onBeforeRestartServer)(closeServer);
152
+ resolve({
153
+ port,
154
+ urls: urls.map((item) => item.url),
155
+ server: {
156
+ close: closeServer
157
+ }
158
+ });
178
159
  }
179
- });
180
- }
181
- );
182
- });
160
+ );
161
+ });
162
+ },
163
+ afterListen: async () => {
164
+ await options.context.hooks.onAfterStartDevServer.call({
165
+ port,
166
+ routes
167
+ });
168
+ },
169
+ onHTTPUpgrade: devMiddlewares.onUpgrade,
170
+ close: async () => {
171
+ await options.context.hooks.onCloseDevServer.call();
172
+ await devMiddlewares.close();
173
+ }
174
+ };
175
+ (0, import_shared.debug)("create dev server done");
176
+ return server;
183
177
  }
184
178
  // Annotate the CommonJS export names for ESM import in node:
185
179
  0 && (module.exports = {
186
- getServerAPIs,
187
- startDevServer
180
+ createDevServer
188
181
  });
@@ -42,7 +42,7 @@ const applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
42
42
  };
43
43
  const before = [];
44
44
  const after = [];
45
- setupMiddlewares.forEach((handler) => {
45
+ for (const handler of setupMiddlewares) {
46
46
  handler(
47
47
  {
48
48
  unshift: (...handlers) => before.unshift(...handlers),
@@ -50,7 +50,7 @@ const applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
50
50
  },
51
51
  serverOptions
52
52
  );
53
- });
53
+ }
54
54
  return { before, after };
55
55
  };
56
56
  const applyDefaultMiddlewares = async ({
@@ -90,9 +90,9 @@ const applyDefaultMiddlewares = async ({
90
90
  dev.proxy
91
91
  );
92
92
  upgradeEvents.push(upgrade);
93
- proxyMiddlewares.forEach((middleware) => {
93
+ for (const middleware of proxyMiddlewares) {
94
94
  middlewares.push(middleware);
95
- });
95
+ }
96
96
  }
97
97
  const { default: launchEditorMiddleware } = await Promise.resolve().then(() => __toESM(require("../../compiled/launch-editor-middleware")));
98
98
  middlewares.push(["/__open-in-editor", launchEditorMiddleware()]);
@@ -131,7 +131,9 @@ const applyDefaultMiddlewares = async ({
131
131
  middlewares.push(import_middlewares.faviconFallbackMiddleware);
132
132
  return {
133
133
  onUpgrade: (...args) => {
134
- upgradeEvents.forEach((cb) => cb(...args));
134
+ for (const cb of upgradeEvents) {
135
+ cb(...args);
136
+ }
135
137
  }
136
138
  };
137
139
  };
@@ -145,7 +147,7 @@ const getMiddlewares = async (options) => {
145
147
  options.dev,
146
148
  compileMiddlewareAPI
147
149
  );
148
- before.forEach((fn) => middlewares.push(fn));
150
+ middlewares.push(...before);
149
151
  const { onUpgrade } = await applyDefaultMiddlewares({
150
152
  middlewares,
151
153
  dev: options.dev,
@@ -153,7 +155,7 @@ const getMiddlewares = async (options) => {
153
155
  output: options.output,
154
156
  pwd: options.pwd
155
157
  });
156
- after.forEach((fn) => middlewares.push(fn));
158
+ middlewares.push(...after);
157
159
  return {
158
160
  close: async () => {
159
161
  compileMiddlewareAPI?.close();
@@ -75,12 +75,12 @@ function getURLMessages(urls, routes) {
75
75
  }
76
76
  message += ` ${`> ${label}`}
77
77
  `;
78
- routes.forEach((r) => {
78
+ for (const r of routes) {
79
79
  message += ` ${import_shared.color.dim("-")} ${import_shared.color.dim(
80
80
  r.entryName.padEnd(maxNameLength + 4)
81
81
  )}${import_shared.color.cyan((0, import_shared.normalizeUrl)(`${url}${r.pathname}`))}
82
82
  `;
83
- });
83
+ }
84
84
  });
85
85
  return message;
86
86
  }
@@ -1,2 +1,2 @@
1
- export { startDevServer, getServerAPIs } from './devServer';
1
+ export { createDevServer } from './devServer';
2
2
  export { startProdServer } from './prodServer';
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var server_exports = {};
20
20
  __export(server_exports, {
21
- getServerAPIs: () => import_devServer.getServerAPIs,
22
- startDevServer: () => import_devServer.startDevServer,
21
+ createDevServer: () => import_devServer.createDevServer,
23
22
  startProdServer: () => import_prodServer.startProdServer
24
23
  });
25
24
  module.exports = __toCommonJS(server_exports);
@@ -27,7 +26,6 @@ var import_devServer = require("./devServer");
27
26
  var import_prodServer = require("./prodServer");
28
27
  // Annotate the CommonJS export names for ESM import in node:
29
28
  0 && (module.exports = {
30
- getServerAPIs,
31
- startDevServer,
29
+ createDevServer,
32
30
  startProdServer
33
31
  });
@@ -81,9 +81,9 @@ class RsbuildProdServer {
81
81
  if (proxy) {
82
82
  const { createProxyMiddleware } = await Promise.resolve().then(() => __toESM(require("./proxy")));
83
83
  const { middlewares, upgrade } = createProxyMiddleware(proxy);
84
- middlewares.forEach((middleware) => {
84
+ for (const middleware of middlewares) {
85
85
  this.middlewares.use(middleware);
86
- });
86
+ }
87
87
  this.app.on("upgrade", upgrade);
88
88
  }
89
89
  this.applyStaticAssetMiddleware();