@rsbuild/webpack 0.0.12 → 0.0.14

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 (65) hide show
  1. package/dist/config/defaults.js +1 -4
  2. package/dist/core/createContext.js +0 -4
  3. package/dist/core/initConfigs.js +1 -2
  4. package/dist/core/startDevServer.js +6 -1
  5. package/dist/core/webpackConfig.js +7 -8
  6. package/dist/plugins/babel.d.ts +1 -1
  7. package/dist/plugins/minimize.js +5 -2
  8. package/dist/plugins/tsLoader.js +2 -3
  9. package/dist/shared/plugin.js +0 -2
  10. package/dist/types/config/index.d.ts +6 -14
  11. package/dist/types/config/index.js +0 -10
  12. package/dist/types/config/security.d.ts +3 -3
  13. package/dist/types/config/source.d.ts +3 -13
  14. package/dist/types/config/tools.d.ts +8 -11
  15. package/dist/types/context.d.ts +0 -2
  16. package/dist/types/hooks.d.ts +7 -2
  17. package/dist/types/thirdParty/index.d.ts +0 -1
  18. package/dist/webpackPlugins/ModuleScopePlugin.js +3 -4
  19. package/dist/webpackPlugins/ProgressPlugin/helpers/bar.js +9 -10
  20. package/dist/webpackPlugins/ProgressPlugin/helpers/type.d.ts +5 -7
  21. package/package.json +8 -7
  22. package/compiled/webpack-manifest-plugin/index.js +0 -1
  23. package/compiled/webpack-manifest-plugin/license +0 -21
  24. package/compiled/webpack-manifest-plugin/package.json +0 -1
  25. package/compiled/webpack-manifest-plugin/types/helpers.d.ts +0 -23
  26. package/compiled/webpack-manifest-plugin/types/hooks.d.ts +0 -24
  27. package/compiled/webpack-manifest-plugin/types/index.d.ts +0 -30
  28. package/dist/config/validate/dev.d.ts +0 -3
  29. package/dist/config/validate/dev.js +0 -29
  30. package/dist/config/validate/experiments.d.ts +0 -3
  31. package/dist/config/validate/experiments.js +0 -29
  32. package/dist/config/validate/html.d.ts +0 -3
  33. package/dist/config/validate/html.js +0 -29
  34. package/dist/config/validate/index.d.ts +0 -4
  35. package/dist/config/validate/index.js +0 -52
  36. package/dist/config/validate/output.d.ts +0 -3
  37. package/dist/config/validate/output.js +0 -37
  38. package/dist/config/validate/performance.d.ts +0 -3
  39. package/dist/config/validate/performance.js +0 -47
  40. package/dist/config/validate/security.d.ts +0 -4
  41. package/dist/config/validate/security.js +0 -38
  42. package/dist/config/validate/source.d.ts +0 -3
  43. package/dist/config/validate/source.js +0 -34
  44. package/dist/config/validate/tools.d.ts +0 -3
  45. package/dist/config/validate/tools.js +0 -48
  46. package/dist/exports/HtmlWebpackPlugin.d.ts +0 -2
  47. package/dist/exports/HtmlWebpackPlugin.js +0 -35
  48. package/dist/plugins/manifest.d.ts +0 -2
  49. package/dist/plugins/manifest.js +0 -58
  50. package/dist/plugins/pug.d.ts +0 -2
  51. package/dist/plugins/pug.js +0 -52
  52. package/dist/types/config/dev.d.ts +0 -3
  53. package/dist/types/config/dev.js +0 -16
  54. package/dist/types/config/experiments.d.ts +0 -3
  55. package/dist/types/config/experiments.js +0 -16
  56. package/dist/types/config/html.d.ts +0 -3
  57. package/dist/types/config/html.js +0 -16
  58. package/dist/types/config/output.d.ts +0 -9
  59. package/dist/types/config/output.js +0 -16
  60. package/dist/types/config/performance.d.ts +0 -3
  61. package/dist/types/config/performance.js +0 -16
  62. package/dist/types/thirdParty/CopyWebpackPlugin.d.ts +0 -62
  63. package/dist/types/thirdParty/CopyWebpackPlugin.js +0 -16
  64. package/dist/webpackLoaders/pugLoader.d.ts +0 -3
  65. package/dist/webpackLoaders/pugLoader.js +0 -44
@@ -33,10 +33,7 @@ const createDefaultConfig = () => ({
33
33
  pluginOptions: {}
34
34
  }
35
35
  },
36
- source: {
37
- ...(0, import_shared.getDefaultSourceConfig)(),
38
- define: {}
39
- },
36
+ source: (0, import_shared.getDefaultSourceConfig)(),
40
37
  output: (0, import_shared.getDefaultOutputConfig)(),
