@rsbuild/webpack 0.2.18 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,3 @@
1
1
  import { InitConfigsOptions } from './initConfigs';
2
- import { type Stats, type BuildOptions } from '@rsbuild/shared';
3
- import type { Compiler, MultiStats, MultiCompiler } from 'webpack';
4
- export interface BuildExecuter {
5
- (compiler: Compiler): Promise<{
6
- stats: Stats;
7
- }>;
8
- (compiler: MultiCompiler): Promise<{
9
- stats: MultiStats;
10
- }>;
11
- (compiler: Compiler | MultiCompiler): Promise<{
12
- stats: Stats | MultiStats;
13
- }>;
14
- }
15
- export declare const webpackBuild: BuildExecuter;
16
- export declare const build: (initOptions: InitConfigsOptions, { mode, watch, compiler: customCompiler }?: BuildOptions, executer?: BuildExecuter) => Promise<void>;
2
+ import { type BuildOptions } from '@rsbuild/shared';
3
+ export declare const build: (initOptions: InitConfigsOptions, { mode, watch, compiler: customCompiler }?: BuildOptions) => Promise<void>;
@@ -18,29 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var build_exports = {};
20
20
  __export(build_exports, {
21
- build: () => build,
22
- webpackBuild: () => webpackBuild
21
+ build: () => build
23
22
  });
24
23
  module.exports = __toCommonJS(build_exports);
25
24
  var import_createCompiler = require("./createCompiler");
26
25
  var import_initConfigs = require("./initConfigs");
27
26
  var import_shared = require("@rsbuild/shared");
28
- const webpackBuild = async (compiler) => {
29
- return new Promise((resolve, reject) => {
30
- compiler.run((err, stats) => {
31
- if (err || stats?.hasErrors()) {
32
- const buildError = err || new Error("Webpack build failed!");
33
- reject(buildError);
34
- } else {
35
- compiler.close((closeErr) => {
36
- closeErr && import_shared.logger.error(closeErr);
37
- resolve({ stats });
38
- });
39
- }
40
- });
41
- });
42
- };
43
- const build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}, executer) => {
27
+ const build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
44
28
  if (!process.env.NODE_ENV) {
45
29
  process.env.NODE_ENV = mode;
46
30
  }
@@ -57,7 +41,7 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
57
41
  });
58
42
  bundlerConfigs = webpackConfigs;
59
43
  }
60
- await context.hooks.onBeforeBuildHook.call({
44
+ await context.hooks.onBeforeBuild.call({
61
45
  bundlerConfigs
62
46
  });
63
47
  if (watch) {
@@ -66,15 +50,26 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
66
50
  import_shared.logger.error(err);
67
51
  }
68
52
  });
69
- } else {
70
- const executeResult = await executer?.(compiler);
71
- await context.hooks.onAfterBuildHook.call({
72
- stats: executeResult?.stats
73
- });
53
+ return;
74
54
  }
55
+ const { stats } = await new Promise(
56
+ (resolve, reject) => {
57
+ compiler.run((err, stats2) => {
58
+ if (err || stats2?.hasErrors()) {
59
+ const buildError = err || new Error("Webpack build failed!");
60
+ reject(buildError);
61
+ } else {
62
+ compiler.close((closeErr) => {
63
+ closeErr && import_shared.logger.error(closeErr);
64
+ resolve({ stats: stats2 });
65
+ });
66
+ }
67
+ });
68
+ }
69
+ );
70
+ await context.hooks.onAfterBuild.call({ stats });
75
71
  };
76
72
  // Annotate the CommonJS export names for ESM import in node:
77
73
  0 && (module.exports = {
78
- build,
79
- webpackBuild
74
+ build
80
75
  });
