@rsbuild/core 0.3.6 → 0.3.8

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 (51) hide show
  1. package/compiled/on-finished/index.d.ts +13 -0
  2. package/compiled/on-finished/index.js +14 -0
  3. package/compiled/on-finished/license +23 -0
  4. package/compiled/on-finished/package.json +1 -0
  5. package/dist/cli/commands.js +7 -6
  6. package/dist/cli/config.d.ts +4 -2
  7. package/dist/cli/config.js +12 -10
  8. package/dist/cli/prepare.js +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/loadEnv.js +9 -4
  11. package/dist/plugins/asset.js +3 -3
  12. package/dist/plugins/basic.js +2 -2
  13. package/dist/plugins/cache.js +9 -9
  14. package/dist/plugins/fileSize.js +7 -7
  15. package/dist/plugins/html.js +4 -4
  16. package/dist/plugins/inlineChunk.js +2 -2
  17. package/dist/plugins/nodeAddons.js +3 -3
  18. package/dist/plugins/server.js +2 -2
  19. package/dist/plugins/splitChunks.js +2 -2
  20. package/dist/plugins/startUrl.js +5 -5
  21. package/dist/plugins/wasm.js +2 -2
  22. package/dist/provider/config.js +5 -11
  23. package/dist/provider/core/createContext.js +4 -4
  24. package/dist/provider/core/inspectConfig.js +3 -3
  25. package/dist/provider/core/rspackConfig.d.ts +2 -1
  26. package/dist/provider/core/rspackConfig.js +8 -5
  27. package/dist/provider/htmlPluginUtil.d.ts +1 -1
  28. package/dist/provider/htmlPluginUtil.js +7 -13
  29. package/dist/provider/index.d.ts +1 -0
  30. package/dist/provider/index.js +3 -0
  31. package/dist/provider/plugins/css.js +9 -5
  32. package/dist/provider/plugins/output.js +3 -3
  33. package/dist/provider/plugins/resolve.js +3 -7
  34. package/dist/provider/plugins/rspackProfile.d.ts +1 -1
  35. package/dist/provider/plugins/rspackProfile.js +7 -7
  36. package/dist/provider/plugins/swc.js +3 -3
  37. package/dist/provider/shared.js +2 -2
  38. package/dist/rspack/HtmlAppIconPlugin.js +5 -5
  39. package/dist/rspack/InlineChunkHtmlPlugin.js +2 -2
  40. package/dist/rspack/preload/helpers/determineAsValue.js +11 -27
  41. package/dist/server/compilerDevMiddleware.d.ts +2 -2
  42. package/dist/server/getDevMiddlewares.js +9 -5
  43. package/dist/server/httpServer.js +2 -2
  44. package/dist/server/middlewares.d.ts +2 -0
  45. package/dist/server/middlewares.js +55 -11
  46. package/dist/server/prodServer.d.ts +1 -1
  47. package/dist/server/prodServer.js +5 -2
  48. package/dist/server/restart.js +2 -2
  49. package/dist/server/socketServer.d.ts +2 -2
  50. package/package.json +3 -3
  51. package/types.d.ts +24 -0
@@ -21,7 +21,7 @@ __export(inspectConfig_exports, {
21
21
  inspectConfig: () => inspectConfig
22
22
  });
23
23
  module.exports = __toCommonJS(inspectConfig_exports);
24
- var import_path = require("path");
24
+ var import_node_path = require("node:path");
25
25
  var import_initConfigs = require("./initConfigs");
26
26
  var import_shared = require("@rsbuild/shared");