41
38
  security: {
42
39
  ...(0, import_shared.getDefaultSecurityConfig)(),
@@ -25,7 +25,6 @@ module.exports = __toCommonJS(createContext_exports);
25
25
  var import_path = require("path");
26
26
  var import_shared = require("@rsbuild/shared");
27
27
  var import_initHooks = require("./initHooks");
28
- var import_validate = require("../config/validate");
29
28
  var import_defaults = require("../config/defaults");
30
29
  function createPrimaryContext(options, userRsbuildConfig) {
31
30
  const rsbuildConfig = (0, import_defaults.withDefaultConfig)(userRsbuildConfig);
@@ -34,18 +33,15 @@ function createPrimaryContext(options, userRsbuildConfig) {
34
33
  rsbuildConfig.output,
35
34
  "webpack"
36
35
  );
37
- const configValidatingTask = Promise.resolve();
38
36
  return {
39
37
  ...context,
40
38
  hooks: (0, import_initHooks.initHooks)(),
41
- configValidatingTask,
42
39
  config: { ...rsbuildConfig },
43
40
  originalConfig: userRsbuildConfig
44
41
  };
45
42
  }
46
43
  async function createContext(options, rsbuildConfig) {
47
44
  (0, import_shared.debug)("create context");
48
- await (0, import_validate.validateRsbuildConfig)(rsbuildConfig);
49
45
  const ctx = createPrimaryContext(options, rsbuildConfig);
50
46
  const tsconfigPath = (0, import_path.join)(ctx.rootPath, import_shared.TS_CONFIG_FILE);
51
47
  if (await (0, import_shared.isFileExists)(tsconfigPath)) {
@@ -39,14 +39,13 @@ async function initConfigs({
39
39
  pluginStore,
40
40
  rsbuildOptions
41
41
  }) {
42
- await context.configValidatingTask;
43
42
  await (0, import_shared.initPlugins)({
44
43
  pluginAPI: context.pluginAPI,
45
44
  pluginStore
46
45
  });
47
46
  await modifyRsbuildConfig(context);
48
47
  context.normalizedConfig = (0, import_normalize.normalizeConfig)(context.config);
49
- const targets = (0, import_shared.ensureArray)(rsbuildOptions.target);
48
+ const targets = (0, import_shared.castArray)(rsbuildOptions.target);
50
49
  const webpackConfigs = await Promise.all(
51
50
  targets.map((target) => (0, import_webpackConfig.generateWebpackConfig)({ target, context }))
52
51
  );
@@ -66,7 +66,12 @@ async function createDevServer(options, port, serverOptions, customCompiler) {
66
66
  return server;
67
67
  }
68
68
  async function startDevServer(options, startDevServerOptions = {}) {
69
- return (0, import_shared.startDevServer)(options, createDevServer, startDevServerOptions);
69
+ return (0, import_shared.startDevServer)(
70
+ options,
71
+ // @ts-expect-error compiler type mismatch
72
+ createDevServer,
73
+ startDevServerOptions
74
+ );
70
75
  }
71
76
  // Annotate the CommonJS export names for ESM import in node:
72
77
  0 && (module.exports = {
@@ -32,7 +32,6 @@ __export(webpackConfig_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(webpackConfig_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
- var import_lodash = require("lodash");
36
35
  var import_shared2 = require("../shared");
37
36
  async function modifyWebpackChain(context, utils, chain) {
38
37
  var _a;
@@ -42,7 +41,7 @@ async function modifyWebpackChain(context, utils, chain) {
42
41
  utils
43
42
  );
44
43
  if ((_a = context.config.tools) == null ? void 0 : _a.webpackChain) {
45
- (0, import_shared.ensureArray)(context.config.tools.webpackChain).forEach((item) => {
44
+ (0, import_shared.castArray)(context.config.tools.webpackChain).forEach((item) => {
46
45
  item(modifiedChain, utils);
47
46
  });
48
47
  }
@@ -69,7 +68,7 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
69
68
  }
70
69
  async function getChainUtils(target) {
71
70
  const { default: webpack } = await Promise.resolve().then(() => __toESM(require("webpack")));
72
- const { default: HtmlWebpackPlugin } = await Promise.resolve().then(() => __toESM(require("html-webpack-plugin")));
71
+ const { default: HtmlPlugin } = await Promise.resolve().then(() => __toESM(require("html-webpack-plugin")));
73
72
  const nodeEnv = process.env.NODE_ENV;
74
73
  const nameMap = {
75
74
  web: "client",
@@ -88,8 +87,8 @@ async function getChainUtils(target) {
88
87
  isWebWorker: target === "web-worker",
89
88
  CHAIN_ID: import_shared.CHAIN_ID,
90
89
  getCompiledPath: import_shared2.getCompiledPath,
91
- HtmlWebpackPlugin,
92
- HtmlPlugin: HtmlWebpackPlugin
90
+ HtmlPlugin,
91
+ HtmlWebpackPlugin: HtmlPlugin
93
92
  };
94
93
  }
95
94
  async function getConfigUtils(config, chainUtils) {
@@ -98,7 +97,7 @@ async function getConfigUtils(config, chainUtils) {
98
97
  ...chainUtils,
99
98
  mergeConfig: merge,
100
99
  addRules(rules) {
101
- const ruleArr = (0, import_lodash.castArray)(rules);
100
+ const ruleArr = (0, import_shared.castArray)(rules);
102
101
  if (!config.module) {
103
102
  config.module = {};
104
103
  }
@@ -108,14 +107,14 @@ async function getConfigUtils(config, chainUtils) {
108
107
  config.module.rules.unshift(...ruleArr);
109
108
  },
110
109
  prependPlugins(plugins) {
111
- const pluginArr = (0, import_lodash.castArray)(plugins);
110
+ const pluginArr = (0, import_shared.castArray)(plugins);
112
111
  if (!config.plugins) {
113
112
  config.plugins = [];
114
113
  }
115
114
  config.plugins.unshift(...pluginArr);
116
115
  },
117
116
  appendPlugins(plugins) {
118
- const pluginArr = (0, import_lodash.castArray)(plugins);
117
+ const pluginArr = (0, import_shared.castArray)(plugins);
119
118
  if (!config.plugins) {
120
119
  config.plugins = [];
121
120
  }
@@ -1,3 +1,3 @@
1
1
  import type { RsbuildPlugin, NormalizedConfig } from '../types';
2
- export declare const getUseBuiltIns: (config: NormalizedConfig) => false | "entry" | "usage";
2
+ export declare const getUseBuiltIns: (config: NormalizedConfig) => false | "usage" | "entry";
3
3
  export declare const pluginBabel: () => RsbuildPlugin;
@@ -32,6 +32,7 @@ __export(minimize_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(minimize_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
+ var import_plugin_css_minimizer = require("@rsbuild/plugin-css-minimizer");
35
36
  async function applyJSMinimizer(chain, config) {
36
37
  const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
37
38
  const finalOptions = await (0, import_shared.getJSMinifyOptions)(config);
@@ -44,13 +45,15 @@ async function applyJSMinimizer(chain, config) {
44
45
  const pluginMinimize = () => ({
45
46
  name: "plugin-minimize",
46
47
  setup(api) {
47
- api.modifyBundlerChain(async (chain, { isProd }) => {
48
+ api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID: CHAIN_ID2 }) => {
48
49
  const config = api.getNormalizedConfig();
49
50
  const isMinimize = isProd && !config.output.disableMinimize;
50
51
  chain.optimization.minimize(isMinimize);
51
52
  if (isMinimize) {
52
53
  await applyJSMinimizer(chain, config);
53
- await (0, import_shared.applyCSSMinimizer)(chain, config);
54
+ await (0, import_plugin_css_minimizer.applyCSSMinimizer)(chain, CHAIN_ID2, {
55
+ pluginOptions: config.tools.minifyCss
56
+ });
54
57
  }
55
58
  });
56
59
  }
@@ -33,7 +33,6 @@ __export(tsLoader_exports, {
33
33
  module.exports = __toCommonJS(tsLoader_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  var import_plugin_babel = require("@rsbuild/plugin-babel");
36
- var import_lodash = __toESM(require("lodash"));
37
36
  var import_web = require("@rsbuild/babel-preset/web");
38
37
  var import_babel = require("./babel");
39
38
  const pluginTsLoader = () => {
@@ -67,10 +66,10 @@ const pluginTsLoader = () => {
67
66
  const excludes = [];
68
67
  const tsLoaderUtils = {
69
68
  addIncludes(items) {
70
- includes.push(...import_lodash.default.castArray(items));
69
+ includes.push(...(0, import_shared.castArray)(items));
71
70
  },
72
71
  addExcludes(items) {
73
- excludes.push(...import_lodash.default.castArray(items));
72
+ excludes.push(...(0, import_shared.castArray)(items));
74
73
  }
75
74
  };
76
75
  const tsLoaderOptions = (0, import_shared.mergeChainedOptions)(
@@ -66,7 +66,6 @@ const applyDefaultPlugins = (plugins) => {
66
66
  (_b = plugins.cleanOutput) == null ? void 0 : _b.call(plugins),
67
67
  Promise.resolve().then(() => __toESM(require("../plugins/hmr"))).then((m) => m.pluginHMR()),
68
68
  plugins.svg(),
69
- Promise.resolve().then(() => __toESM(require("../plugins/pug"))).then((m) => m.pluginPug()),
70
69
  Promise.resolve().then(() => __toESM(require("../plugins/copy"))).then((m) => m.pluginCopy()),
71
70
  Promise.resolve().then(() => __toESM(require("../plugins/react"))).then((m) => m.pluginReactWebpack()),
72
71
  plugins.font(),
@@ -79,7 +78,6 @@ const applyDefaultPlugins = (plugins) => {
79
78
  plugins.define(),
80
79
  Promise.resolve().then(() => __toESM(require("../plugins/progress"))).then((m) => m.pluginProgress()),
81
80
  Promise.resolve().then(() => __toESM(require("../plugins/minimize"))).then((m) => m.pluginMinimize()),
82
- Promise.resolve().then(() => __toESM(require("../plugins/manifest"))).then((m) => m.pluginManifest()),
83
81
  Promise.resolve().then(() => __toESM(require("../plugins/moduleScopes"))).then((m) => m.pluginModuleScopes()),
84
82
  Promise.resolve().then(() => __toESM(require("../plugins/tsLoader"))).then((m) => m.pluginTsLoader()),
85
83
  Promise.resolve().then(() => __toESM(require("../plugins/babel"))).then((m) => m.pluginBabel()),
@@ -1,12 +1,12 @@
1
1
  import type { DeepReadonly } from '@rsbuild/shared';
2
- import type { DevConfig, NormalizedDevConfig } from './dev';
3
- import type { ExperimentsConfig, NormalizedExperimentsConfig } from './experiments';
4
- import type { HtmlConfig, NormalizedHtmlConfig } from './html';
5
- import type { NormalizedOutputConfig, OutputConfig } from './output';
6
- import type { NormalizedPerformanceConfig, PerformanceConfig } from './performance';
7
2
  import type { NormalizedSecurityConfig, SecurityConfig } from './security';
8
3
  import type { NormalizedSourceConfig, SourceConfig } from './source';
9
4
  import type { NormalizedToolsConfig, ToolsConfig } from './tools';
5
+ import type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig } from '@rsbuild/shared';
6
+ export type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig };
7
+ export * from './security';
8
+ export * from './source';
9
+ export * from './tools';
10
10
  /** The Rsbuild config when using Webpack as the bundler */
11
11
  export interface RsbuildConfig {
12
12
  dev?: DevConfig;
@@ -27,12 +27,4 @@ export type NormalizedConfig = DeepReadonly<{
27
27
  security: NormalizedSecurityConfig;
28
28
  performance: NormalizedPerformanceConfig;
29
29
  experiments: NormalizedExperimentsConfig;
30
- }>;
31
- export * from './dev';
32
- export * from './experiments';
33
- export * from './html';
34
- export * from './output';
35
- export * from './performance';
36
- export * from './security';
37
- export * from './source';
38
- export * from './tools';
30
+ }>;
@@ -15,21 +15,11 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var config_exports = {};
17
17
  module.exports = __toCommonJS(config_exports);
18
- __reExport(config_exports, require("./dev"), module.exports);
19
- __reExport(config_exports, require("./experiments"), module.exports);
20
- __reExport(config_exports, require("./html"), module.exports);
21
- __reExport(config_exports, require("./output"), module.exports);
22
- __reExport(config_exports, require("./performance"), module.exports);
23
18
  __reExport(config_exports, require("./security"), module.exports);
24
19
  __reExport(config_exports, require("./source"), module.exports);
25
20
  __reExport(config_exports, require("./tools"), module.exports);
26
21
  // Annotate the CommonJS export names for ESM import in node:
27
22
  0 && (module.exports = {
28
- ...require("./dev"),
29
- ...require("./experiments"),
30
- ...require("./html"),
31
- ...require("./output"),
32
- ...require("./performance"),
33
23
  ...require("./security"),
34
24
  ...require("./source"),
35
25
  ...require("./tools")
@@ -1,9 +1,9 @@
1
- import type { SriOptions, SharedSecurityConfig, NormalizedSharedSecurityConfig } from '@rsbuild/shared';
2
- export type SecurityConfig = SharedSecurityConfig & {
1
+ import type { SriOptions, SecurityConfig as BaseSecurityConfig, NormalizedSecurityConfig as BaseNormalizedSecurityConfig } from '@rsbuild/shared';
2
+ export type SecurityConfig = BaseSecurityConfig & {
3
3
  /**
4
4
  * Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML allows the browser to
5
5
  * verify the integrity of the introduced resource, thus preventing tampering with the downloaded resource.
6
6
  */
7
7
  sri?: SriOptions | boolean;
8
8
  };
9
- export type NormalizedSecurityConfig = NormalizedSharedSecurityConfig & Required<Pick<SecurityConfig, 'sri'>>;
9
+ export type NormalizedSecurityConfig = BaseNormalizedSecurityConfig & Required<Pick<SecurityConfig, 'sri'>>;
@@ -1,4 +1,4 @@
1
- import type { SharedSourceConfig, NormalizedSharedSourceConfig, ChainedConfig } from '@rsbuild/shared';
1
+ import type { ChainedConfig, SourceConfig as BaseSourceConfig, NormalizedSourceConfig as BaseNormalizedSourceConfig } from '@rsbuild/shared';
2
2
  export type ModuleScopes = Array<string | RegExp>;
3
3
  export type TransformImport = {
4
4
  libraryName: string;
@@ -10,27 +10,17 @@ export type TransformImport = {
10
10
  customName?: ((member: string) => string | undefined) | string;
11
11
  customStyleName?: ((member: string) => string | undefined) | string;
12
12
  };
13
- export interface SourceConfig extends SharedSourceConfig {
14
- /**
15
- * Replaces variables in your code with other values or expressions at compile time.
16
- */
17
- define?: Record<string, any>;
13
+ export interface SourceConfig extends BaseSourceConfig {
18
14
  /**
19
15
  * Restrict importing paths. After configuring this option, all source files can only import code from
20
16
  * the specific paths, and import code from other paths is not allowed.
21
17
  */
22
18
  moduleScopes?: ChainedConfig<ModuleScopes>;
23
- /**
24
- * Configure babel-plugin-import or swc-plugin-import or Rspack builtins plugin import
25
- */
26
- transformImport?: false | TransformImport[];
27
19
  }
28
- export interface NormalizedSourceConfig extends NormalizedSharedSourceConfig {
29
- define: Record<string, any>;
20
+ export interface NormalizedSourceConfig extends BaseNormalizedSourceConfig {
30
21
  /**
31
22
  * Restrict importing paths. After configuring this option, all source files can only import code from
32
23
  * the specific paths, and import code from other paths is not allowed.
33
24
  */
34
25
  moduleScopes?: ChainedConfig<ModuleScopes>;
35
- transformImport?: false | TransformImport[];
36
26
  }
@@ -1,7 +1,8 @@
1
- import type { ArrayOrNot, ChainedConfig, FileFilterUtil, SharedToolsConfig, TerserPluginOptions } from '@rsbuild/shared';
1
+ import type { ArrayOrNot, ChainedConfig, FileFilterUtil, TerserPluginOptions, ToolsConfig as BaseToolsConfig } from '@rsbuild/shared';
2
2
  import type { BabelTransformOptions, BabelConfigUtils } from '@rsbuild/plugin-babel';
3
+ import type { PluginCssMinimizerOptions } from '@rsbuild/plugin-css-minimizer';
3
4
  import type { ModifyWebpackChainUtils, ModifyWebpackConfigUtils } from '../hooks';
4
- import type { CSSExtractOptions, HTMLPluginOptions, TSLoaderOptions, WebpackChain, WebpackConfig } from '../thirdParty';
5
+ import type { WebpackChain, WebpackConfig, TSLoaderOptions, CSSExtractOptions } from '../thirdParty';
5
6
  import type { NormalizedCSSExtractOptions } from '../thirdParty/css';
6
7
  export type ToolsTerserConfig = ChainedConfig<TerserPluginOptions>;
7
8
  export type ToolsTSLoaderConfig = ChainedConfig<TSLoaderOptions, {
@@ -9,14 +10,10 @@ export type ToolsTSLoaderConfig = ChainedConfig<TSLoaderOptions, {
9
10
  addExcludes: FileFilterUtil;
10
11
  }>;
11
12
  export type ToolsCssExtractConfig = CSSExtractOptions | ((options: CSSExtractOptions) => CSSExtractOptions | void);
12
- export type ToolsHtmlPluginConfig = ChainedConfig<HTMLPluginOptions, {
13
- entryName: string;
14
- entryValue: WebpackConfig['entry'];
15
- }>;
16
13
  export type ToolsWebpackConfig = ChainedConfig<WebpackConfig, ModifyWebpackConfigUtils>;
17
14
  export type ToolsWebpackChainConfig = ArrayOrNot<(chain: WebpackChain, utils: ModifyWebpackChainUtils) => void>;
18
15
  export type ToolsBabelConfig = ChainedConfig<BabelTransformOptions, BabelConfigUtils>;
19
- export interface ToolsConfig extends SharedToolsConfig {
16
+ export interface ToolsConfig extends BaseToolsConfig {
20
17
  /**
21
18
  * Modify the options of [babel-loader](https://github.com/babel/babel-loader)
22
19
  * When `tools.babel`'s type is Function,the default babel config will be passed in as the first parameter, the config object can be modified directly, or a value can be returned as the final result.
@@ -33,10 +30,6 @@ export interface ToolsConfig extends SharedToolsConfig {
33
30
  * When `tools.tsLoader` is not undefined, Rsbuild will use ts-loader instead of babel-loader to compile TypeScript code.
34
31
  */
35
32
  tsLoader?: ToolsTSLoaderConfig;
36
- /**
37
- * Modify the options of [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin).
38
- */
39
- htmlPlugin?: false | ToolsHtmlPluginConfig;
40
33
  /**
41
34
  * Modify the options of [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
42
35
  */
@@ -49,6 +42,10 @@ export interface ToolsConfig extends SharedToolsConfig {
49
42
  * Configure webpack by [webpack-chain](https://github.com/neutrinojs/webpack-chain).
50
43
  */
51
44
  webpackChain?: ToolsWebpackChainConfig;
45
+ /**
46
+ * Modify the options of [css-minimizer-webpack-plugin](https://github.com/webpack-contrib/css-minimizer-webpack-plugin).
47
+ */
48
+ minifyCss?: PluginCssMinimizerOptions['pluginOptions'];
52
49
  }
53
50
  export interface NormalizedToolsConfig extends ToolsConfig {
54
51
  cssExtract: NormalizedCSSExtractOptions;
@@ -8,8 +8,6 @@ export type Context = BaseContext & {
8
8
  hooks: Readonly<Hooks>;
9
9
  /** Current Rsbuild config. */
10
10
  config: Readonly<RsbuildConfig>;
11
- /** The async task to validate schema of config. */
12
- configValidatingTask: Promise<void>;
13
11
  /** The original Rsbuild config passed from the createRsbuild method. */
14
12
  originalConfig: Readonly<RsbuildConfig>;
15
13
  /** The normalized Rsbuild config. */
@@ -2,10 +2,15 @@ import type { ChainIdentifier, ModifyChainUtils } from '@rsbuild/shared';
2
2
  import type { WebpackChain, WebpackConfig } from './thirdParty';
3
3
  import type { RuleSetRule, WebpackPluginInstance } from 'webpack';
4
4
  export type ModifyWebpackChainUtils = ModifyChainUtils & {
5
- /** @deprecated Use target instead. */
6
- name: string;
7
5
  webpack: typeof import('webpack');
8
6
  CHAIN_ID: ChainIdentifier;
7
+ /**
8
+ * @deprecated Use target instead.
9
+ * */
10
+ name: string;
11
+ /**
12
+ * @deprecated Use HtmlPlugin instead.
13
+ */
9
14
  HtmlWebpackPlugin: typeof import('html-webpack-plugin');
10
15
  };
11
16
  export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
@@ -2,7 +2,6 @@ import type { WebpackChain } from '@rsbuild/shared';
2
2
  import type webpack from 'webpack';
3
3
  import type { Configuration as WebpackConfig } from 'webpack';
4
4
  import type { Options as RawTSLoaderOptions } from 'ts-loader';
5
- export type { CopyPluginOptions } from './CopyWebpackPlugin';
6
5
  export type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
7
6
  export type { SubresourceIntegrityPluginOptions as SubresourceIntegrityOptions } from 'webpack-subresource-integrity';
8
7
  export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
@@ -22,7 +22,6 @@ __export(ModuleScopePlugin_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(ModuleScopePlugin_exports);
24
24
  var import_path = require("path");
25
- var import_chalk = require("@rsbuild/shared/chalk");
26
25
  var import_shared = require("@rsbuild/shared");
27
26
  class ModuleScopePlugin {
28
27
  constructor({
@@ -76,16 +75,16 @@ class ModuleScopePlugin {
76
75
  const requestRelative = (0, import_path.relative)(allowedDir, requestFullPath);
77
76
  return requestRelative.startsWith("../") || requestRelative.startsWith("..\\");
78
77
  })) {
79
- let message = `You attempted to import ${import_chalk.chalk.bold(
78
+ let message = `You attempted to import ${import_shared.color.bold(
80
79
  request.__innerRequest_request
81
80
  )} which is not allowed. `;
82
81
  if (allowedDirs.length) {
83
- message += `Allowed dirs: ${import_chalk.chalk.bold(
82
+ message += `Allowed dirs: ${import_shared.color.bold(
84
83
  relativeAllowedDirs.join(",")
85
84
  )}. `;
86
85
  }
87
86
  if (allowedPatterns.length) {
88
- message += `Allowed patterns: ${import_chalk.chalk.bold(
87
+ message += `Allowed patterns: ${import_shared.color.bold(
89
88
  allowedPatterns.map((p) => p.toString()).join(",")
90
89
  )}. `;
91
90
  }
@@ -36,7 +36,7 @@ __export(bar_exports, {
36
36
  module.exports = __toCommonJS(bar_exports);
37
37
  var import_cli_truncate = __toESM(require("../../../../compiled/cli-truncate"));
38
38
  var import_utils = require("./utils");
39
- var import_chalk = require("@rsbuild/shared/chalk");
39
+ var import_shared = require("@rsbuild/shared");
40
40
  const defaultOption = {
41
41
  total: 100,
42
42
  current: 0,
@@ -51,7 +51,7 @@ const defaultOption = {
51
51
  done: false,
52
52
  spaceWidth: 1,
53
53
  messageWidth: 25,
54
- messageColor: "grey",
54
+ messageColor: "gray",
55
55
  id: "",
56
56
  maxIdLen: 16,
57
57
  hasErrors: false
@@ -89,15 +89,15 @@ const renderBar = (option) => {
89
89
  } = mergedOptions;
90
90
  const space = " ".repeat(spaceWidth);
91
91
  const percent = (0, import_utils.clamp)(Math.floor(current / total * 100), 0, 100);
92
- const barColor = Reflect.get(import_chalk.chalk, color);
93
- const backgroundColor = Reflect.get(import_chalk.chalk, bgColor);
94
- const doneColor = hasErrors ? import_chalk.chalk.bold.red : Reflect.get(import_chalk.chalk, color);
92
+ const barColor = import_shared.color[color];
93
+ const backgroundColor = color[bgColor];
94
+ const doneColor = hasErrors ? import_shared.color.red : barColor;
95
95
  const idColor = done ? doneColor : barColor;
96
96
  const id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : "";
97
97
  const { columns: terminalWidth = FULL_WIDTH } = process.stdout;
98
98
  if (done) {
99
99
  if (hasErrors) {
100
- const message2 = doneColor(errorInfo);
100
+ const message2 = import_shared.color.bold(doneColor(errorInfo));
101
101
  if (terminalWidth >= MIDDLE_WIDTH) {
102
102
  return [idColor(errorIcon), id, doneColor(`${space}${message2}`)].join(
103
103
  ""
@@ -107,10 +107,9 @@ const renderBar = (option) => {
107
107
  }
108
108
  return "";
109
109
  }
110
- const msgStr = Reflect.get(
111
- import_chalk.chalk,
112
- messageColor
113
- )((0, import_cli_truncate.default)(message, messageWidth, { position: "start" }));
110
+ const msgStr = import_shared.color[messageColor](
111
+ (0, import_cli_truncate.default)(message, messageWidth, { position: "start" })
112
+ );
114
113
  const left = (0, import_utils.clamp)(Math.floor(percent * width / 100), 0, width);
115
114
  const right = (0, import_utils.clamp)(width - left, 0, width);
116
115
  const barStr = `${barColor(char.repeat(left))}${backgroundColor(
@@ -1,10 +1,9 @@
1
- import type { chalk } from '@rsbuild/shared/chalk';
2
- type Color = (typeof chalk)['ForegroundColor'];
1
+ import type { Colors } from '@rsbuild/shared';
3
2
  export type Props = {
4
3
  total: number;
5
4
  current: number;
6
- color: Color;
7
- bgColor: Color;
5
+ color: Colors;
6
+ bgColor: Colors;
8
7
  char: string;
9
8
  width: number;
10
9
  buildIcon: string;
@@ -14,12 +13,11 @@ export type Props = {
14
13
  done: boolean;
15
14
  messageWidth: number;
16
15
  spaceWidth: number;
17
- messageColor: Color;
16
+ messageColor: Colors;
18
17
  id: string;
19
18
  maxIdLen: number;
20
19
  hasErrors: boolean;
21
20
  };
22
21
  export type BusOption = {
23
22
  state: Props[];
24
- };
25
- export {};
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/webpack",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "homepage": "https://rsbuild.dev",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "@babel/core": "^7.23.2",
44
44
  "@babel/preset-react": "^7.22.15",
45
- "@modern-js/server": "^2.39.0",
45
+ "@modern-js/server": "0.0.0-next-20231103131234",
46
46
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
47
47
  "babel-loader": "9.1.3",
48
48
  "babel-plugin-import": "1.13.5",
@@ -59,10 +59,11 @@
59
59
  "tsconfig-paths-webpack-plugin": "4.1.0",
60
60
  "webpack": "^5.89.0",
61
61
  "webpack-subresource-integrity": "5.1.0",
62
- "@rsbuild/babel-preset": "0.0.12",
63
- "@rsbuild/core": "0.0.12",
64
- "@rsbuild/plugin-babel": "0.0.12",
65
- "@rsbuild/shared": "0.0.12"
62
+ "@rsbuild/babel-preset": "0.0.14",
63
+ "@rsbuild/plugin-babel": "0.0.14",
64
+ "@rsbuild/plugin-css-minimizer": "0.0.14",
65
+ "@rsbuild/core": "0.0.14",
66
+ "@rsbuild/shared": "0.0.14"
66
67
  },
67
68
  "devDependencies": {
68
69
  "@types/lodash": "^4.14.200",
@@ -70,7 +71,7 @@
70
71
  "react": "^18.2.0",
71
72
  "react-dom": "^18.2.0",
72
73
  "typescript": "^5.2.2",
73
- "@rsbuild/test-helper": "0.0.12"
74
+ "@rsbuild/test-helper": "0.0.14"
74
75
  },
75
76
  "engines": {
76
77
  "node": ">=14.0.0"
@@ -1 +0,0 @@
1
- (()=>{"use strict";var e={831:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:true});t.transformFiles=t.reduceChunk=t.reduceAssets=t.generateManifest=void 0;const n=s(17);const generateManifest=(e,t,{generate:s,seed:n={}})=>{let o;if(s){const a=Array.from(e.entrypoints.entries());const i=a.reduce(((e,[t,s])=>Object.assign(e,{[t]:s.getFiles()})),{});o=s(n,t,i)}else{o=t.reduce(((e,t)=>Object.assign(e,{[t.name]:t.path})),n)}return o};t.generateManifest=generateManifest;const getFileType=(e,{transformExtensions:t})=>{const s=e.replace(/\?.*/,"");const n=s.split(".");const o=n.pop();return t.test(o)?`${n.pop()}.${o}`:o};const reduceAssets=(e,t,s)=>{let o;if(s[t.name]){o=s[t.name]}else if(t.info.sourceFilename){o=n.join(n.dirname(t.name),n.basename(t.info.sourceFilename))}if(o){return e.concat({isAsset:true,isChunk:false,isInitial:false,isModuleAsset:true,name:o,path:t.name})}const a=t.chunks&&t.chunks.length>0;if(a){return e}return e.concat({isAsset:true,isChunk:false,isInitial:false,isModuleAsset:false,name:t.name,path:t.name})};t.reduceAssets=reduceAssets;const reduceChunk=(e,t,s,o)=>{Array.from(t.auxiliaryFiles||[]).forEach((e=>{o[e]={isAsset:true,isChunk:false,isInitial:false,isModuleAsset:true,name:n.basename(e),path:e}}));return Array.from(t.files).reduce(((e,n)=>{let o=t.name?t.name:null;o=o?s.useEntryKeys&&!n.endsWith(".map")?o:`${o}.${getFileType(n,s)}`:n;return e.concat({chunk:t,isAsset:false,isChunk:true,isInitial:t.isOnlyInitial(),isModuleAsset:false,name:o,path:n})}),e)};t.reduceChunk=reduceChunk;const standardizeFilePaths=e=>{const t=Object.assign({},e);t.name=e.name.replace(/\\/g,"/");t.path=e.path.replace(/\\/g,"/");return t};const transformFiles=(e,t)=>["filter","map","sort"].filter((e=>!!t[e])).reduce(((e,s)=>e[s](t[s])),e).map(standardizeFilePaths);t.transformFiles=transformFiles},406:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:true});t.normalModuleLoaderHook=t.getCompilerHooks=t.emitHook=t.beforeRunHook=void 0;const n=s(147);const o=s(17);const a=s(279);const i=s(908);const r=s(831);const l=new WeakMap;const getCompilerHooks=e=>{let t=l.get(e);if(typeof t==="undefined"){t={afterEmit:new a.SyncWaterfallHook(["manifest"]),beforeEmit:new a.SyncWaterfallHook(["manifest"])};l.set(e,t)}return t};t.getCompilerHooks=getCompilerHooks;const beforeRunHook=({emitCountMap:e,manifestFileName:t},s,n)=>{const o=e.get(t)||0;e.set(t,o+1);if(n){n()}};t.beforeRunHook=beforeRunHook;const u=function emit({compiler:e,emitCountMap:t,manifestAssetId:s,manifestFileName:a,moduleAssets:l,options:u},c){const p=t.get(a)-1;const m=c.getStats().toJson({all:false,assets:true,cachedAssets:true,ids:true,publicPath:true});const f=u.publicPath!==null?u.publicPath:m.publicPath;const{basePath:d,removeKeyHash:h}=u;t.set(a,p);const k={};let b=Array.from(c.chunks).reduce(((e,t)=>r.reduceChunk(e,t,u,k)),[]);b=m.assets.reduce(((e,t)=>r.reduceAssets(e,t,l)),b);b=b.filter((({name:s,path:n})=>{var a;return!n.includes("hot-update")&&typeof t.get(o.join(((a=e.options.output)===null||a===void 0?void 0:a.path)||"<unknown>",s))==="undefined"}));b.forEach((e=>{delete k[e.path]}));Object.keys(k).forEach((e=>{b=b.concat(k[e])}));b=b.map((e=>{const normalizePath=e=>{if(!e.endsWith("/")){return`${e}/`}return e};const t={name:d?normalizePath(d)+e.name:e.name,path:f?normalizePath(f)+e.path:e.path};t.name=h?t.name.replace(h,""):t.name;return Object.assign(e,t)}));b=r.transformFiles(b,u);let g=r.generateManifest(c,b,u);const _=p===0;g=getCompilerHooks(e).beforeEmit.call(g);if(_){const e=u.serialize(g);c.emitAsset(s,new i.RawSource(e));if(u.writeToFileEmit){n.mkdirSync(o.dirname(a),{recursive:true});n.writeFileSync(a,e)}}getCompilerHooks(e).afterEmit.call(g)};t.emitHook=u;const normalModuleLoaderHook=({moduleAssets:e},t,s)=>{const{emitFile:n}=t;t.emitFile=(t,a,i)=>{if(s.userRequest&&!e[t]){Object.assign(e,{[t]:o.join(o.dirname(t),o.basename(s.userRequest))})}return n.call(s,t,a,i)}};t.normalModuleLoaderHook=normalModuleLoaderHook},227:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.WebpackManifestPlugin=t.getCompilerHooks=void 0;const o=s(17);const a=n(s(530));const i=s(406);Object.defineProperty(t,"getCompilerHooks",{enumerable:true,get:function(){return i.getCompilerHooks}});const r=new Map;const l={assetHookStage:Infinity,basePath:"",fileName:"manifest.json",filter:null,generate:void 0,map:null,publicPath:null,removeKeyHash:/([a-f0-9]{16,32}\.?)/gi,seed:void 0,serialize(e){return JSON.stringify(e,null,2)},sort:null,transformExtensions:/^(gz|map)$/i,useEntryKeys:false,useLegacyEmit:false,writeToFileEmit:false};class WebpackManifestPlugin{constructor(e){this.options=Object.assign({},l,e)}apply(e){var t,s;const n={};const l=o.resolve(((t=e.options.output)===null||t===void 0?void 0:t.path)||"./",this.options.fileName);const u=o.relative(((s=e.options.output)===null||s===void 0?void 0:s.path)||"./",l);const c=i.beforeRunHook.bind(this,{emitCountMap:r,manifestFileName:l});const p=i.emitHook.bind(this,{compiler:e,emitCountMap:r,manifestAssetId:u,manifestFileName:l,moduleAssets:n,options:this.options});const m=i.normalModuleLoaderHook.bind(this,{moduleAssets:n});const f={name:"WebpackManifestPlugin",stage:this.options.assetHookStage};e.hooks.compilation.tap(f,(e=>{const t=!a.default.getCompilationHooks?e.hooks.normalModuleLoader:a.default.getCompilationHooks(e).loader;t.tap(f,m)}));if(this.options.useLegacyEmit===true){e.hooks.emit.tap(f,p)}else{e.hooks.thisCompilation.tap(f,(e=>{e.hooks.processAssets.tap(f,(()=>p(e)))}))}e.hooks.run.tapAsync(f,c);e.hooks.watchRun.tapAsync(f,c)}}t.WebpackManifestPlugin=WebpackManifestPlugin},279:e=>{e.exports=require("../tapable")},908:e=>{e.exports=require("../webpack-sources")},147:e=>{e.exports=require("fs")},17:e=>{e.exports=require("path")},530:e=>{e.exports=require("webpack/lib/NormalModule")}};var t={};function __nccwpck_require__(s){var n=t[s];if(n!==undefined){return n.exports}var o=t[s]={exports:{}};var a=true;try{e[s].call(o.exports,o,o.exports,__nccwpck_require__);a=false}finally{if(a)delete t[s]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var s=__nccwpck_require__(227);module.exports=s})();
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) Dane Thurber <dane.thurber@gmail.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"name":"webpack-manifest-plugin","author":"Dane Thurber <dane.thurber@gmail.com>","version":"5.0.0","license":"MIT","types":"types/index.d.ts"}
@@ -1,23 +0,0 @@
1
- import { AssetInfo, Chunk, Asset, Compilation } from 'webpack';
2
- import { InternalOptions, Manifest } from '.';
3
- export interface FileDescriptor {
4
- chunk?: Chunk;
5
- isAsset: Boolean;
6
- isChunk: Boolean;
7
- isInitial: Boolean;
8
- isModuleAsset: Boolean;
9
- name: string;
10
- path: string;
11
- }
12
- export interface CompilationAssetInfo extends AssetInfo {
13
- sourceFilename: string;
14
- }
15
- export interface CompilationAsset extends Asset {
16
- chunks: any[];
17
- info: CompilationAssetInfo;
18
- }
19
- declare const generateManifest: (compilation: Compilation, files: FileDescriptor[], { generate, seed }: InternalOptions) => Manifest;
20
- declare const reduceAssets: (files: FileDescriptor[], asset: CompilationAsset, moduleAssets: Record<any, any>) => FileDescriptor[];
21
- declare const reduceChunk: (files: FileDescriptor[], chunk: Chunk, options: InternalOptions, auxiliaryFiles: Record<any, any>) => FileDescriptor[];
22
- declare const transformFiles: (files: FileDescriptor[], options: InternalOptions) => FileDescriptor[];
23
- export { generateManifest, reduceAssets, reduceChunk, transformFiles };
@@ -1,24 +0,0 @@
1
- import { Compiler, Module, Compilation, LoaderContext } from 'webpack';
2
- import { EmitCountMap, InternalOptions } from '.';
3
- interface BeforeRunHookArgs {
4
- emitCountMap: EmitCountMap;
5
- manifestFileName: string;
6
- }
7
- interface EmitHookArgs {
8
- compiler: Compiler;
9
- emitCountMap: EmitCountMap;
10
- manifestAssetId: string;
11
- manifestFileName: string;
12
- moduleAssets: Record<any, any>;
13
- options: InternalOptions;
14
- }
15
- declare const getCompilerHooks: (compiler: Compiler) => any;
16
- declare const beforeRunHook: ({ emitCountMap, manifestFileName }: BeforeRunHookArgs, _: Compiler, callback: Function) => void;
17
- declare const emitHook: ({ compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, options }: EmitHookArgs, compilation: Compilation) => void;
18
- interface LegacyModule extends Module {
19
- userRequest?: any;
20
- }
21
- declare const normalModuleLoaderHook: ({ moduleAssets }: {
22
- moduleAssets: Record<any, any>;
23
- }, loaderContext: LoaderContext<any>, module: LegacyModule) => void;
24
- export { beforeRunHook, emitHook, getCompilerHooks, normalModuleLoaderHook };