@@ -40,7 +40,7 @@ async function createCompiler({
40
40
  webpackConfigs
41
41
  }) {
42
42
  (0, import_shared.debug)("create compiler");
43
- await context.hooks.onBeforeCreateCompilerHook.call({
43
+ await context.hooks.onBeforeCreateCompiler.call({
44
44
  bundlerConfigs: webpackConfigs
45
45
  });
46
46
  const { default: webpack } = await Promise.resolve().then(() => __toESM(require("webpack")));
@@ -55,14 +55,14 @@ async function createCompiler({
55
55
  import_shared.logger.warn(message);
56
56
  }
57
57
  if ((0, import_shared.isDev)()) {
58
- await context.hooks.onDevCompileDoneHook.call({
58
+ await context.hooks.onDevCompileDone.call({
59
59
  isFirstCompile,
60
60
  stats
61
61
  });
62
62
  }
63
63
  isFirstCompile = false;
64
64
  });
65
- await context.hooks.onAfterCreateCompilerHook.call({
65
+ await context.hooks.onAfterCreateCompiler.call({
66
66
  compiler
67
67
  });
68
68
  (0, import_shared.debug)("create compiler done");
@@ -52,8 +52,8 @@ async function initConfigs({
52
52
  bundlerConfigs: webpackConfigs
53
53
  });
54
54
  };
55
- context.hooks.onBeforeBuildHook.tap(inspect);
56
- context.hooks.onBeforeStartDevServerHook.tap(inspect);
55
+ context.hooks.onBeforeBuild.tap(inspect);
56
+ context.hooks.onBeforeStartDevServer.tap(inspect);
57
57
  }
58
58
  return {
59
59
  webpackConfigs
@@ -35,7 +35,7 @@ var import_shared = require("@rsbuild/shared");
35
35
  var import_shared2 = require("../shared");
36
36
  async function modifyWebpackChain(context, utils, chain) {
37
37
  (0, import_shared.debug)("modify webpack chain");
38
- const [modifiedChain] = await context.hooks.modifyWebpackChainHook.call(
38
+ const [modifiedChain] = await context.hooks.modifyWebpackChain.call(
39
39
  chain,
40
40
  utils
41
41
  );
@@ -49,7 +49,7 @@ async function modifyWebpackChain(context, utils, chain) {
49
49
  }
50
50
  async function modifyWebpackConfig(context, webpackConfig, utils) {
51
51
  (0, import_shared.debug)("modify webpack config");
52
- let [modifiedConfig] = await context.hooks.modifyWebpackConfigHook.call(
52
+ let [modifiedConfig] = await context.hooks.modifyWebpackConfig.call(
53
53
  webpackConfig,
54
54
  utils
55
55
  );
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { webpackProvider } from './provider';
2
- export { webpackBuild } from './core/build';
3
2
  export type { webpack, WebpackChain, WebpackConfig, } from './types';
package/dist/index.js CHANGED
@@ -18,14 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
- webpackBuild: () => import_build.webpackBuild,
22
21
  webpackProvider: () => import_provider.webpackProvider
23
22
  });
24
23
  module.exports = __toCommonJS(src_exports);
25
24
  var import_provider = require("./provider");
26
- var import_build = require("./core/build");
27
25
  // Annotate the CommonJS export names for ESM import in node:
28
26
  0 && (module.exports = {
29
- webpackBuild,
30
27
  webpackProvider
31
28
  });
@@ -39,7 +39,7 @@ const pluginServer = () => ({
39
39
  api.modifyBundlerChain(async (chain, { isProd }) => {
40
40
  const config = api.getNormalizedConfig();
41
41
  if (isProd && config.server?.publicDir) {
42
- const { name, copyOnBuild } = config.server?.publicDir;
42
+ const { name, copyOnBuild } = config.server.publicDir;
43
43
  if (!copyOnBuild || !name) {
44
44
  return;
45
45
  }
@@ -49,8 +49,8 @@ class ProgressPlugin extends import_webpack.default.ProgressPlugin {
49
49
  dependencies: true,
50
50
  dependenciesCount: 1e4,
51
51
  percentBy: null,
52
- handler: (percentage, message) => {
53
- percentage = friendlyPercentage(percentage);
52
+ handler: (originalPercentage, message) => {
53
+ const percentage = friendlyPercentage(originalPercentage);
54
54
  const done = percentage === 1;
55
55
  if (process.stdout.isTTY) {
56
56
  import_helpers.bus.update({
package/dist/provider.js CHANGED
@@ -44,9 +44,19 @@ const webpackProvider = async ({
44
44
  const context = await (0, import_provider.createContext)(rsbuildOptions, rsbuildConfig, "webpack");
45
45
  const pluginAPI = (0, import_provider.getPluginAPI)({ context, pluginStore });
46
46
  context.pluginAPI = pluginAPI;
47
+ const createCompiler = async () => {
48
+ const { createCompiler: createCompiler2 } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
49
+ const { webpackConfigs } = await (0, import_initConfigs.initConfigs)({
50
+ context,
51
+ pluginStore,
52
+ rsbuildOptions
53
+ });
54
+ return createCompiler2({ context, webpackConfigs });
55
+ };
47
56
  return {
48
57
  bundler: "webpack",
49
58
  pluginAPI,
59
+ createCompiler,
50
60
  publicContext: (0, import_provider.createPublicContext)(context),
51
61
  async applyDefaultPlugins() {
52
62
  pluginStore.addPlugins(await (0, import_shared2.applyDefaultPlugins)(plugins));
@@ -59,15 +69,6 @@ const webpackProvider = async ({
59
69
  });
60
70
  return webpackConfigs;
61
71
  },
62
- async createCompiler() {
63
- const { createCompiler } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
64
- const { webpackConfigs } = await (0, import_initConfigs.initConfigs)({
65
- context,
66
- pluginStore,
67
- rsbuildOptions
68
- });
69
- return createCompiler({ context, webpackConfigs });
70
- },
71
72
  async getServerAPIs(options) {
72
73
  const { getServerAPIs } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core/server")));
73
74
  const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
@@ -104,12 +105,8 @@ const webpackProvider = async ({
104
105
  return startProdServer(context, context.config, options);
105
106
  },
106
107
  async build(options) {
107
- const { build: buildImpl, webpackBuild } = await Promise.resolve().then(() => __toESM(require("./core/build")));
108
- return buildImpl(
109
- { context, pluginStore, rsbuildOptions },
110
- options,
111
- webpackBuild
112
- );
108
+ const { build } = await Promise.resolve().then(() => __toESM(require("./core/build")));
109
+ return build({ context, pluginStore, rsbuildOptions }, options);
113
110
  },
114
111
  async inspectConfig(inspectOptions) {
115
112
  const { inspectConfig } = await Promise.resolve().then(() => __toESM(require("./core/inspectConfig")));
package/dist/shared.js CHANGED
@@ -45,7 +45,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared2.awaitableGetter)([
45
45
  Promise.resolve().then(() => __toESM(require("./plugins/resolve"))).then((m) => m.pluginResolve()),
46
46
  plugins.fileSize?.(),
47
47
  plugins.cleanOutput?.(),
48
- Promise.resolve().then(() => __toESM(require("./plugins/hmr"))).then((m) => m.pluginHMR()),
49
48
  plugins.asset(),
50
49
  Promise.resolve().then(() => __toESM(require("./plugins/copy"))).then((m) => m.pluginCopy()),
51
50
  plugins.html(),
@@ -59,8 +58,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared2.awaitableGetter)([
59
58
  Promise.resolve().then(() => __toESM(require("./plugins/sass"))).then((m) => m.pluginSass()),
60
59
  Promise.resolve().then(() => __toESM(require("./plugins/less"))).then((m) => m.pluginLess()),
61
60
  plugins.bundleAnalyzer(),
62
- plugins.toml(),
63
- plugins.yaml(),
64
61
  plugins.splitChunks(),
65
62
  plugins.startUrl?.(),
66
63
  plugins.inlineChunk(),
@@ -74,9 +71,8 @@ const getCompiledPath = (packageName) => {
74
71
  const providerCompilerPath = (0, import_path.join)(__dirname, "../../compiled", packageName);
75
72
  if (import_fs.default.existsSync(providerCompilerPath)) {
76
73
  return providerCompilerPath;
77
- } else {
78
- return (0, import_shared.getSharedPkgCompiledPath)(packageName);
79
74
  }
75
+ return (0, import_shared.getSharedPkgCompiledPath)(packageName);
80
76
  };
81
77
  // Annotate the CommonJS export names for ESM import in node:
82
78
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/webpack",
3
- "version": "0.2.18",
3
+ "version": "0.3.0",
4
4
  "homepage": "https://rsbuild.dev",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,13 +35,13 @@
35
35
  "terser-webpack-plugin": "5.3.9",
36
36
  "tsconfig-paths-webpack-plugin": "4.1.0",
37
37
  "webpack": "^5.89.0",
38
- "@rsbuild/core": "0.2.18",
39
- "@rsbuild/shared": "0.2.18"
38
+ "@rsbuild/shared": "0.3.0",
39
+ "@rsbuild/core": "0.3.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "16.x",
43
43
  "typescript": "^5.3.0",
44
- "@rsbuild/test-helper": "0.2.18"
44
+ "@rsbuild/test-helper": "0.3.0"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",
@@ -1,2 +0,0 @@
1
- import { type RsbuildPlugin } from '@rsbuild/shared';
2
- export declare const pluginHMR: () => RsbuildPlugin;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var hmr_exports = {};
20
- __export(hmr_exports, {
21
- pluginHMR: () => pluginHMR
22
- });
23
- module.exports = __toCommonJS(hmr_exports);
24
- var import_shared = require("@rsbuild/shared");
25
- const pluginHMR = () => ({
26
- name: "rsbuild-webpack:hmr",
27
- setup(api) {
28
- api.modifyBundlerChain((chain, utils) => {
29
- const config = api.getNormalizedConfig();
30
- if (!(0, import_shared.isUsingHMR)(config, utils)) {
31
- return;
32
- }
33
- const { bundler, CHAIN_ID } = utils;
34
- chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
35
- });
36
- }
37
- });
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- pluginHMR
41
- });