27
27
  async function inspectConfig({
@@ -55,8 +55,8 @@ async function inspectConfig({
55
55
  )
56
56
  );
57
57
  let outputPath = inspectOptions.outputPath || context.distPath;
58
- if (!(0, import_path.isAbsolute)(outputPath)) {
59
- outputPath = (0, import_path.join)(context.rootPath, outputPath);
58
+ if (!(0, import_node_path.isAbsolute)(outputPath)) {
59
+ outputPath = (0, import_node_path.join)(context.rootPath, outputPath);
60
60
  }
61
61
  if (inspectOptions.writeToDisk) {
62
62
  await (0, import_shared.outputInspectConfigFiles)({
@@ -1,5 +1,6 @@
1
- import { type RspackConfig, type RsbuildTarget } from '@rsbuild/shared';
1
+ import { type RspackConfig, type RsbuildTarget, type ModifyChainUtils } from '@rsbuild/shared';
2
2
  import type { InternalContext } from '../../types';
3
+ export declare function getChainUtils(target: RsbuildTarget): ModifyChainUtils;
3
4
  export declare function generateRspackConfig({ target, context, }: {
4
5
  target: RsbuildTarget;
5
6
  context: InternalContext;
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var rspackConfig_exports = {};
30
30
  __export(rspackConfig_exports, {
31
- generateRspackConfig: () => generateRspackConfig
31
+ generateRspackConfig: () => generateRspackConfig,
32
+ getChainUtils: () => getChainUtils
32
33
  });
33
34
  module.exports = __toCommonJS(rspackConfig_exports);
34
35
  var import_shared = require("@rsbuild/shared");
@@ -91,15 +92,16 @@ async function getConfigUtils(config, chainUtils) {
91
92
  }
92
93
  };
93
94
  }
94
- async function getChainUtils(target) {
95
+ function getChainUtils(target) {
95
96
  const nodeEnv = (0, import_shared.getNodeEnv)();
96
97
  return {
97
98
  env: nodeEnv,
98
99
  target,
100
+ isDev: nodeEnv === "development",
99
101
  isProd: nodeEnv === "production",
100
102
  isServer: target === "node",
101
- isServiceWorker: target === "service-worker",
102
103
  isWebWorker: target === "web-worker",
104
+ isServiceWorker: target === "service-worker",
103
105
  getCompiledPath: import_shared2.getCompiledPath,
104
106
  CHAIN_ID: import_shared.CHAIN_ID,
105
107
  HtmlPlugin: (0, import_htmlPluginUtil.getHTMLPlugin)()
@@ -109,7 +111,7 @@ async function generateRspackConfig({
109
111
  target,
110
112
  context
111
113
  }) {
112
- const chainUtils = await getChainUtils(target);
114
+ const chainUtils = getChainUtils(target);
113
115
  const {
114
116
  BannerPlugin,
115
117
  DefinePlugin,
@@ -135,5 +137,6 @@ async function generateRspackConfig({
135
137
  }
136
138
  // Annotate the CommonJS export names for ESM import in node:
137
139
  0 && (module.exports = {
138
- generateRspackConfig
140
+ generateRspackConfig,
141
+ getChainUtils
139
142
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This file is used to provide/set a global html-plugin singleton
3
3
  */
4
- import HtmlWebpackPlugin from 'html-webpack-plugin';
4
+ import type HtmlWebpackPlugin from 'html-webpack-plugin';
5
5
  /**
6
6
  * This method is used to override the Rsbuild default html-plugin (html-rspack-plugin).
7
7
  */
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var htmlPluginUtil_exports = {};
30
20
  __export(htmlPluginUtil_exports, {
@@ -32,13 +22,17 @@ __export(htmlPluginUtil_exports, {
32
22
  setHTMLPlugin: () => setHTMLPlugin
33
23
  });
34
24
  module.exports = __toCommonJS(htmlPluginUtil_exports);
35
- var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
36
25
  let htmlPlugin;
37
26
  const setHTMLPlugin = (plugin) => {
38
- htmlPlugin = plugin;
27
+ if (plugin) {
28
+ htmlPlugin = plugin;
29
+ }
39
30
  };
40
31
  const getHTMLPlugin = () => {
41
- return htmlPlugin || import_html_webpack_plugin.default;
32
+ if (!htmlPlugin) {
33
+ htmlPlugin = require("html-webpack-plugin");
34
+ }
35
+ return htmlPlugin;
42
36
  };
43
37
  // Annotate the CommonJS export names for ESM import in node:
44
38
  0 && (module.exports = {
@@ -9,3 +9,4 @@ export { applyBaseCSSRule, applyCSSModuleRule } from './plugins/css';
9
9
  export type { InternalContext } from '../types';
10
10
  export { setHTMLPlugin, getHTMLPlugin } from './htmlPluginUtil';
11
11
  export { formatStats } from './shared';
12
+ export { getChainUtils } from './core/rspackConfig';
@@ -23,6 +23,7 @@ __export(provider_exports, {
23
23
  createContext: () => import_createContext.createContext,
24
24
  createPublicContext: () => import_createContext.createPublicContext,
25
25
  formatStats: () => import_shared2.formatStats,
26
+ getChainUtils: () => import_rspackConfig.getChainUtils,
26
27
  getHTMLPlugin: () => import_htmlPluginUtil.getHTMLPlugin,
27
28
  getPluginAPI: () => import_initPlugins.getPluginAPI,
28
29
  initHooks: () => import_initHooks.initHooks,
@@ -41,6 +42,7 @@ var import_initPlugins = require("./core/initPlugins");
41
42
  var import_css = require("./plugins/css");
42
43
  var import_htmlPluginUtil = require("./htmlPluginUtil");
43
44
  var import_shared2 = require("./shared");
45
+ var import_rspackConfig = require("./core/rspackConfig");
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
46
48
  applyBaseCSSRule,
@@ -48,6 +50,7 @@ var import_shared2 = require("./shared");
48
50
  createContext,
49
51
  createPublicContext,
50
52
  formatStats,
53
+ getChainUtils,
51
54
  getHTMLPlugin,
52
55
  getPluginAPI,
53
56
  initHooks,
@@ -34,7 +34,7 @@ __export(css_exports, {
34
34
  pluginCss: () => pluginCss
35
35
  });
36
36
  module.exports = __toCommonJS(css_exports);
37
- var import_path = __toESM(require("path"));
37
+ var import_node_path = __toESM(require("node:path"));
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  const enableNativeCss = (config) => !config.output.injectStyles;
40
40
  async function applyBaseCSSRule({
@@ -86,7 +86,7 @@ async function applyBaseCSSRule({
86
86
  } else {
87
87
  if (!isServer && !isWebWorker && enableCSSModuleTS) {
88
88
  const { cssModules } = config.output;
89
- rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(import_path.default.resolve(__dirname, "../css-modules-typescript-pre-loader")).options({
89
+ rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(import_node_path.default.resolve(__dirname, "../css-modules-typescript-pre-loader")).options({
90
90
  modules: {
91
91
  exportLocalsConvention: cssModules.exportLocalsConvention,
92
92
  auto: cssModules.auto
@@ -162,9 +162,11 @@ const pluginCss = () => {
162
162
  });
163
163
  api.modifyRspackConfig(
164
164
  async (rspackConfig, { isProd, isServer, isWebWorker }) => {
165
+ var _a;
165
166
  const config = api.getNormalizedConfig();
166
167
  if (!enableNativeCss(config)) {
167
- (0, import_shared.setConfig)(rspackConfig, "experiments.css", false);
168
+ rspackConfig.experiments || (rspackConfig.experiments = {});
169
+ rspackConfig.experiments.css = false;
168
170
  return;
169
171
  }
170
172
  let localIdentName = config.output.cssModules.localIdentName || // Using shorter classname in production to reduce bundle size
@@ -175,11 +177,13 @@ const pluginCss = () => {
175
177
  );
176
178
  localIdentName = localIdentName.replace(":base64", "");
177
179
  }
178
- (0, import_shared.setConfig)(rspackConfig, "builtins.css.modules", {
180
+ rspackConfig.builtins || (rspackConfig.builtins = {});
181
+ (_a = rspackConfig.builtins).css || (_a.css = {});
182
+ rspackConfig.builtins.css.modules = {
179
183
  localsConvention: config.output.cssModules.exportLocalsConvention,
180
184
  localIdentName,
181
185
  exportsOnly: isServer || isWebWorker
182
- });
186
+ };
183
187
  const rules = rspackConfig.module?.rules;
184
188
  applyCSSModuleRule(rules, import_shared.CSS_REGEX, config);
185
189
  }
@@ -31,7 +31,7 @@ __export(output_exports, {
31
31
  pluginOutput: () => pluginOutput
32
32
  });
33
33
  module.exports = __toCommonJS(output_exports);
34
- var import_path = require("path");
34
+ var import_node_path = require("node:path");
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  const pluginOutput = () => ({
37
37
  name: "rsbuild:output",
@@ -51,8 +51,8 @@ const pluginOutput = () => ({
51
51
  const cssPath = (0, import_shared.getDistPath)(config, "css");
52
52
  const cssFilename = (0, import_shared.getFilename)(config, "css", isProd);
53
53
  rspackConfig.output || (rspackConfig.output = {});
54
- rspackConfig.output.cssFilename = import_path.posix.join(cssPath, cssFilename);
55
- rspackConfig.output.cssChunkFilename = import_path.posix.join(
54
+ rspackConfig.output.cssFilename = import_node_path.posix.join(cssPath, cssFilename);
55
+ rspackConfig.output.cssChunkFilename = import_node_path.posix.join(
56
56
  cssPath,
57
57
  `async/${cssFilename}`
58
58
  );
@@ -29,16 +29,12 @@ const pluginResolve = () => ({
29
29
  api.modifyRspackConfig(async (rspackConfig, { isServer }) => {
30
30
  const isTsProject = Boolean(api.context.tsconfigPath);
31
31
  const config = api.getNormalizedConfig();
32
+ rspackConfig.resolve || (rspackConfig.resolve = {});
32
33
  if (isTsProject && config.source.aliasStrategy === "prefer-tsconfig") {
33
- (0, import_shared.setConfig)(
34
- rspackConfig,
35
- "resolve.tsConfigPath",
36
- api.context.tsconfigPath
37
- );
34
+ rspackConfig.resolve.tsConfigPath = api.context.tsconfigPath;
38
35
  }
39
36
  if (isServer) {
40
- const nodeConditionNames = ["require", "node"];
41
- (0, import_shared.setConfig)(rspackConfig, "resolve.conditionNames", nodeConditionNames);
37
+ rspackConfig.resolve.conditionNames = ["require", "node"];
42
38
  }
43
39
  });
44
40
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { RsbuildPlugin } from '../../types';
3
- import inspector from 'inspector';
3
+ import inspector from 'node:inspector';
4
4
  export declare const stopProfiler: (output: string, profileSession?: inspector.Session) => void;
5
5
  export declare const pluginRspackProfile: () => RsbuildPlugin;
@@ -32,8 +32,8 @@ __export(rspackProfile_exports, {
32
32
  stopProfiler: () => stopProfiler
33
33
  });
34
34
  module.exports = __toCommonJS(rspackProfile_exports);
35
- var import_path = __toESM(require("path"));
36
- var import_inspector = __toESM(require("inspector"));
35
+ var import_node_path = __toESM(require("node:path"));
36
+ var import_node_inspector = __toESM(require("node:inspector"));
37
37
  var import_shared = require("@rsbuild/shared");
38
38
  var import_shared2 = require("@rsbuild/shared");
39
39
  const stopProfiler = (output, profileSession) => {
@@ -60,7 +60,7 @@ const pluginRspackProfile = () => ({
60
60
  experimental_cleanupGlobalTrace: cleanupGlobalTrace
61
61
  } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
62
62
  const timestamp = Date.now();
63
- const profileDir = import_path.default.join(
63
+ const profileDir = import_node_path.default.join(
64
64
  api.context.distPath,
65
65
  `rspack-profile-${timestamp}`
66
66
  );
@@ -68,16 +68,16 @@ const pluginRspackProfile = () => ({
68
68
  const enableProfileTrace = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("TRACE");
69
69
  const enableCPUProfile = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("CPU");
70
70
  const enableLogging = RSPACK_PROFILE === "ALL" || RSPACK_PROFILE.includes("LOGGING");
71
- const traceFilePath = import_path.default.join(profileDir, "trace.json");
72
- const cpuProfilePath = import_path.default.join(profileDir, "jscpuprofile.json");
73
- const loggingFilePath = import_path.default.join(profileDir, "logging.json");
71
+ const traceFilePath = import_node_path.default.join(profileDir, "trace.json");
72
+ const cpuProfilePath = import_node_path.default.join(profileDir, "jscpuprofile.json");
73
+ const loggingFilePath = import_node_path.default.join(profileDir, "logging.json");
74
74
  const onStart = () => {
75
75
  import_shared.fse.ensureDirSync(profileDir);
76
76
  if (enableProfileTrace) {
77
77
  registerGlobalTrace("trace", "chrome", traceFilePath);
78
78
  }
79
79
  if (enableCPUProfile) {
80
- profileSession = new import_inspector.default.Session();
80
+ profileSession = new import_node_inspector.default.Session();
81
81
  profileSession.connect();
82
82
  profileSession.post("Profiler.enable");
83
83
  profileSession.post("Profiler.start");
@@ -33,7 +33,7 @@ __export(swc_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(swc_exports);
35
35
  var import_shared = require("@rsbuild/shared");
36
- var import_path = __toESM(require("path"));
36
+ var import_node_path = __toESM(require("node:path"));
37
37
  var import_constants = require("../../constants");
38
38
  const builtinSwcLoaderName = "builtin:swc-loader";
39
39
  async function getDefaultSwcConfig(config, rootPath, target) {
@@ -79,7 +79,7 @@ const pluginSwc = () => ({
79
79
  if (swcConfig.jsc?.externalHelpers) {
80
80
  chain.resolve.alias.set(
81
81
  "@swc/helpers",
82
- import_path.default.dirname(require.resolve("@swc/helpers/package.json"))
82
+ import_node_path.default.dirname(require.resolve("@swc/helpers/package.json"))
83
83
  );
84
84
  }
85
85
  if ((0, import_shared.isWebTarget)(target)) {
@@ -101,7 +101,7 @@ const pluginSwc = () => ({
101
101
  async function applyCoreJs(swcConfig, chain, polyfillMode) {
102
102
  const coreJsPath = require.resolve("core-js/package.json");
103
103
  const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
104
- const coreJsDir = import_path.default.dirname(coreJsPath);
104
+ const coreJsDir = import_node_path.default.dirname(coreJsPath);
105
105
  swcConfig.env.coreJs = version;
106
106
  if (polyfillMode === "usage") {
107
107
  swcConfig.env.shippedProposals = true;
@@ -36,7 +36,7 @@ __export(shared_exports, {
36
36
  rspackMinVersion: () => rspackMinVersion
37
37
  });
38
38
  module.exports = __toCommonJS(shared_exports);
39
- var import_path = require("path");
39
+ var import_node_path = require("node:path");
40
40
  var import_shared = require("@rsbuild/shared");
41
41
  var import_shared2 = require("@rsbuild/shared");
42
42
  var import_shared3 = require("@rsbuild/shared");
@@ -103,7 +103,7 @@ const isSatisfyRspackVersion = async (originalVersion) => {
103
103
  return true;
104
104
  };
105
105
  const getCompiledPath = (packageName) => {
106
- const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
106
+ const providerCompilerPath = (0, import_node_path.join)(__dirname, "../../compiled", packageName);
107
107
  if (import_shared2.fse.existsSync(providerCompilerPath)) {
108
108
  return providerCompilerPath;
109
109
  }
@@ -36,8 +36,8 @@ __export(HtmlAppIconPlugin_exports, {
36
36
  HtmlAppIconPlugin: () => HtmlAppIconPlugin
37
37
  });
38
38
  module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
39
- var import_fs = __toESM(require("fs"));
40
- var import_path = require("path");
39
+ var import_node_fs = __toESM(require("node:fs"));
40
+ var import_node_path = require("node:path");
41
41
  var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
42
42
  var import_shared = require("@rsbuild/shared");
43
43
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
@@ -51,12 +51,12 @@ class HtmlAppIconPlugin {
51
51
  this.iconPath = options.iconPath;
52
52
  }
53
53
  apply(compiler) {
54
- if (!import_fs.default.existsSync(this.iconPath)) {
54
+ if (!import_node_fs.default.existsSync(this.iconPath)) {
55
55
  throw new Error(
56
56
  `[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
57
57
  );
58
58
  }
59
- const iconRelativePath = import_path.posix.join(this.distDir, (0, import_path.basename)(this.iconPath));
59
+ const iconRelativePath = import_node_path.posix.join(this.distDir, (0, import_node_path.basename)(this.iconPath));
60
60
  compiler.hooks.compilation.tap(this.name, (compilation) => {
61
61
  (0, import_htmlPluginUtil.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
62
62
  const publicPath = (0, import_shared.getPublicPathFromCompiler)(compiler);
@@ -82,7 +82,7 @@ class HtmlAppIconPlugin {
82
82
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
83
83
  },
84
84
  (assets) => {
85
- const source = import_fs.default.readFileSync(this.iconPath);
85
+ const source = import_node_fs.default.readFileSync(this.iconPath);
86
86
  assets[iconRelativePath] = new import_webpack_sources.default.RawSource(
87
87
  source,
88
88
  false
@@ -26,7 +26,7 @@ __export(InlineChunkHtmlPlugin_exports, {
26
26
  InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
27
27
  });
28
28
  module.exports = __toCommonJS(InlineChunkHtmlPlugin_exports);
29
- var import_path = require("path");
29
+ var import_node_path = require("node:path");
30
30
  var import_shared = require("@rsbuild/shared");
31
31
  var import_htmlPluginUtil = require("../provider/htmlPluginUtil");
32
32
  class InlineChunkHtmlPlugin {
@@ -61,7 +61,7 @@ class InlineChunkHtmlPlugin {
61
61
  if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
62
62
  !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
63
63
  const prefix = (0, import_shared.addTrailingSlash)(
64
- (0, import_path.join)(publicPath, this.distPath[type] || "")
64
+ (0, import_node_path.join)(publicPath, this.distPath[type] || "")
65
65
  );
66
66
  return source.replace(
67
67
  /# sourceMappingURL=/,
@@ -31,8 +31,9 @@ __export(determineAsValue_exports, {
31
31
  determineAsValue: () => determineAsValue
32
32
  });
33
33
  module.exports = __toCommonJS(determineAsValue_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_url = require("url");
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_node_url = require("node:url");
36
+ var import_shared = require("@rsbuild/shared");
36
37
  /**
37
38
  * @license
38
39
  * Copyright 2018 Google Inc.
@@ -54,41 +55,24 @@ function determineAsValue({
54
55
  href,
55
56
  file
56
57
  }) {
57
- const url = new import_url.URL(file || href, "https://example.com");
58
- const extension = import_path.default.extname(url.pathname);
59
- if ([".css"].includes(extension)) {
58
+ const url = new import_node_url.URL(file || href, "https://example.com");
59
+ const extension = import_node_path.default.extname(url.pathname).slice(1);
60
+ if (["css"].includes(extension)) {
60
61
  return "style";
61
62
  }
62
- if ([
63
- ".png",
64
- ".jpg",
65
- ".jpeg",
66
- ".jfif",
67
- ".pjpeg",
68
- ".pjp",
69
- ".svg",
70
- ".webp",
71
- ".bmp",
72
- ".apng",
73
- ".avif",
74
- ".gif",
75
- ".ico",
76
- ".cur",
77
- ".tif",
78
- ".tiff"
79
- ].includes(extension)) {
63
+ if (import_shared.IMAGE_EXTENSIONS.includes(extension)) {
80
64
  return "image";
81
65
  }
82
- if ([".mp4", ".ogg", ".webm"].includes(extension)) {
66
+ if (import_shared.VIDEO_EXTENSIONS.includes(extension)) {
83
67
  return "video";
84
68
  }
85
- if ([".mp3", ".wav"].includes(extension)) {
69
+ if (import_shared.AUDIO_EXTENSIONS.includes(extension)) {
86
70
  return "audio";
87
71
  }
88
- if ([".woff2", ".otf", ".ttf", ".woff", ".eot"].includes(extension)) {
72
+ if (import_shared.FONT_EXTENSIONS.includes(extension)) {
89
73
  return "font";
90
74
  }
91
- if ([".vtt"].includes(extension)) {
75
+ if (["vtt"].includes(extension)) {
92
76
  return "track";
93
77
  }
94
78
  return "script";
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import type { IncomingMessage } from 'http';
4
- import type { Socket } from 'net';
3
+ import type { IncomingMessage } from 'node:http';
4
+ import type { Socket } from 'node:net';
5
5
  import type { DevMiddlewaresConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
6
6
  type Options = {
7
7
  publicPaths: string[];
@@ -31,9 +31,10 @@ __export(getDevMiddlewares_exports, {
31
31
  getMiddlewares: () => getMiddlewares
32
32
  });
33
33
  module.exports = __toCommonJS(getDevMiddlewares_exports);
34
- var import_url = __toESM(require("url"));
34
+ var import_node_url = __toESM(require("node:url"));
35
+ var import_shared = require("@rsbuild/shared");
35
36
  var import_middlewares = require("./middlewares");
36
- var import_path = require("path");
37
+ var import_node_path = require("node:path");
37
38
  const applySetupMiddlewares = (dev, compileMiddlewareAPI) => {
38
39
  const setupMiddlewares = dev.setupMiddlewares || [];
39
40
  const serverOptions = {
@@ -71,7 +72,7 @@ const applyDefaultMiddlewares = async ({
71
72
  }
72
73
  middlewares.push((req, res, next) => {
73
74
  res.setHeader("Access-Control-Allow-Origin", "*");
74
- const path = req.url ? import_url.default.parse(req.url).pathname : "";
75
+ const path = req.url ? import_node_url.default.parse(req.url).pathname : "";
75
76
  if (path?.includes("hot-update")) {
76
77
  res.setHeader("Access-Control-Allow-Credentials", "false");
77
78
  }
@@ -104,7 +105,7 @@ const applyDefaultMiddlewares = async ({
104
105
  if (dev.publicDir !== false && dev.publicDir?.name) {
105
106
  const { default: sirv } = await Promise.resolve().then(() => __toESM(require("../../compiled/sirv")));
106
107
  const { name } = dev.publicDir;
107
- const publicDir = (0, import_path.isAbsolute)(name) ? name : (0, import_path.join)(pwd, name);
108
+ const publicDir = (0, import_node_path.isAbsolute)(name) ? name : (0, import_node_path.join)(pwd, name);
108
109
  const assetMiddleware = sirv(publicDir, {
109
110
  etag: true,
110
111
  dev: true
@@ -114,7 +115,7 @@ const applyDefaultMiddlewares = async ({
114
115
  const { distPath } = output;
115
116
  compileMiddlewareAPI && middlewares.push(
116
117
  (0, import_middlewares.getHtmlFallbackMiddleware)({
117
- distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(pwd, distPath),
118
+ distPath: (0, import_node_path.isAbsolute)(distPath) ? distPath : (0, import_node_path.join)(pwd, distPath),
118
119
  callback: compileMiddlewareAPI.middleware,
119
120
  htmlFallback: dev.htmlFallback
120
121
  })
@@ -137,6 +138,9 @@ const applyDefaultMiddlewares = async ({
137
138
  const getMiddlewares = async (options) => {
138
139
  const middlewares = [];
139
140
  const { compileMiddlewareAPI } = options;
141
+ if ((0, import_shared.isDebug)()) {
142
+ middlewares.push(await (0, import_middlewares.getRequestLoggerMiddleware)());
143
+ }
140
144
  const { before, after } = applySetupMiddlewares(
141
145
  options.dev,
142
146
  compileMiddlewareAPI
@@ -33,10 +33,10 @@ __export(httpServer_exports, {
33
33
  module.exports = __toCommonJS(httpServer_exports);
34
34
  const createHttpServer = async (options) => {
35
35
  if (options.https) {
36
- const { createServer: createServer2 } = await Promise.resolve().then(() => __toESM(require("https")));
36
+ const { createServer: createServer2 } = await Promise.resolve().then(() => __toESM(require("node:https")));
37
37
  return createServer2(options.https, options.middlewares);
38
38
  }
39
- const { createServer } = await Promise.resolve().then(() => __toESM(require("http")));
39
+ const { createServer } = await Promise.resolve().then(() => __toESM(require("node:http")));
40
40
  return createServer(options.middlewares);
41
41
  };
42
42
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,5 +1,7 @@
1
1
  import { type HtmlFallback, type RequestHandler as Middleware } from '@rsbuild/shared';
2
+ import type { NextHandleFunction } from '@rsbuild/shared/connect';
2
3
  export declare const faviconFallbackMiddleware: Middleware;
4
+ export declare const getRequestLoggerMiddleware: () => Promise<NextHandleFunction>;
3
5
  export declare const notFoundMiddleware: Middleware;
4
6
  export declare const getHtmlFallbackMiddleware: (params: {
5
7
  distPath: string;