@rsbuild/core 0.0.25 → 0.0.27

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 (66) hide show
  1. package/bin/rsbuild.js +4 -25
  2. package/compiled/jiti/index.js +1885 -0
  3. package/compiled/jiti/license +21 -0
  4. package/compiled/jiti/package.json +1 -0
  5. package/compiled/jiti/types/jiti.d.ts +19 -0
  6. package/compiled/jiti/types/types.d.ts +31 -0
  7. package/compiled/sirv/index.js +1 -0
  8. package/compiled/sirv/package.json +1 -0
  9. package/compiled/sirv/sirv.d.ts +27 -0
  10. package/dist/cli/commands.d.ts +8 -4
  11. package/dist/cli/commands.js +49 -10
  12. package/dist/cli/config.d.ts +2 -2
  13. package/dist/cli/config.js +15 -6
  14. package/dist/cli/prepare.d.ts +1 -0
  15. package/dist/cli/{run.js → prepare.js} +19 -17
  16. package/dist/createRsbuild.d.ts +0 -1
  17. package/dist/createRsbuild.js +4 -9
  18. package/dist/index.d.ts +7 -3
  19. package/dist/index.js +2 -4
  20. package/dist/plugins/splitChunks.d.ts +0 -2
  21. package/dist/plugins/splitChunks.js +3 -13
  22. package/dist/rspack-provider/config.d.ts +9 -0
  23. package/dist/rspack-provider/{config/defaults.js → config.js} +9 -3
  24. package/dist/rspack-provider/core/createCompiler.d.ts +3 -4
  25. package/dist/rspack-provider/core/createCompiler.js +21 -11
  26. package/dist/rspack-provider/core/createContext.d.ts +8 -2
  27. package/dist/rspack-provider/core/createContext.js +90 -5
  28. package/dist/rspack-provider/core/initConfigs.d.ts +2 -2
  29. package/dist/rspack-provider/core/initConfigs.js +4 -3
  30. package/dist/rspack-provider/core/initPlugins.js +2 -1
  31. package/dist/rspack-provider/core/rspackConfig.js +1 -4
  32. package/dist/rspack-provider/index.d.ts +3 -2
  33. package/dist/rspack-provider/index.js +11 -4
  34. package/dist/rspack-provider/plugins/css.js +2 -10
  35. package/dist/rspack-provider/provider.js +5 -6
  36. package/dist/rspack-provider/shared.d.ts +8 -0
  37. package/dist/rspack-provider/shared.js +116 -0
  38. package/dist/server/devServer.d.ts +3 -3
  39. package/dist/server/devServer.js +9 -6
  40. package/dist/server/middlewares.d.ts +1 -1
  41. package/dist/server/middlewares.js +2 -2
  42. package/dist/server/prodServer.js +1 -1
  43. package/dist/server/proxy.d.ts +3 -4
  44. package/dist/server/proxy.js +15 -17
  45. package/dist/server/restart.js +2 -4
  46. package/package.json +5 -8
  47. package/dist/cli/index.d.ts +0 -2
  48. package/dist/cli/index.js +0 -31
  49. package/dist/cli/run.d.ts +0 -5
  50. package/dist/rspack-provider/config/defaults.d.ts +0 -3
  51. package/dist/rspack-provider/config/normalize.d.ts +0 -7
  52. package/dist/rspack-provider/config/normalize.js +0 -33
  53. package/dist/rspack-provider/shared/constants.d.ts +0 -1
  54. package/dist/rspack-provider/shared/constants.js +0 -28
  55. package/dist/rspack-provider/shared/fs.d.ts +0 -1
  56. package/dist/rspack-provider/shared/fs.js +0 -38
  57. package/dist/rspack-provider/shared/index.d.ts +0 -3
  58. package/dist/rspack-provider/shared/index.js +0 -26
  59. package/dist/rspack-provider/shared/plugin.d.ts +0 -3
  60. package/dist/rspack-provider/shared/plugin.js +0 -75
  61. package/dist/rspack-provider/shared/rspackVersion.d.ts +0 -3
  62. package/dist/rspack-provider/shared/rspackVersion.js +0 -61
  63. /package/dist/rspack-provider/{rspackLoader/css-modules-typescript-pre-loader → css-modules-typescript-pre-loader}/index.d.ts +0 -0
  64. /package/dist/rspack-provider/{rspackLoader/css-modules-typescript-pre-loader → css-modules-typescript-pre-loader}/index.js +0 -0
  65. /package/dist/rspack-provider/{rspackLoader/css-modules-typescript-pre-loader → css-modules-typescript-pre-loader}/postcss-icss-extract-plugin.d.ts +0 -0
  66. /package/dist/rspack-provider/{rspackLoader/css-modules-typescript-pre-loader → css-modules-typescript-pre-loader}/postcss-icss-extract-plugin.js +0 -0
