@rsbuild/core 0.1.9 → 0.2.1

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 (93) hide show
  1. package/bin/rsbuild.js +2 -0
  2. package/dist/cli/commands.js +6 -3
  3. package/dist/cli/config.d.ts +7 -1
  4. package/dist/cli/config.js +6 -3
  5. package/dist/cli/prepare.js +1 -1
  6. package/dist/createRsbuild.js +2 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +2 -0
  9. package/dist/loadEnv.d.ts +2 -2
  10. package/dist/loadEnv.js +2 -2
  11. package/dist/plugins/asset.js +2 -2
  12. package/dist/plugins/basic.d.ts +5 -0
  13. package/dist/plugins/basic.js +68 -0
  14. package/dist/plugins/html.d.ts +1 -2
  15. package/dist/plugins/html.js +8 -8
  16. package/dist/plugins/index.js +2 -3
  17. package/dist/plugins/inlineChunk.js +25 -28
  18. package/dist/plugins/networkPerformance.js +3 -11
  19. package/dist/plugins/nodeAddons.js +1 -1
  20. package/dist/plugins/preloadOrPrefetch.js +4 -10
  21. package/dist/plugins/wasm.js +1 -1
  22. package/dist/provider/core/createCompiler.js +17 -8
  23. package/dist/provider/core/createContext.d.ts +3 -3
  24. package/dist/provider/core/createContext.js +13 -27
  25. package/dist/provider/core/initConfigs.d.ts +2 -2
  26. package/dist/provider/core/initConfigs.js +4 -3
  27. package/dist/provider/core/initPlugins.js +15 -12
  28. package/dist/provider/core/inspectConfig.d.ts +2 -20
  29. package/dist/provider/core/inspectConfig.js +6 -6
  30. package/dist/provider/css-modules-typescript-pre-loader/index.js +1 -1
  31. package/dist/provider/css-modules-typescript-pre-loader/{postcss-icss-extract-plugin.js → postcssIcssExtractPlugin.js} +5 -5
  32. package/dist/provider/index.d.ts +1 -2
  33. package/dist/provider/index.js +4 -7
  34. package/dist/provider/plugins/css.js +3 -7
  35. package/dist/provider/plugins/less.js +1 -1
  36. package/dist/provider/plugins/output.js +2 -2
  37. package/dist/provider/plugins/resolve.js +0 -5
  38. package/dist/provider/plugins/server.d.ts +2 -0
  39. package/dist/provider/plugins/server.js +70 -0
  40. package/dist/provider/plugins/swc.js +1 -1
  41. package/dist/provider/provider.js +15 -1
  42. package/dist/provider/shared.d.ts +1 -2
  43. package/dist/provider/shared.js +2 -15
  44. package/dist/rspack/HtmlAppIconPlugin.d.ts +0 -3
  45. package/dist/rspack/HtmlAppIconPlugin.js +2 -2
  46. package/dist/rspack/HtmlBasicPlugin.d.ts +0 -3
  47. package/dist/rspack/HtmlBasicPlugin.js +24 -10
  48. package/dist/rspack/HtmlCrossOriginPlugin.d.ts +0 -3
  49. package/dist/rspack/HtmlCrossOriginPlugin.js +12 -2
  50. package/dist/rspack/HtmlNetworkPerformancePlugin.d.ts +1 -3
  51. package/dist/rspack/HtmlNetworkPerformancePlugin.js +13 -3
  52. package/dist/rspack/HtmlNoncePlugin.d.ts +0 -3
  53. package/dist/rspack/HtmlNoncePlugin.js +12 -2
  54. package/dist/rspack/HtmlTagsPlugin.d.ts +1 -7
  55. package/dist/rspack/HtmlTagsPlugin.js +12 -1
  56. package/dist/rspack/InlineChunkHtmlPlugin.d.ts +2 -3
  57. package/dist/rspack/InlineChunkHtmlPlugin.js +17 -3
  58. package/dist/rspack/RemoveCssSourcemapPlugin.d.ts +1 -3
  59. package/dist/rspack/RemoveCssSourcemapPlugin.js +1 -2
  60. package/dist/rspack/{HtmlPreloadOrPrefetchPlugin/index.d.ts → preload/HtmlPreloadOrPrefetchPlugin.d.ts} +3 -4
  61. package/dist/rspack/{HtmlPreloadOrPrefetchPlugin/index.js → preload/HtmlPreloadOrPrefetchPlugin.js} +17 -7
  62. package/dist/server/{dev-middleware → compiler-dev-middleware}/index.d.ts +3 -5
  63. package/dist/server/{dev-middleware → compiler-dev-middleware}/index.js +4 -7
  64. package/dist/server/{dev-middleware → compiler-dev-middleware}/socketServer.d.ts +2 -2
  65. package/dist/server/devMiddlewares.d.ts +7 -0
  66. package/dist/server/devMiddlewares.js +156 -0
  67. package/dist/server/devServer.d.ts +10 -23
  68. package/dist/server/devServer.js +77 -162
  69. package/dist/server/httpServer.d.ts +8 -0
  70. package/dist/server/httpServer.js +48 -0
  71. package/dist/server/index.d.ts +1 -1
  72. package/dist/server/index.js +2 -0
  73. package/dist/server/prodServer.d.ts +0 -5
  74. package/dist/server/prodServer.js +11 -25
  75. package/package.json +4 -4
  76. package/dist/plugins/devtool.d.ts +0 -2
  77. package/dist/plugins/devtool.js +0 -46
  78. package/dist/plugins/server.d.ts +0 -2
  79. package/dist/plugins/server.js +0 -56
  80. package/dist/provider/plugins/basic.d.ts +0 -5
  81. package/dist/provider/plugins/basic.js +0 -34
  82. /package/dist/provider/css-modules-typescript-pre-loader/{postcss-icss-extract-plugin.d.ts → postcssIcssExtractPlugin.d.ts} +0 -0
  83. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/determineAsValue.d.ts +0 -0
  84. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/determineAsValue.js +0 -0
  85. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/doesChunkBelongToHtml.d.ts +0 -0
  86. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/doesChunkBelongToHtml.js +0 -0
  87. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/extractChunks.d.ts +0 -0
  88. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/extractChunks.js +0 -0
  89. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/index.d.ts +0 -0
  90. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/index.js +0 -0
  91. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/type.d.ts +0 -0
  92. /package/dist/rspack/{HtmlPreloadOrPrefetchPlugin → preload}/helpers/type.js +0 -0
  93. /package/dist/server/{dev-middleware → compiler-dev-middleware}/socketServer.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { type PluginStore, type RspackConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
2
- import type { Context } from '../../types';
2
+ import type { Context, NormalizedConfig } from '../../types';
3
3
  export type InitConfigsOptions = {
4
4
  context: Context;
5
5
  pluginStore: PluginStore;
@@ -8,7 +8,7 @@ export type InitConfigsOptions = {
8
8
  export declare function initRsbuildConfig({
9
9
  context,
10
10
  pluginStore
11
- }: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<void>;
11
+ }: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<NormalizedConfig>;
12
12
  export declare function initConfigs({
13
13
  context,
14
14
  pluginStore,
@@ -41,7 +41,7 @@ async function initRsbuildConfig({
41
41
  pluginStore
42
42
  }) {
43
43
  if (context.normalizedConfig) {
44
- return;
44
+ return context.normalizedConfig;
45
45
  }
46
46
  await (0, import_shared.initPlugins)({
47
47
  pluginAPI: context.pluginAPI,
@@ -50,14 +50,15 @@ async function initRsbuildConfig({
50
50
  await modifyRsbuildConfig(context);
51
51
  context.normalizedConfig = (0, import_config.normalizeConfig)(context.config);
52
52
  (0, import_createContext.updateContextByNormalizedConfig)(context, context.normalizedConfig);
53
+ return context.normalizedConfig;
53
54
  }
54
55
  async function initConfigs({
55
56
  context,
56
57
  pluginStore,
57
58
  rsbuildOptions
58
59
  }) {
59
- await initRsbuildConfig({ context, pluginStore });
60
- const targets = (0, import_shared.castArray)(rsbuildOptions.target);
60
+ const normalizedConfig = await initRsbuildConfig({ context, pluginStore });
61
+ const { targets } = normalizedConfig.output;
61
62
  const rspackConfigs = await Promise.all(
62
63
  targets.map((target) => (0, import_rspackConfig.generateRspackConfig)({ target, context }))
63
64
  );
@@ -29,21 +29,24 @@ function getPluginAPI({
29
29
  }) {
30
30
  const { hooks } = context;
31
31
  const publicContext = (0, import_createContext.createPublicContext)(context);
32
- const getRsbuildConfig = () => {
33
- if (!context.normalizedConfig) {
34
- throw new Error(
35
- "Cannot access Rsbuild config until modifyRsbuildConfig is called."
36
- );
32
+ const getNormalizedConfig = () => {
33
+ if (context.normalizedConfig) {
34
+ return context.normalizedConfig;
37
35
  }
38
- return context.config;
36
+ throw new Error(
37
+ "Cannot access normalized config until modifyRsbuildConfig is called."
38
+ );
39
39
  };
40
- const getNormalizedConfig = () => {
41
- if (!context.normalizedConfig) {
42
- throw new Error(
43
- "Cannot access normalized config until modifyRsbuildConfig is called."
44
- );
40
+ const getRsbuildConfig = (type = "current") => {
41
+ switch (type) {
42
+ case "original":
43
+ return context.originalConfig;
44
+ case "current":
45
+ return context.config;
46
+ case "normalized":
47
+ return getNormalizedConfig();
45
48
  }
46
- return context.normalizedConfig;
49
+ throw new Error("`getRsbuildConfig` get an invalid type param.");
47
50
  };
48
51
  const getHTMLPaths = () => {
49
52
  return Object.keys(context.entry).reduce(
@@ -1,5 +1,5 @@
1
1
  import { type InitConfigsOptions } from './initConfigs';
2
- import { type RspackConfig, type InspectConfigOptions } from '@rsbuild/shared';
2
+ import { type RspackConfig, type InspectConfigResult, type InspectConfigOptions } from '@rsbuild/shared';
3
3
  export declare function inspectConfig({
4
4
  context,
5
5
  pluginStore,
@@ -9,22 +9,4 @@ export declare function inspectConfig({
9
9
  }: InitConfigsOptions & {
10
10
  inspectOptions?: InspectConfigOptions;
11
11
  bundlerConfigs?: RspackConfig[];
12
- }): Promise<{
13
- rsbuildConfig: string;
14
- bundlerConfigs: string[];
15
- origin: {
16
- rsbuildConfig: {
17
- pluginNames: string[];
18
- dev?: import("@rsbuild/shared").DevConfig | undefined;
19
- server?: import("@rsbuild/shared").ServerConfig | undefined;
20
- html?: import("@rsbuild/shared").HtmlConfig | undefined;
21
- tools?: import("@rsbuild/shared").ToolsConfig | undefined;
22
- source?: import("@rsbuild/shared").SourceConfig | undefined;
23
- output?: import("@rsbuild/shared").OutputConfig | undefined;
24
- security?: import("@rsbuild/shared").SecurityConfig | undefined;
25
- performance?: import("@rsbuild/shared").PerformanceConfig | undefined;
26
- plugins?: import("@rsbuild/shared").RsbuildPlugin[] | undefined;
27
- };
28
- bundlerConfigs: RspackConfig[];
29
- };
30
- }>;
12
+ }): Promise<InspectConfigResult<'rspack'>>;
@@ -36,15 +36,15 @@ async function inspectConfig({
36
36
  } else if (!process.env.NODE_ENV) {
37
37
  process.env.NODE_ENV = "development";
38
38
  }
39
- const rsbuildDebugConfig = {
40
- ...context.config,
41
- pluginNames: pluginStore.plugins.map((p) => p.name)
42
- };
43
39
  const rspackConfigs = bundlerConfigs || (await (0, import_initConfigs.initConfigs)({
44
40
  context,
45
41
  pluginStore,
46
42
  rsbuildOptions
47
43
  })).rspackConfigs;
44
+ const rsbuildDebugConfig = {
45
+ ...context.normalizedConfig,
46
+ pluginNames: pluginStore.plugins.map((p) => p.name)
47
+ };
48
48
  const rawRsbuildConfig = await (0, import_shared.stringifyConfig)(
49
49
  rsbuildDebugConfig,
50
50
  inspectOptions.verbose
@@ -60,13 +60,13 @@ async function inspectConfig({
60
60
  }
61
61
  if (inspectOptions.writeToDisk) {
62
62
  await (0, import_shared.outputInspectConfigFiles)({
63
- rsbuildConfig: rawRsbuildConfig,
63
+ rsbuildConfig: context.normalizedConfig,
64
+ rawRsbuildConfig,
64
65
  bundlerConfigs: rawBundlerConfigs,
65
66
  inspectOptions: {
66
67
  ...inspectOptions,
67
68
  outputPath
68
69
  },
69
- rsbuildOptions,
70
70
  configType: "rspack"
71
71
  });
72
72
  }
@@ -39,7 +39,7 @@ async function processCss(inputSource, {
39
39
  const { default: postcss } = await Promise.resolve().then(() => __toESM(require("postcss")));
40
40
  const { default: localByDefault } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/postcss-modules-local-by-default")));
41
41
  const { default: modulesScope } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/postcss-modules-scope")));
42
- const { default: postcssICSSExtractPlugin } = await Promise.resolve().then(() => __toESM(require("./postcss-icss-extract-plugin")));
42
+ const { default: postcssICSSExtractPlugin } = await Promise.resolve().then(() => __toESM(require("./postcssIcssExtractPlugin")));
43
43
  const { default: extractImports } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/postcss-modules-extract-imports")));
44
44
  const { default: modulesValues } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/postcss-modules-values")));
45
45
  const parserOptions = {
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var postcss_icss_extract_plugin_exports = {};
20
- __export(postcss_icss_extract_plugin_exports, {
21
- default: () => postcss_icss_extract_plugin_default
19
+ var postcssIcssExtractPlugin_exports = {};
20
+ __export(postcssIcssExtractPlugin_exports, {
21
+ default: () => postcssIcssExtractPlugin_default
22
22
  });
23
- module.exports = __toCommonJS(postcss_icss_extract_plugin_exports);
23
+ module.exports = __toCommonJS(postcssIcssExtractPlugin_exports);
24
24
  var import_icss_utils = require("@rsbuild/shared/icss-utils");
25
25
  var import_shared = require("@rsbuild/shared");
26
26
  const dashesCamelCase = (str) => str.replace(/-+(\w)/g, (_match, firstLetter) => firstLetter.toUpperCase());
@@ -64,4 +64,4 @@ const plugin = (options) => {
64
64
  };
65
65
  };
66
66
  plugin.postcss = true;
67
- var postcss_icss_extract_plugin_default = plugin;
67
+ var postcssIcssExtractPlugin_default = plugin;
@@ -1,7 +1,6 @@
1
- export { getRspackVersion } from './shared';
2
1
  export { rspackProvider } from './provider';
3
2
  export type { Rspack, RspackConfig } from '@rsbuild/shared';
4
- export { createPublicContext, createContextByConfig } from './core/createContext';
3
+ export { createContext, createPublicContext } from './core/createContext';
5
4
  export { initPlugins } from '@rsbuild/shared';
6
5
  export { initHooks, type Hooks } from './core/initHooks';
7
6
  export { withDefaultConfig } from './config';
@@ -20,21 +20,19 @@ var provider_exports = {};
20
20
  __export(provider_exports, {
21
21
  applyBaseCSSRule: () => import_css.applyBaseCSSRule,
22
22
  applyCSSModuleRule: () => import_css.applyCSSModuleRule,
23
- createContextByConfig: () => import_createContext.createContextByConfig,
23
+ createContext: () => import_createContext.createContext,
24
24
  createPublicContext: () => import_createContext.createPublicContext,
25
25
  getPluginAPI: () => import_initPlugins.getPluginAPI,
26
- getRspackVersion: () => import_shared.getRspackVersion,
27
26
  initHooks: () => import_initHooks.initHooks,
28
- initPlugins: () => import_shared2.initPlugins,
27
+ initPlugins: () => import_shared.initPlugins,
29
28
  initRsbuildConfig: () => import_initConfigs.initRsbuildConfig,
30
29
  rspackProvider: () => import_provider.rspackProvider,
31
30
  withDefaultConfig: () => import_config.withDefaultConfig
32
31
  });
33
32
  module.exports = __toCommonJS(provider_exports);
34
- var import_shared = require("./shared");
35
33
  var import_provider = require("./provider");
36
34
  var import_createContext = require("./core/createContext");
37
- var import_shared2 = require("@rsbuild/shared");
35
+ var import_shared = require("@rsbuild/shared");
38
36
  var import_initHooks = require("./core/initHooks");
39
37
  var import_config = require("./config");
40
38
  var import_initConfigs = require("./core/initConfigs");
@@ -44,10 +42,9 @@ var import_css = require("./plugins/css");
44
42
  0 && (module.exports = {
45
43
  applyBaseCSSRule,
46
44
  applyCSSModuleRule,
47
- createContextByConfig,
45
+ createContext,
48
46
  createPublicContext,
49
47
  getPluginAPI,
50
- getRspackVersion,
51
48
  initHooks,
52
49
  initPlugins,
53
50
  initRsbuildConfig,
@@ -36,7 +36,7 @@ __export(css_exports, {
36
36
  module.exports = __toCommonJS(css_exports);
37
37
  var import_path = __toESM(require("path"));
38
38
  var import_shared = require("@rsbuild/shared");
39
- const enableNativeCss = (config) => !config.output.disableCssExtract;
39
+ const enableNativeCss = (config) => !config.output.injectStyles;
40
40
  async function applyBaseCSSRule({
41
41
  rule,
42
42
  config,
@@ -44,7 +44,6 @@ async function applyBaseCSSRule({
44
44
  utils: { target, isProd, isServer, isWebWorker, CHAIN_ID },
45
45
  importLoaders = 1
46
46
  }) {
47
- const enableSourceMap = (0, import_shared.isUseCssSourceMap)(config);
48
47
  const enableCSSModuleTS = Boolean(config.output.enableCssModuleTSDeclaration);
49
48
  const browserslist = await (0, import_shared.getBrowserslistWithDefault)(
50
49
  context.rootPath,
@@ -55,7 +54,6 @@ async function applyBaseCSSRule({
55
54
  const localIdentName = (0, import_shared.getCssModuleLocalIdentName)(config, isProd);
56
55
  const cssLoaderOptions = (0, import_shared.getCssLoaderOptions)({
57
56
  config,
58
- enableSourceMap,
59
57
  importLoaders,
60
58
  isServer,
61
59
  isWebWorker,
@@ -99,7 +97,6 @@ async function applyBaseCSSRule({
99
97
  }
100
98
  if (!isServer && !isWebWorker) {
101
99
  const postcssLoaderOptions = (0, import_shared.getPostcssConfig)({
102
- enableSourceMap,
103
100
  browserslist,
104
101
  config
105
102
  });
@@ -154,11 +151,10 @@ const pluginCss = () => {
154
151
  config,
155
152
  context: api.context
156
153
  });
157
- const enableSourceMap = (0, import_shared.isUseCssSourceMap)(config);
158
154
  const enableExtractCSS = (0, import_shared.isUseCssExtract)(config, utils.target);
159
- if (!enableSourceMap && enableExtractCSS) {
155
+ if (!config.output.sourceMap.css && enableExtractCSS) {
160
156
  const { RemoveCssSourcemapPlugin } = await Promise.resolve().then(() => __toESM(require("../../rspack/RemoveCssSourcemapPlugin")));
161
- chain.plugin("remove-css-sourcemap").use(RemoveCssSourcemapPlugin, [utils.HtmlPlugin]);
157
+ chain.plugin("remove-css-sourcemap").use(RemoveCssSourcemapPlugin, []);
162
158
  }
163
159
  });
164
160
  api.modifyRspackConfig(
@@ -49,7 +49,7 @@ function pluginLess() {
49
49
  });
50
50
  const { excludes, options } = (0, import_shared.getLessLoaderOptions)(
51
51
  config.tools.less,
52
- (0, import_shared.isUseCssSourceMap)(config)
52
+ config.output.sourceMap.css
53
53
  );
54
54
  excludes.forEach((item) => {
55
55
  rule.exclude.add(item);
@@ -48,8 +48,8 @@ const pluginOutput = () => ({
48
48
  });
49
49
  api.modifyRspackConfig(async (rspackConfig, { isProd }) => {
50
50
  const config = api.getNormalizedConfig();
51
- const cssPath = (0, import_shared.getDistPath)(config.output, "css");
52
- const cssFilename = (0, import_shared.getFilename)(config.output, "css", isProd);
51
+ const cssPath = (0, import_shared.getDistPath)(config, "css");
52
+ const cssFilename = (0, import_shared.getFilename)(config, "css", isProd);
53
53
  rspackConfig.output || (rspackConfig.output = {});
54
54
  rspackConfig.output.cssFilename = import_path.posix.join(cssPath, cssFilename);
55
55
  rspackConfig.output.cssChunkFilename = import_path.posix.join(
@@ -26,11 +26,6 @@ const pluginResolve = () => ({
26
26
  name: "rsbuild:resolve",
27
27
  setup(api) {
28
28
  (0, import_shared.applyResolvePlugin)(api);
29
- api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
30
- if (chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI)) {
31
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).resolve.set("fullySpecified", false);
32
- }
33
- });
34
29
  api.modifyRspackConfig(async (rspackConfig, { isServer }) => {
35
30
  const isTsProject = Boolean(api.context.tsconfigPath);
36
31
  const config = api.getNormalizedConfig();
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '../../types';
2
+ export declare const pluginServer: () => RsbuildPlugin;
@@ -0,0 +1,70 @@
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 server_exports = {};
30
+ __export(server_exports, {
31
+ pluginServer: () => pluginServer
32
+ });
33
+ module.exports = __toCommonJS(server_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = require("path");
36
+ const pluginServer = () => ({
37
+ name: "rsbuild:server",
38
+ setup(api) {
39
+ api.modifyBundlerChain(async (chain, { isProd }) => {
40
+ const config = api.getNormalizedConfig();
41
+ if (isProd && config.server?.publicDir) {
42
+ const { name, copyOnBuild } = config.server?.publicDir;
43
+ if (!copyOnBuild || !name) {
44
+ return;
45
+ }
46
+ const publicDir = (0, import_path.isAbsolute)(name) ? name : (0, import_path.join)(api.context.rootPath, name);
47
+ const publicPattern = [
48
+ {
49
+ from: publicDir,
50
+ to: "",
51
+ noErrorOnMissing: true
52
+ }
53
+ ];
54
+ if (!import_fs.default.existsSync(publicDir)) {
55
+ return;
56
+ }
57
+ const { CopyRspackPlugin } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
58
+ chain.plugin("public-dir").use(CopyRspackPlugin, [
59
+ {
60
+ patterns: publicPattern
61
+ }
62
+ ]);
63
+ }
64
+ });
65
+ }
66
+ });
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ pluginServer
70
+ });
@@ -54,7 +54,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
54
54
  env: {
55
55
  targets: await (0, import_shared.getBrowserslistWithDefault)(rootPath, config, target)
56
56
  },
57
- sourceMaps: (0, import_shared.isUseJsSourceMap)(config),
57
+ sourceMaps: Boolean((0, import_shared.getJsSourceMap)(config)),
58
58
  exclude: [],
59
59
  inlineSourcesContent: true
60
60
  };
@@ -41,7 +41,11 @@ function rspackProvider({
41
41
  }) {
42
42
  const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(originalRsbuildConfig);
43
43
  return async ({ pluginStore, rsbuildOptions, plugins }) => {
44
- const context = await (0, import_createContext.createContext)(rsbuildOptions, rsbuildConfig);
44
+ const context = await (0, import_createContext.createContext)(
45
+ rsbuildOptions,
46
+ rsbuildConfig,
47
+ "rspack"
48
+ );
45
49
  const pluginAPI = (0, import_initPlugins.getPluginAPI)({ context, pluginStore });
46
50
  context.pluginAPI = pluginAPI;
47
51
  return {
@@ -63,6 +67,16 @@ function rspackProvider({
63
67
  rspackConfigs
64
68
  });
65
69
  },
70
+ async createDevServer(options) {
71
+ const { createDevServer } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
72
+ const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
73
+ await (0, import_initConfigs.initRsbuildConfig)({ context, pluginStore });
74
+ return createDevServer(
75
+ { context, pluginStore, rsbuildOptions },
76
+ createDevMiddleware,
77
+ options
78
+ );
79
+ },
66
80
  async startDevServer(options) {
67
81
  const { startDevServer } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
68
82
  const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
@@ -1,7 +1,6 @@
1
1
  import { RsbuildPlugin } from '../types';
2
- import { Plugins } from '@rsbuild/shared';
2
+ import { type Plugins } from '@rsbuild/shared';
3
3
  export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
4
- export declare const getRspackVersion: () => Promise<string>;
5
4
  export declare const rspackMinVersion = "0.4.0";
6
5
  export declare const isSatisfyRspackVersion: (version: string) => Promise<boolean>;
7
6
  export declare const getCompiledPath: (packageName: string) => string;
@@ -31,7 +31,6 @@ __export(shared_exports, {
31
31
  BUILTIN_LOADER: () => BUILTIN_LOADER,
32
32
  applyDefaultPlugins: () => applyDefaultPlugins,
33
33
  getCompiledPath: () => getCompiledPath,
34
- getRspackVersion: () => getRspackVersion,
35
34
  isSatisfyRspackVersion: () => isSatisfyRspackVersion,
36
35
  rspackMinVersion: () => rspackMinVersion
37
36
  });
@@ -42,12 +41,11 @@ var import_shared2 = require("@rsbuild/shared");
42
41
  var import_shared3 = require("@rsbuild/shared");
43
42
  const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
44
43
  Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
45
- Promise.resolve().then(() => __toESM(require("./plugins/basic"))).then((m) => m.pluginBasic()),
44
+ plugins.basic(),
46
45
  plugins.entry(),
47
46
  // plugins.cache(),
48
47
  plugins.target(),
49
48
  Promise.resolve().then(() => __toESM(require("./plugins/output"))).then((m) => m.pluginOutput()),
50
- plugins.devtool(),
51
49
  Promise.resolve().then(() => __toESM(require("./plugins/resolve"))).then((m) => m.pluginResolve()),
52
50
  plugins.fileSize(),
53
51
  // cleanOutput plugin should before the html plugin
@@ -75,19 +73,9 @@ const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
75
73
  plugins.networkPerformance(),
76
74
  plugins.preloadOrPrefetch(),
77
75
  plugins.performance(),
78
- plugins.server(),
76
+ Promise.resolve().then(() => __toESM(require("./plugins/server"))).then((m) => m.pluginServer()),
79
77
  Promise.resolve().then(() => __toESM(require("./plugins/rspackProfile"))).then((m) => m.pluginRspackProfile())
80
78
  ]);
81
- const getRspackVersion = async () => {
82
- try {
83
- const core = require.resolve("@rspack/core");
84
- const pkg = await Promise.resolve().then(() => __toESM(require((0, import_path.join)(core, "../../package.json"))));
85
- return pkg?.version;
86
- } catch (err) {
87
- console.error(err);
88
- return "";
89
- }
90
- };
91
79
  const rspackMinVersion = "0.4.0";
92
80
  const compareSemver = (version1, version2) => {
93
81
  const parts1 = version1.split(".").map(Number);
@@ -127,7 +115,6 @@ const BUILTIN_LOADER = "builtin:";
127
115
  BUILTIN_LOADER,
128
116
  applyDefaultPlugins,
129
117
  getCompiledPath,
130
- getRspackVersion,
131
118
  isSatisfyRspackVersion,
132
119
  rspackMinVersion
133
120
  });
@@ -1,15 +1,12 @@
1
- import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
1
  import type { Compiler } from '@rspack/core';
3
2
  type AppIconOptions = {
4
3
  distDir: string;
5
4
  iconPath: string;
6
- HtmlPlugin: typeof HtmlWebpackPlugin;
7
5
  };
8
6
  export declare class HtmlAppIconPlugin {
9
7
  readonly name: string;
10
8
  readonly distDir: string;
11
9
  readonly iconPath: string;
12
- readonly HtmlPlugin: typeof HtmlWebpackPlugin;
13
10
  constructor(options: AppIconOptions);
14
11
  apply(compiler: Compiler): void;
15
12
  }
@@ -33,6 +33,7 @@ __export(HtmlAppIconPlugin_exports, {
33
33
  module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
34
34
  var import_fs = __toESM(require("fs"));
35
35
  var import_path = __toESM(require("path"));
36
+ var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
36
37
  var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
37
38
  var import_shared = require("@rsbuild/shared");
38
39
  class HtmlAppIconPlugin {
@@ -40,7 +41,6 @@ class HtmlAppIconPlugin {
40
41
  this.name = "HtmlAppIconPlugin";
41
42
  this.distDir = options.distDir;
42
43
  this.iconPath = options.iconPath;
43
- this.HtmlPlugin = options.HtmlPlugin;
44
44
  }
45
45
  apply(compiler) {
46
46
  if (!import_fs.default.existsSync(this.iconPath)) {
@@ -53,7 +53,7 @@ class HtmlAppIconPlugin {
53
53
  import_path.default.basename(this.iconPath)
54
54
  );
55
55
  compiler.hooks.compilation.tap(this.name, (compilation) => {
56
- this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
56
+ import_html_webpack_plugin.default.getHooks(compilation).alterAssetTagGroups.tap(
57
57
  this.name,
58
58
  (data) => {
59
59
  const { publicPath } = compiler.options.output;
@@ -1,4 +1,3 @@
1
- import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
1
  import type { Compiler } from '@rspack/core';
3
2
  export type HtmlInfo = {
4
3
  title?: string;
@@ -7,13 +6,11 @@ export type HtmlInfo = {
7
6
  };
8
7
  export type HtmlBasicPluginOptions = {
9
8
  info: Record<string, HtmlInfo>;
10
- HtmlPlugin: typeof HtmlWebpackPlugin;
11
9
  };
12
10
  export declare const hasTitle: (html?: string) => boolean;
13
11
  export declare class HtmlBasicPlugin {
14
12
  readonly name: string;
15
13
  readonly options: HtmlBasicPluginOptions;
16
- readonly HtmlPlugin: typeof HtmlWebpackPlugin;
17
14
  constructor(options: HtmlBasicPluginOptions);
18
15
  apply(compiler: Compiler): void;
19
16
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var HtmlBasicPlugin_exports = {};
20
30
  __export(HtmlBasicPlugin_exports, {
@@ -22,16 +32,16 @@ __export(HtmlBasicPlugin_exports, {
22
32
  hasTitle: () => hasTitle
23
33
  });
24
34
  module.exports = __toCommonJS(HtmlBasicPlugin_exports);
35
+ var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
25
36
  const hasTitle = (html) => html ? /<title/i.test(html) && /<\/title/i.test(html) : false;
26
37
  class HtmlBasicPlugin {
27
38
  constructor(options) {
28
39
  this.name = "HtmlBasicPlugin";
29
40
  this.options = options;
30
- this.HtmlPlugin = options.HtmlPlugin;
31
41
  }
32
42
  apply(compiler) {
33
- const addTitleTag = (headTags, outputName) => {
34
- const { title } = this.options.info[outputName];
43
+ const addTitleTag = (headTags, entryName) => {
44
+ const { title } = this.options.info[entryName];
35
45
  if (title) {
36
46
  headTags.unshift({
37
47
  tagName: "title",
@@ -42,8 +52,8 @@ class HtmlBasicPlugin {
42
52
  });
43
53
  }
44
54
  };
45
- const addFavicon = (headTags, outputName) => {
46
- const { favicon } = this.options.info[outputName];
55
+ const addFavicon = (headTags, entryName) => {
56
+ const { favicon } = this.options.info[entryName];
47
57
  if (favicon) {
48
58
  headTags.unshift({
49
59
  tagName: "link",
@@ -57,15 +67,19 @@ class HtmlBasicPlugin {
57
67
  }
58
68
  };
59
69
  compiler.hooks.compilation.tap(this.name, (compilation) => {
60
- this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
70
+ import_html_webpack_plugin.default.getHooks(compilation).alterAssetTagGroups.tap(
61
71
  this.name,
62
72
  (data) => {
63
- const { headTags, outputName } = data;
64
- const { templateContent } = this.options.info[outputName];
73
+ const entryName = data.plugin.options?.entryName;
74
+ if (!entryName) {
75
+ return data;
76
+ }
77
+ const { headTags } = data;
78
+ const { templateContent } = this.options.info[entryName];
65
79
  if (!hasTitle(templateContent)) {
66
- addTitleTag(headTags, outputName);
80
+ addTitleTag(headTags, entryName);
67
81
  }
68
- addFavicon(headTags, outputName);
82
+ addFavicon(headTags, entryName);
69
83
  return data;
70
84
  }
71
85
  );
@@ -1,14 +1,11 @@
1
- import type HtmlWebpackPlugin from 'html-webpack-plugin';
2
1
  import type { CrossOrigin } from '@rsbuild/shared';
3
2
  import type { Compiler, RspackPluginInstance } from '@rspack/core';
4
3
  type CrossOriginOptions = {
5
4
  crossOrigin: CrossOrigin;
6
- HtmlPlugin: typeof HtmlWebpackPlugin;
7
5
  };
8
6
  export declare class HtmlCrossOriginPlugin implements RspackPluginInstance {
9
7
  readonly name: string;
10
8
  readonly crossOrigin: CrossOrigin;
11
- readonly HtmlPlugin: typeof HtmlWebpackPlugin;
12
9
  constructor(options: CrossOriginOptions);
13
10
  apply(compiler: Compiler): void;
14
11
  }