@@ -1,5 +1,11 @@
1
- import { type CreateRsbuildOptions } from '@rsbuild/shared';
2
- import type { Context, RsbuildConfig } from '../../types';
1
+ import { RsbuildConfig, type Context as BaseContext, type BundlerType, type SourceConfig, type OutputConfig, type NormalizedConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
2
+ import type { Context } from '../../types';
3
+ /**
4
+ * Create context by config.
5
+ */
6
+ export declare function createContextByConfig(options: Required<CreateRsbuildOptions>, bundlerType: BundlerType, sourceConfig?: SourceConfig, outputConfig?: OutputConfig): BaseContext;
7
+ export declare function updateContextByNormalizedConfig(context: BaseContext, config: NormalizedConfig): void;
8
+ export declare function createPublicContext(context: BaseContext): Readonly<BaseContext>;
3
9
  /**
4
10
  * Generate the actual context used in the build,
5
11
  * which can have a lot of overhead and take some side effects.
@@ -18,16 +18,98 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var createContext_exports = {};
20
20
  __export(createContext_exports, {
21
- createContext: () => createContext
21
+ createContext: () => createContext,
22
+ createContextByConfig: () => createContextByConfig,
23
+ createPublicContext: () => createPublicContext,
24
+ updateContextByNormalizedConfig: () => updateContextByNormalizedConfig
22
25
  });
23
26
  module.exports = __toCommonJS(createContext_exports);
24
27
  var import_path = require("path");
25
28
  var import_shared = require("@rsbuild/shared");
26
29
  var import_initHooks = require("./initHooks");
27
- var import_defaults = require("../config/defaults");
30
+ var import_config = require("../config");
31
+ function getDefaultEntry(root) {
32
+ const files = [
33
+ // Most projects are using typescript now.
34
+ // So we put `.ts` as the first one to improve performance.
35
+ "ts",
36
+ "js",
37
+ "tsx",
38
+ "jsx",
39
+ ".mjs",
40
+ ".cjs"
41
+ ].map((ext) => (0, import_path.join)(root, `src/index.${ext}`));
42
+ const entryFile = (0, import_shared.findExists)(files);
43
+ if (entryFile) {
44
+ return {
45
+ index: entryFile
46
+ };
47
+ }
48
+ return {};
49
+ }
50
+ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputConfig = {}) {
51
+ const { cwd, target } = options;
52
+ const rootPath = cwd;
53
+ const distPath = (0, import_shared.getAbsoluteDistPath)(cwd, outputConfig);
54
+ const cachePath = (0, import_path.join)(rootPath, "node_modules", ".cache");
55
+ if (sourceConfig.entries) {
56
+ import_shared.logger.warn(
57
+ "[Rsbuild] `source.entries` option has been renamed to `source.entry`, please update the Rsbuild config."
58
+ );
59
+ import_shared.logger.warn(
60
+ "[Rsbuild] `source.entries` option will be removed in Rsbuild v0.2.0."
61
+ );
62
+ }
63
+ const context = {
64
+ entry: sourceConfig.entry || // TODO: remove sourceConfig.entries in v0.2.0
65
+ // compat with previous config
66
+ sourceConfig.entries || getDefaultEntry(rootPath),
67
+ version: "0.0.27",
68
+ target,
69
+ rootPath,
70
+ distPath,
71
+ cachePath,
72
+ bundlerType
73
+ };
74
+ return context;
75
+ }
76
+ function updateContextByNormalizedConfig(context, config) {
77
+ context.distPath = (0, import_shared.getAbsoluteDistPath)(context.rootPath, config.output);
78
+ if (config.source.entry) {
79
+ context.entry = config.source.entry;
80
+ }
81
+ }
82
+ function createPublicContext(context) {
83
+ const exposedKeys = [
84
+ "entry",
85
+ "target",
86
+ "version",
87
+ "rootPath",
88
+ "distPath",
89
+ "devServer",
90
+ "cachePath",
91
+ "configPath",
92
+ "tsconfigPath",
93
+ "bundlerType"
94
+ ];
95
+ return new Proxy(context, {
96
+ get(target, prop) {
97
+ if (exposedKeys.includes(prop)) {
98
+ return target[prop];
99
+ }
100
+ return void 0;
101
+ },
102
+ set(_, prop) {
103
+ import_shared.logger.error(
104
+ `Context is readonly, you can not assign to the "context.${prop}" prop.`
105
+ );
106
+ return true;
107
+ }
108
+ });
109
+ }
28
110
  async function createContext(options, userRsbuildConfig) {
29
- const rsbuildConfig = (0, import_defaults.withDefaultConfig)(userRsbuildConfig);
30
- const context = (0, import_shared.createContextByConfig)(
111
+ const rsbuildConfig = (0, import_config.withDefaultConfig)(userRsbuildConfig);
112
+ const context = createContextByConfig(
31
113
  options,
32
114
  "rspack",
33
115
  rsbuildConfig.source,
@@ -44,5 +126,8 @@ async function createContext(options, userRsbuildConfig) {
44
126
  }
45
127
  // Annotate the CommonJS export names for ESM import in node:
46
128
  0 && (module.exports = {
47
- createContext
129
+ createContext,
130
+ createContextByConfig,
131
+ createPublicContext,
132
+ updateContextByNormalizedConfig
48
133
  });
@@ -1,4 +1,4 @@
1
- import { type PluginStore, type CreateRsbuildOptions } from '@rsbuild/shared';
1
+ import { type PluginStore, type RspackConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
2
2
  import type { Context } from '../../types';
3
3
  export type InitConfigsOptions = {
4
4
  context: Context;
@@ -10,5 +10,5 @@ export declare function initConfigs({
10
10
  pluginStore,
11
11
  rsbuildOptions
12
12
  }: InitConfigsOptions): Promise<{
13
- rspackConfigs: import("@rsbuild/shared").RspackConfig[];
13
+ rspackConfigs: RspackConfig[];
14
14
  }>;
@@ -22,9 +22,10 @@ __export(initConfigs_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(initConfigs_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
+ var import_createContext = require("./createContext");
25
26
  var import_inspectConfig = require("./inspectConfig");
26
27
  var import_rspackConfig = require("./rspackConfig");
27
- var import_normalize = require("../config/normalize");
28
+ var import_config = require("../config");
28
29
  async function modifyRsbuildConfig(context) {
29
30
  (0, import_shared.debug)("modify Rsbuild config");
30
31
  const [modified] = await context.hooks.modifyRsbuildConfigHook.call(
@@ -44,8 +45,8 @@ async function initConfigs({
44
45
  pluginStore
45
46
  });
46
47
  await modifyRsbuildConfig(context);
47
- context.normalizedConfig = (0, import_normalize.normalizeConfig)(context.config);
48
- (0, import_shared.updateContextByNormalizedConfig)(context, context.normalizedConfig);
48
+ context.normalizedConfig = (0, import_config.normalizeConfig)(context.config);
49
+ (0, import_createContext.updateContextByNormalizedConfig)(context, context.normalizedConfig);
49
50
  const targets = (0, import_shared.castArray)(rsbuildOptions.target);
50
51
  const rspackConfigs = await Promise.all(
51
52
  targets.map((target) => (0, import_rspackConfig.generateRspackConfig)({ target, context }))
@@ -22,12 +22,13 @@ __export(initPlugins_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(initPlugins_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
+ var import_createContext = require("./createContext");
25
26
  function getPluginAPI({
26
27
  context,
27
28
  pluginStore
28
29
  }) {
29
30
  const { hooks } = context;
30
- const publicContext = (0, import_shared.createPublicContext)(context);
31
+ const publicContext = (0, import_createContext.createPublicContext)(context);
31
32
  const getRsbuildConfig = () => {
32
33
  if (!context.normalizedConfig) {
33
34
  throw new Error(
@@ -104,9 +104,6 @@ async function getChainUtils(target) {
104
104
  HtmlPlugin
105
105
  };
106
106
  }
107
- const convertToRspackConfig = (config) => {
108
- return config;
109
- };
110
107
  async function generateRspackConfig({
111
108
  target,
112
109
  context
@@ -121,7 +118,7 @@ async function generateRspackConfig({
121
118
  ProvidePlugin
122
119
  }
123
120
  });
124
- let rspackConfig = convertToRspackConfig(chain.toConfig());
121
+ let rspackConfig = chain.toConfig();
125
122
  rspackConfig = await modifyRspackConfig(
126
123
  context,
127
124
  rspackConfig,
@@ -1,4 +1,5 @@
1
- export { getRspackVersion } from './shared/rspackVersion';
1
+ export { getRspackVersion } from './shared';
2
2
  export { rspackProvider } from './provider';
3
3
  export type { RspackProvider } from './provider';
4
- export type { Rspack, RspackConfig } from '@rsbuild/shared';
4
+ export type { Rspack, RspackConfig } from '@rsbuild/shared';
5
+ export { createPublicContext, createContextByConfig, updateContextByNormalizedConfig } from './core/createContext';
@@ -18,14 +18,21 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var rspack_provider_exports = {};
20
20
  __export(rspack_provider_exports, {
21
- getRspackVersion: () => import_rspackVersion.getRspackVersion,
22
- rspackProvider: () => import_provider.rspackProvider
21
+ createContextByConfig: () => import_createContext.createContextByConfig,
22
+ createPublicContext: () => import_createContext.createPublicContext,
23
+ getRspackVersion: () => import_shared.getRspackVersion,
24
+ rspackProvider: () => import_provider.rspackProvider,
25
+ updateContextByNormalizedConfig: () => import_createContext.updateContextByNormalizedConfig
23
26
  });
24
27
  module.exports = __toCommonJS(rspack_provider_exports);
25
- var import_rspackVersion = require("./shared/rspackVersion");
28
+ var import_shared = require("./shared");
26
29
  var import_provider = require("./provider");
30
+ var import_createContext = require("./core/createContext");
27
31
  // Annotate the CommonJS export names for ESM import in node:
28
32
  0 && (module.exports = {
33
+ createContextByConfig,
34
+ createPublicContext,
29
35
  getRspackVersion,
30
- rspackProvider
36
+ rspackProvider,
37
+ updateContextByNormalizedConfig
31
38
  });
@@ -45,7 +45,6 @@ async function applyBaseCSSRule({
45
45
  utils: { target, isProd, isServer, isWebWorker, CHAIN_ID },
46
46
  importLoaders = 1
47
47
  }) {
48
- const enableExtractCSS = (0, import_shared.isUseCssExtract)(config, target);
49
48
  const enableSourceMap = (0, import_shared.isUseCssSourceMap)(config);
50
49
  const enableCSSModuleTS = Boolean(config.output.enableCssModuleTSDeclaration);
51
50
  const browserslist = await (0, import_shared.getBrowserslistWithDefault)(
@@ -53,7 +52,6 @@ async function applyBaseCSSRule({
53
52
  config,
54
53
  target
55
54
  );
56
- const enableCssMinify = !enableExtractCSS && isProd;
57
55
  if (!enableNativeCss(config)) {
58
56
  const localIdentName = (0, import_shared.getCssModuleLocalIdentName)(config, isProd);
59
57
  const cssLoaderOptions = (0, import_shared.getCssLoaderOptions)({
@@ -91,12 +89,7 @@ async function applyBaseCSSRule({
91
89
  } else {
92
90
  if (!isServer && !isWebWorker && enableCSSModuleTS) {
93
91
  const { cssModules } = config.output;
94
- rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(
95
- import_path.default.resolve(
96
- __dirname,
97
- "../rspackLoader/css-modules-typescript-pre-loader"
98
- )
99
- ).options({
92
+ rule.use(CHAIN_ID.USE.CSS_MODULES_TS).loader(import_path.default.resolve(__dirname, "../css-modules-typescript-pre-loader")).options({
100
93
  modules: {
101
94
  exportLocalsConvention: cssModules.exportLocalsConvention,
102
95
  auto: cssModules.auto
@@ -109,8 +102,7 @@ async function applyBaseCSSRule({
109
102
  const postcssLoaderOptions = (0, import_shared.getPostcssConfig)({
110
103
  enableSourceMap,
111
104
  browserslist,
112
- config,
113
- enableCssMinify
105
+ config
114
106
  });
115
107
  rule.use(CHAIN_ID.USE.POSTCSS).loader((0, import_shared2.getCompiledPath)("postcss-loader")).options(postcssLoaderOptions).end();
116
108
  }
@@ -35,17 +35,16 @@ var import_shared = require("@rsbuild/shared");
35
35
  var import_createContext = require("./core/createContext");
36
36
  var import_initConfigs = require("./core/initConfigs");
37
37
  var import_initPlugins = require("./core/initPlugins");
38
- var import_plugin = require("./shared/plugin");
39
- var import_rspackVersion = require("./shared/rspackVersion");
38
+ var import_shared2 = require("./shared");
40
39
  function rspackProvider({
41
40
  rsbuildConfig: originalRsbuildConfig
42
41
  }) {
43
42
  const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(originalRsbuildConfig);
44
43
  return async ({ pluginStore, rsbuildOptions, plugins }) => {
45
- if (!await (0, import_rspackVersion.isSatisfyRspackMinimumVersion)()) {
44
+ if (!await (0, import_shared2.isSatisfyRspackMinimumVersion)()) {
46
45
  throw new Error(
47
46
  `The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared.color.green(
48
- import_rspackVersion.supportedRspackMinimumVersion
47
+ import_shared2.supportedRspackMinimumVersion
49
48
  )}`
50
49
  );
51
50
  }
@@ -55,9 +54,9 @@ function rspackProvider({
55
54
  return {
56
55
  bundler: "rspack",
57
56
  pluginAPI,
58
- publicContext: (0, import_shared.createPublicContext)(context),
57
+ publicContext: (0, import_createContext.createPublicContext)(context),
59
58
  async applyDefaultPlugins() {
60
- pluginStore.addPlugins(await (0, import_plugin.applyDefaultPlugins)(plugins));
59
+ pluginStore.addPlugins(await (0, import_shared2.applyDefaultPlugins)(plugins));
61
60
  },
62
61
  async createCompiler() {
63
62
  const { createCompiler } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
@@ -0,0 +1,8 @@
1
+ import { RsbuildPlugin } from '../types';
2
+ import { Plugins } from '@rsbuild/shared';
3
+ export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
4
+ export declare const getRspackVersion: () => Promise<string>;
5
+ export declare const supportedRspackMinimumVersion = "0.3.6";
6
+ export declare const isSatisfyRspackMinimumVersion: (customVersion?: string) => Promise<boolean>;
7
+ export declare const getCompiledPath: (packageName: string) => string;
8
+ export declare const BUILTIN_LOADER = "builtin:";
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var shared_exports = {};
30
+ __export(shared_exports, {
31
+ BUILTIN_LOADER: () => BUILTIN_LOADER,
32
+ applyDefaultPlugins: () => applyDefaultPlugins,
33
+ getCompiledPath: () => getCompiledPath,
34
+ getRspackVersion: () => getRspackVersion,
35
+ isSatisfyRspackMinimumVersion: () => isSatisfyRspackMinimumVersion,
36
+ supportedRspackMinimumVersion: () => supportedRspackMinimumVersion
37
+ });
38
+ module.exports = __toCommonJS(shared_exports);
39
+ var import_path = require("path");
40
+ var import_shared = require("@rsbuild/shared");
41
+ var import_shared2 = require("@rsbuild/shared");
42
+ var import_shared3 = require("@rsbuild/shared");
43
+ const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
44
+ Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
45
+ Promise.resolve().then(() => __toESM(require("./plugins/basic"))).then((m) => m.pluginBasic()),
46
+ plugins.entry(),
47
+ // plugins.cache(),
48
+ plugins.target(),
49
+ Promise.resolve().then(() => __toESM(require("./plugins/output"))).then((m) => m.pluginOutput()),
50
+ plugins.devtool(),
51
+ Promise.resolve().then(() => __toESM(require("./plugins/resolve"))).then((m) => m.pluginResolve()),
52
+ plugins.fileSize(),
53
+ // cleanOutput plugin should before the html plugin
54
+ plugins.cleanOutput(),
55
+ plugins.asset(),
56
+ plugins.html(),
57
+ plugins.wasm(),
58
+ plugins.moment(),
59
+ plugins.nodeAddons(),
60
+ plugins.define(),
61
+ Promise.resolve().then(() => __toESM(require("./plugins/css"))).then((m) => m.pluginCss()),
62
+ Promise.resolve().then(() => __toESM(require("./plugins/less"))).then((m) => m.pluginLess()),
63
+ Promise.resolve().then(() => __toESM(require("./plugins/sass"))).then((m) => m.pluginSass()),
64
+ Promise.resolve().then(() => __toESM(require("./plugins/minimize"))).then((m) => m.pluginMinimize()),
65
+ Promise.resolve().then(() => __toESM(require("./plugins/hmr"))).then((m) => m.pluginHMR()),
66
+ Promise.resolve().then(() => __toESM(require("./plugins/progress"))).then((m) => m.pluginProgress()),
67
+ Promise.resolve().then(() => __toESM(require("./plugins/swc"))).then((m) => m.pluginSwc()),
68
+ plugins.externals(),
69
+ plugins.toml(),
70
+ plugins.yaml(),
71
+ plugins.splitChunks(),
72
+ plugins.startUrl(),
73
+ plugins.inlineChunk(),
74
+ plugins.bundleAnalyzer(),
75
+ plugins.networkPerformance(),
76
+ plugins.preloadOrPrefetch(),
77
+ plugins.performance(),
78
+ Promise.resolve().then(() => __toESM(require("./plugins/rspackProfile"))).then((m) => m.pluginRspackProfile())
79
+ ]);
80
+ const getRspackVersion = async () => {
81
+ try {
82
+ const core = require.resolve("@rspack/core");
83
+ const pkg = await Promise.resolve().then(() => __toESM(require((0, import_path.join)(core, "../../package.json"))));
84
+ return pkg == null ? void 0 : pkg.version;
85
+ } catch (err) {
86
+ console.error(err);
87
+ return "";
88
+ }
89
+ };
90
+ const supportedRspackMinimumVersion = "0.3.6";
91
+ const isSatisfyRspackMinimumVersion = async (customVersion) => {
92
+ let version = customVersion || await getRspackVersion();
93
+ const semver = await Promise.resolve().then(() => __toESM(require("semver")));
94
+ if (version.includes("-canary")) {
95
+ version = version.split("-canary")[0];
96
+ }
97
+ return version ? semver.lte(supportedRspackMinimumVersion, version) : true;
98
+ };
99
+ const getCompiledPath = (packageName) => {
100
+ const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
101
+ if (import_shared2.fse.existsSync(providerCompilerPath)) {
102
+ return providerCompilerPath;
103
+ } else {
104
+ return (0, import_shared.getSharedPkgCompiledPath)(packageName);
105
+ }
106
+ };
107
+ const BUILTIN_LOADER = "builtin:";
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ BUILTIN_LOADER,
111
+ applyDefaultPlugins,
112
+ getCompiledPath,
113
+ getRspackVersion,
114
+ isSatisfyRspackMinimumVersion,
115
+ supportedRspackMinimumVersion
116
+ });
@@ -3,7 +3,7 @@
3
3
  /// <reference types="node" />
4
4
  import { Server } from 'http';
5
5
  import type { ListenOptions } from 'net';
6
- import { RsbuildDevServerOptions, CreateDevServerOptions, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
6
+ import { RsbuildDevServerOptions, CreateDevMiddlewareReturns, DevServerContext, StartDevServerOptions, StartServerResult } from '@rsbuild/shared';
7
7
  import connect from '@rsbuild/shared/connect';
8
8
  export declare class RsbuildDevServer {
9
9
  private readonly dev;
@@ -22,9 +22,9 @@ export declare class RsbuildDevServer {
22
22
  }
23
23
  export declare function startDevServer<Options extends {
24
24
  context: DevServerContext;
25
- }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevServerOptions['devMiddleware']>, {
25
+ }>(options: Options, createDevMiddleware: (options: Options, compiler: StartDevServerOptions['compiler']) => Promise<CreateDevMiddlewareReturns>, {
26
26
  open,
27
- compiler,
27
+ compiler: customCompiler,
28
28
  printURLs,
29
29
  strictPort,
30
30
  logger: customLogger,
@@ -105,8 +105,7 @@ class RsbuildDevServer {
105
105
  next();
106
106
  });
107
107
  if (dev.proxy) {
108
- const { middlewares, handleUpgrade } = (0, import_proxy.createProxyMiddleware)(dev.proxy);
109
- app && handleUpgrade(app);
108
+ const { middlewares } = (0, import_proxy.createProxyMiddleware)(dev.proxy, app);
110
109
  middlewares.forEach((middleware) => {
111
110
  this.middlewares.use(middleware);
112
111
  });
@@ -116,7 +115,7 @@ class RsbuildDevServer {
116
115
  this.middlewares.use(
117
116
  (0, import_middlewares.getHtmlFallbackMiddleware)({
118
117
  distPath: (0, import_path.join)(this.pwd, this.output.distPath),
119
- assetPrefix: this.output.assetPrefix,
118
+ publicPath: this.output.publicPath,
120
119
  callback: devMiddleware.middleware
121
120
  })
122
121
  );
@@ -159,7 +158,7 @@ class RsbuildDevServer {
159
158
  }
160
159
  async function startDevServer(options, createDevMiddleware, {
161
160
  open,
162
- compiler,
161
+ compiler: customCompiler,
163
162
  printURLs = true,
164
163
  strictPort = false,
165
164
  logger: customLogger,
@@ -189,14 +188,18 @@ async function startDevServer(options, createDevMiddleware, {
189
188
  (_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.html
190
189
  );
191
190
  (0, import_shared.debug)("create dev server");
192
- const devMiddleware = await createDevMiddleware(options, compiler);
191
+ const { devMiddleware, compiler } = await createDevMiddleware(
192
+ options,
193
+ customCompiler
194
+ );
195
+ const publicPath = compiler.compilers ? (0, import_shared.getPublicPathFromCompiler)(compiler.compilers[0]) : (0, import_shared.getPublicPathFromCompiler)(compiler);
193
196
  const server = new RsbuildDevServer({
194
197
  pwd: options.context.rootPath,
195
198
  devMiddleware,
196
199
  dev: devServerConfig,
197
200
  output: {
198
201
  distPath: ((_e = (_d = rsbuildConfig.output) == null ? void 0 : _d.distPath) == null ? void 0 : _e.root) || import_shared.ROOT_DIST_DIR,
199
- assetPrefix: typeof devServerConfig.assetPrefix === "string" && !(0, import_shared.isURL)(devServerConfig.assetPrefix) ? devServerConfig.assetPrefix : ""
202
+ publicPath
200
203
  }
201
204
  });
202
205
  (0, import_shared.debug)("create dev server done");
@@ -3,6 +3,6 @@ export declare const faviconFallbackMiddleware: Middleware;
3
3
  export declare const notFoundMiddleware: Middleware;
4
4
  export declare const getHtmlFallbackMiddleware: (params: {
5
5
  distPath: string;
6
- assetPrefix: string;
6
+ publicPath: string;
7
7
  callback?: Middleware;
8
8
  }) => Middleware;
@@ -48,7 +48,7 @@ const notFoundMiddleware = (_req, res, _next) => {
48
48
  res.statusCode = 404;
49
49
  res.end();
50
50
  };
51
- const getHtmlFallbackMiddleware = ({ assetPrefix, distPath, callback }) => {
51
+ const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
52
52
  return (req, res, next) => {
53
53
  if (
54
54
  // Only accept GET or HEAD
@@ -69,7 +69,7 @@ const getHtmlFallbackMiddleware = ({ assetPrefix, distPath, callback }) => {
69
69
  const tryRewrite = (filePath, newUrl) => {
70
70
  var _a;
71
71
  if (outputFileSystem.existsSync(filePath) && callback) {
72
- newUrl = (0, import_shared.urlJoin)(assetPrefix, newUrl);
72
+ newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
73
73
  (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
74
74
  req.url = newUrl;
75
75
  return callback(req, res, (...args) => {
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(prodServer_exports);
35
35
  var import_http = require("http");
36
36
  var import_connect = __toESM(require("@rsbuild/shared/connect"));
37
37
  var import_path = require("path");
38
- var import_sirv = __toESM(require("sirv"));
38
+ var import_sirv = __toESM(require("../../compiled/sirv"));
39
39
  var import_shared = require("@rsbuild/shared");
40
40
  var import_middlewares = require("./middlewares");
41
41
  class RsbuildProdServer {
@@ -1,9 +1,8 @@
1
1
  import http from 'http';
2
- import { RequestHandler } from 'http-proxy-middleware';
3
- import { ProxyDetail, RequestHandler as Middleware, RsbuildProxyOptions } from '@rsbuild/shared';
2
+ import { RequestHandler } from '@rsbuild/shared/http-proxy-middleware';
3
+ import { type ProxyDetail, type RequestHandler as Middleware, type RsbuildProxyOptions } from '@rsbuild/shared';
4
4
  export declare function formatProxyOptions(proxyOptions: RsbuildProxyOptions): ProxyDetail[];
5
5
  export type HttpUpgradeHandler = NonNullable<RequestHandler['upgrade']>;
6
- export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions) => {
6
+ export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions, app: http.Server) => {
7
7
  middlewares: Middleware[];
8
- handleUpgrade: (server: http.Server) => void;
9
8
  };
@@ -22,7 +22,8 @@ __export(proxy_exports, {
22
22
  formatProxyOptions: () => formatProxyOptions
23
23
  });
24
24
  module.exports = __toCommonJS(proxy_exports);
25
- var import_http_proxy_middleware2 = require("http-proxy-middleware/dist/http-proxy-middleware");
25
+ var import_http_proxy_middleware = require("@rsbuild/shared/http-proxy-middleware");
26
+ var import_shared = require("@rsbuild/shared");
26
27
  function formatProxyOptions(proxyOptions) {
27
28
  var _a;
28
29
  const ret = [];
@@ -45,45 +46,42 @@ function formatProxyOptions(proxyOptions) {
45
46
  ret.push(opts);
46
47
  }
47
48
  }
48
- const handleError = (err, _req, _res, _target) => {
49
- console.error(err);
50
- };
49
+ const handleError = (err) => import_shared.logger.error(err);
51
50
  for (const opts of ret) {
52
51
  (_a = opts.onError) != null ? _a : opts.onError = handleError;
53
52
  }
54
53
  return ret;
55
54
  }
56
- const createProxyMiddleware = (proxyOptions) => {
55
+ const createProxyMiddleware = (proxyOptions, app) => {
57
56
  const formattedOptionsList = formatProxyOptions(proxyOptions);
58
- const proxies = [];
57
+ const proxyMiddlewares = [];
59
58
  const middlewares = [];
60
59
  for (const opts of formattedOptionsList) {
61
- const proxy = new import_http_proxy_middleware2.HttpProxyMiddleware(opts.context, opts);
60
+ const proxyMiddleware = (0, import_http_proxy_middleware.createProxyMiddleware)(opts.context, opts);
62
61
  const middleware = async (req, res, next) => {
63
62
  const bypassUrl = typeof opts.bypass === "function" ? opts.bypass(req, res, opts) : null;
64
- if (typeof bypassUrl === "boolean") {
63
+ if (bypassUrl === false) {
65
64
  res.statusCode = 404;
66
65
  next();
67
66
  } else if (typeof bypassUrl === "string") {
68
67
  req.url = bypassUrl;
69
68
  next();
70
69
  } else {
71
- proxy.middleware(req, res, next);
70
+ proxyMiddleware(req, res, next);
72
71
  }
73
72
  };
74
- proxies.push(proxy);
75
73
  middlewares.push(middleware);
74
+ proxyMiddlewares.push(proxyMiddleware);
76
75
  }
77
- const handleUpgrade = (server) => {
78
- for (const proxy of proxies) {
79
- const raw = proxy;
80
- if (raw.proxyOptions.ws === true && !raw.wsInternalSubscribed) {
81
- server.on("upgrade", raw.handleUpgrade);
82
- raw.wsInternalSubscribed = true;
76
+ const handleUpgrade = (req, socket, head) => {
77
+ for (const middleware of proxyMiddlewares) {
78
+ if (typeof middleware.upgrade === "function") {
79
+ middleware.upgrade(req, socket, head);
83
80
  }
84
81
  }
85
82
  };
86
- return { middlewares, handleUpgrade };
83
+ app.on("upgrade", handleUpgrade);
84
+ return { middlewares };
87
85
  };
88
86
  // Annotate the CommonJS export names for ESM import in node:
89
87
  0 && (module.exports = {
@@ -34,7 +34,7 @@ __export(restart_exports, {
34
34
  module.exports = __toCommonJS(restart_exports);
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_shared = require("@rsbuild/shared");
37
- var import_run = require("../cli/run");
37
+ var import_commands = require("../cli/commands");
38
38
  const cleaners = [];
39
39
  const registerCleaner = (cleaner) => {
40
40
  cleaners.push(cleaner);
@@ -52,9 +52,7 @@ const restartDevServer = async ({ filePath }) => {
52
52
  for (const cleaner of cleaners) {
53
53
  await cleaner();
54
54
  }
55
- const rsbuild = await (0, import_run.runCli)({
56
- isRestart: true
57
- });
55
+ const rsbuild = await (0, import_commands.init)();
58
56
  await rsbuild.startDevServer();
59
57
  };
60
58
  // Annotate the CommonJS export names for ESM import in node: