@rsbuild/webpack 1.1.0 → 1.1.2

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.
package/dist/index.js CHANGED
@@ -7,61 +7,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_webpack_lib_MultiStats_js__ from "webpack/
7
7
  import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs__ from "reduce-configs";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
10
- var __webpack_modules__ = {
11
- "./src/shared.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
12
- __webpack_require__.d(__webpack_exports__, {
13
- A9: function() {
14
- return initRsbuildConfig;
15
- },
16
- AS: function() {
17
- return prettyTime;
18
- },
19
- DO: function() {
20
- return stringifyConfig;
21
- },
22
- EB: function() {
23
- return modifyBundlerChain;
24
- },
25
- Oo: function() {
26
- return registerBuildHook;
27
- },
28
- PD: function() {
29
- return getRsbuildInspectConfig;
30
- },
31
- PZ: function() {
32
- return createDevServer;
33
- },
34
- SM: function() {
35
- return outputInspectConfigFiles;
36
- },
37
- XQ: function() {
38
- return castArray;
39
- },
40
- g5: function() {
41
- return getStatsOptions;
42
- },
43
- iL: function() {
44
- return chainToConfig;
45
- },
46
- px: function() {
47
- return getChainUtils;
48
- },
49
- v1: function() {
50
- return formatStats;
51
- },
52
- xn: function() {
53
- return registerDevHook;
54
- }
55
- });
56
- /* ESM import */ var _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("@rsbuild/core");
57
- const { getChainUtils, initRsbuildConfig, createDevServer, formatStats, getStatsOptions, stringifyConfig, outputInspectConfigFiles, getRsbuildInspectConfig, chainToConfig, modifyBundlerChain, registerDevHook, registerBuildHook, prettyTime } = _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__.__internalHelper;
58
- const castArray = (arr)=>{
59
- if (void 0 === arr) return [];
60
- return Array.isArray(arr) ? arr : [
61
- arr
62
- ];
63
- };
64
- },
10
+ var installedChunks, installChunk, __webpack_modules__ = {
65
11
  "@rsbuild/core": function(module) {
66
12
  module.exports = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
67
13
  },
@@ -77,166 +23,87 @@ var __webpack_modules__ = {
77
23
  webpack: function(module) {
78
24
  module.exports = __WEBPACK_EXTERNAL_MODULE_webpack__;
79
25
  }
80
- };
81
- /************************************************************************/ // The module cache
82
- var __webpack_module_cache__ = {};
83
- // The require function
26
+ }, __webpack_module_cache__ = {};
84
27
  function __webpack_require__(moduleId) {
85
- // Check if module is in cache
86
28
  var cachedModule = __webpack_module_cache__[moduleId];
87
29
  if (void 0 !== cachedModule) return cachedModule.exports;
88
- // Create a new module (and put it into the cache)
89
30
  var module = __webpack_module_cache__[moduleId] = {
90
31
  id: moduleId,
91
- loaded: false,
32
+ loaded: !1,
92
33
  exports: {}
93
34
  };
94
- // Execute the module function
95
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
96
- // Flag the module as loaded
97
- module.loaded = true;
98
- // Return the exports of the module
99
- return module.exports;
35
+ return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.loaded = !0, module.exports;
100
36
  }
101
- // expose the modules object (__webpack_modules__)
102
- __webpack_require__.m = __webpack_modules__;
103
- /************************************************************************/ // webpack/runtime/compat_get_default_export
104
- (()=>{
105
- // getDefaultExport function for compatibility with non-ESM modules
106
- __webpack_require__.n = function(module) {
107
- var getter = module && module.__esModule ? function() {
108
- return module['default'];
109
- } : function() {
110
- return module;
111
- };
112
- __webpack_require__.d(getter, {
113
- a: getter
114
- });
115
- return getter;
116
- };
117
- })();
118
- // webpack/runtime/define_property_getters
119
- (()=>{
120
- __webpack_require__.d = function(exports, definition) {
121
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
122
- enumerable: true,
123
- get: definition[key]
124
- });
125
- };
126
- })();
127
- // webpack/runtime/ensure_chunk
128
- (()=>{
129
- __webpack_require__.f = {};
130
- // This file contains only the entry chunk.
131
- // The chunk loading function for additional chunks
132
- __webpack_require__.e = function(chunkId) {
133
- return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
134
- __webpack_require__.f[key](chunkId, promises);
135
- return promises;
136
- }, []));
137
- };
138
- })();
139
- // webpack/runtime/get javascript chunk filename
140
- (()=>{
141
- // This function allow to reference chunks
142
- __webpack_require__.u = function(chunkId) {
143
- // return url for filenames not based on template
144
- // return url for filenames based on template
145
- return "" + chunkId + ".js";
146
- };
147
- })();
148
- // webpack/runtime/has_own_property
149
- (()=>{
150
- __webpack_require__.o = function(obj, prop) {
151
- return Object.prototype.hasOwnProperty.call(obj, prop);
152
- };
153
- })();
154
- // webpack/runtime/node_module_decorator
155
- (()=>{
156
- __webpack_require__.nmd = function(module) {
157
- module.paths = [];
158
- if (!module.children) module.children = [];
37
+ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = function(module) {
38
+ var getter = module && module.__esModule ? function() {
39
+ return module.default;
40
+ } : function() {
159
41
  return module;
160
42
  };
161
- })();
162
- // webpack/runtime/module_chunk_loading
163
- (()=>{
164
- // object to store loaded and loading chunks
165
- // undefined = chunk not loaded, null = chunk preloaded/prefetched
166
- // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
167
- var installedChunks = {
168
- 980: 0
169
- };
170
- var installChunk = function(data) {
171
- var ids = data.ids;
172
- var modules = data.modules;
173
- var runtime = data.runtime;
174
- // add "modules" to the modules object,
175
- // then flag all "ids" as loaded and fire callback
176
- var moduleId, chunkId, i = 0;
177
- for(moduleId in modules)if (__webpack_require__.o(modules, moduleId)) __webpack_require__.m[moduleId] = modules[moduleId];
178
- if (runtime) runtime(__webpack_require__);
179
- for(; i < ids.length; i++){
180
- chunkId = ids[i];
181
- if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
182
- installedChunks[ids[i]] = 0;
183
- }
184
- };
185
- __webpack_require__.f.j = function(chunkId, promises) {
186
- // import() chunk loading for javascript
187
- var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
188
- if (0 !== installedChunkData) {
189
- // a Promise means "currently loading".
190
- if (installedChunkData) promises.push(installedChunkData[1]);
191
- else {
192
- // setup Promise in chunk cache
193
- var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
194
- if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
195
- throw e;
196
- });
197
- var promise = Promise.race([
198
- promise,
199
- new Promise(function(resolve) {
200
- installedChunkData = installedChunks[chunkId] = [
201
- resolve
202
- ];
203
- })
204
- ]);
205
- promises.push(installedChunkData[1] = promise);
206
- }
43
+ return __webpack_require__.d(getter, {
44
+ a: getter
45
+ }), getter;
46
+ }, __webpack_require__.d = function(exports, definition) {
47
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
48
+ enumerable: !0,
49
+ get: definition[key]
50
+ });
51
+ }, __webpack_require__.f = {}, __webpack_require__.e = function(chunkId) {
52
+ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
53
+ return __webpack_require__.f[key](chunkId, promises), promises;
54
+ }, []));
55
+ }, __webpack_require__.u = function(chunkId) {
56
+ return "" + chunkId + ".js";
57
+ }, __webpack_require__.o = function(obj, prop) {
58
+ return Object.prototype.hasOwnProperty.call(obj, prop);
59
+ }, __webpack_require__.nmd = function(module) {
60
+ return module.paths = [], !module.children && (module.children = []), module;
61
+ }, installedChunks = {
62
+ 980: 0
63
+ }, installChunk = function(data) {
64
+ var ids = data.ids, modules = data.modules, runtime = data.runtime, moduleId, chunkId, i = 0;
65
+ for(moduleId in modules)__webpack_require__.o(modules, moduleId) && (__webpack_require__.m[moduleId] = modules[moduleId]);
66
+ for(runtime && runtime(__webpack_require__); i < ids.length; i++)chunkId = ids[i], __webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId] && installedChunks[chunkId][0](), installedChunks[ids[i]] = 0;
67
+ }, __webpack_require__.f.j = function(chunkId, promises) {
68
+ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
69
+ if (0 !== installedChunkData) {
70
+ if (installedChunkData) promises.push(installedChunkData[1]);
71
+ else {
72
+ var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
73
+ throw 0 !== installedChunks[chunkId] && (installedChunks[chunkId] = void 0), e;
74
+ }), promise = Promise.race([
75
+ promise,
76
+ new Promise(function(resolve) {
77
+ installedChunkData = installedChunks[chunkId] = [
78
+ resolve
79
+ ];
80
+ })
81
+ ]);
82
+ promises.push(installedChunkData[1] = promise);
207
83
  }
208
- };
209
- })();
210
- // EXTERNAL MODULE: external "@rsbuild/core"
211
- var core_ = __webpack_require__("@rsbuild/core");
212
- // EXTERNAL MODULE: ./src/shared.ts
213
- var shared = __webpack_require__("./src/shared.ts");
214
- const getInspectOutputPath = (context, inspectOptions)=>{
215
- if (inspectOptions.outputPath) {
216
- if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(inspectOptions.outputPath)) return inspectOptions.outputPath;
217
- return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.distPath, inspectOptions.outputPath);
218
84
  }
85
+ };
86
+ var core_ = __webpack_require__("@rsbuild/core");
87
+ let getInspectOutputPath = (context, inspectOptions)=>{
88
+ if (inspectOptions.outputPath) return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(inspectOptions.outputPath) ? inspectOptions.outputPath : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.distPath, inspectOptions.outputPath);
219
89
  return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.distPath, '.rsbuild');
220
90
  };
221
- async function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerConfigs, inspectOptions = {} }) {
222
- if (inspectOptions.mode) process.env.NODE_ENV = inspectOptions.mode;
223
- else if (!process.env.NODE_ENV) process.env.NODE_ENV = 'development';
224
- const webpackConfigs = bundlerConfigs || (await initConfigs({
91
+ async function inspectConfig({ helpers, context, pluginManager, rsbuildOptions, bundlerConfigs, inspectOptions = {} }) {
92
+ inspectOptions.mode ? process.env.NODE_ENV = inspectOptions.mode : !process.env.NODE_ENV && (process.env.NODE_ENV = 'development');
93
+ let webpackConfigs = bundlerConfigs || (await initConfigs({
225
94
  context,
226
95
  pluginManager,
227
- rsbuildOptions
228
- })).webpackConfigs;
229
- const rawBundlerConfigs = webpackConfigs.map((config, index)=>({
96
+ rsbuildOptions,
97
+ helpers
98
+ })).webpackConfigs, rawBundlerConfigs = webpackConfigs.map((config, index)=>({
230
99
  name: config.name || String(index),
231
- content: (0, shared /* stringifyConfig */ .DO)(config, inspectOptions.verbose)
232
- }));
233
- const { rsbuildConfig, rawRsbuildConfig, environmentConfigs, rawEnvironmentConfigs } = (0, shared /* getRsbuildInspectConfig */ .PD)({
100
+ content: helpers.stringifyConfig(config, inspectOptions.verbose)
101
+ })), { rsbuildConfig, rawRsbuildConfig, environmentConfigs, rawEnvironmentConfigs } = helpers.getRsbuildInspectConfig({
234
102
  normalizedConfig: context.normalizedConfig,
235
103
  inspectOptions,
236
104
  pluginManager
237
- });
238
- const outputPath = getInspectOutputPath(context, inspectOptions);
239
- if (inspectOptions.writeToDisk) await (0, shared /* outputInspectConfigFiles */ .SM)({
105
+ }), outputPath = getInspectOutputPath(context, inspectOptions);
106
+ return inspectOptions.writeToDisk && await helpers.outputInspectConfigFiles({
240
107
  rawBundlerConfigs,
241
108
  rawEnvironmentConfigs,
242
109
  inspectOptions: {
@@ -244,8 +111,7 @@ async function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerCo
244
111
  outputPath
245
112
  },
246
113
  configType: 'webpack'
247
- });
248
- return {
114
+ }), {
249
115
  rsbuildConfig: rawRsbuildConfig,
250
116
  environmentConfigs: rawEnvironmentConfigs.map((r)=>r.content),
251
117
  bundlerConfigs: rawBundlerConfigs.map((r)=>r.content),
@@ -256,19 +122,21 @@ async function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerCo
256
122
  }
257
123
  };
258
124
  }
125
+ let castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
126
+ arr
127
+ ];
259
128
  async function modifyWebpackChain(context, utils, chain) {
260
129
  var _utils_environment_config_tools;
261
130
  core_.logger.debug('modify webpack chain');
262
- const [modifiedChain] = await context.hooks.modifyWebpackChain.callInEnvironment({
131
+ let [modifiedChain] = await context.hooks.modifyWebpackChain.callInEnvironment({
263
132
  environment: utils.environment.name,
264
133
  args: [
265
134
  chain,
266
135
  utils
267
136
  ]
268
137
  });
269
- if (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.webpackChain) for (const item of (0, shared /* castArray */ .XQ)(utils.environment.config.tools.webpackChain))item(modifiedChain, utils);
270
- core_.logger.debug('modify webpack chain done');
271
- return modifiedChain;
138
+ if (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.webpackChain) for (let item of castArray(utils.environment.config.tools.webpackChain))item(modifiedChain, utils);
139
+ return core_.logger.debug('modify webpack chain done'), modifiedChain;
272
140
  }
273
141
  async function modifyWebpackConfig(context, webpackConfig, utils) {
274
142
  var _utils_environment_config_tools;
@@ -280,34 +148,28 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
280
148
  utils
281
149
  ]
282
150
  });
283
- if (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.webpack) modifiedConfig = (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigsWithContext)({
151
+ return (null === (_utils_environment_config_tools = utils.environment.config.tools) || void 0 === _utils_environment_config_tools ? void 0 : _utils_environment_config_tools.webpack) && (modifiedConfig = (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigsWithContext)({
284
152
  initial: modifiedConfig,
285
153
  config: utils.environment.config.tools.webpack,
286
154
  ctx: utils,
287
155
  mergeFn: utils.mergeConfig
288
- });
289
- core_.logger.debug('modify webpack config done');
290
- return modifiedConfig;
156
+ })), core_.logger.debug('modify webpack config done'), modifiedConfig;
291
157
  }
292
- async function getChainUtils(target, environment) {
293
- const { default: webpack } = await import("webpack");
294
- const nameMap = {
295
- web: 'client',
296
- node: 'server',
297
- 'web-worker': 'web-worker'
298
- };
158
+ async function getChainUtils(target, environment, helpers) {
159
+ let { default: webpack } = await import("webpack");
299
160
  return {
300
- ...(0, shared /* getChainUtils */ .px)(target, environment),
301
- name: nameMap[target] || '',
161
+ ...helpers.getChainUtils(target, environment),
162
+ name: ({
163
+ web: 'client',
164
+ node: 'server',
165
+ 'web-worker': 'web-worker'
166
+ })[target] || '',
302
167
  webpack,
303
- HtmlWebpackPlugin: core_.__internalHelper.getHTMLPlugin()
168
+ HtmlWebpackPlugin: helpers.getHTMLPlugin()
304
169
  };
305
170
  }
306
- async function generateWebpackConfig({ target, context, environment }) {
307
- const chainUtils = await getChainUtils(target, context.environments[environment]);
308
- const { default: webpack } = await import("webpack");
309
- const { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, HotModuleReplacementPlugin } = webpack;
310
- const bundlerChain = await (0, shared /* modifyBundlerChain */ .EB)(context, {
171
+ async function generateWebpackConfig({ target, context, environment, helpers }) {
172
+ let chainUtils = await getChainUtils(target, context.environments[environment], helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
311
173
  ...chainUtils,
312
174
  bundler: {
313
175
  BannerPlugin,
@@ -316,43 +178,36 @@ async function generateWebpackConfig({ target, context, environment }) {
316
178
  ProvidePlugin,
317
179
  HotModuleReplacementPlugin
318
180
  }
319
- });
320
- const chain = await modifyWebpackChain(context, chainUtils, bundlerChain);
321
- let webpackConfig = (0, shared /* chainToConfig */ .iL)(chain);
322
- const configUtils = await core_.__internalHelper.getConfigUtils(webpackConfig, chainUtils);
323
- webpackConfig = await modifyWebpackConfig(context, webpackConfig, configUtils);
324
- return webpackConfig;
181
+ }), chain = await modifyWebpackChain(context, chainUtils, bundlerChain), webpackConfig = helpers.chainToConfig(chain), configUtils = await helpers.getConfigUtils(webpackConfig, chainUtils);
182
+ return webpackConfig = await modifyWebpackConfig(context, webpackConfig, configUtils);
325
183
  }
326
- async function initConfigs({ context, pluginManager, rsbuildOptions }) {
327
- const normalizedConfig = await (0, shared /* initRsbuildConfig */ .A9)({
184
+ async function initConfigs({ context, pluginManager, rsbuildOptions, helpers }) {
185
+ let normalizedConfig = await helpers.initRsbuildConfig({
328
186
  context,
329
187
  pluginManager
330
- });
331
- const webpackConfigs = await Promise.all(Object.entries(normalizedConfig.environments).map(([environment, config])=>generateWebpackConfig({
188
+ }), webpackConfigs = await Promise.all(Object.entries(normalizedConfig.environments).map(([environment, config])=>generateWebpackConfig({
332
189
  target: config.output.target,
333
190
  context,
334
- environment
191
+ environment,
192
+ helpers
335
193
  })));
336
- // write Rsbuild config and webpack config to disk in debug mode
337
194
  if ('verbose' === core_.logger.level) {
338
- const inspect = ()=>{
339
- const inspectOptions = {
340
- verbose: true,
341
- writeToDisk: true
342
- };
195
+ let inspect = ()=>{
343
196
  inspectConfig({
344
197
  context,
345
198
  pluginManager,
346
- inspectOptions,
199
+ inspectOptions: {
200
+ verbose: !0,
201
+ writeToDisk: !0
202
+ },
347
203
  rsbuildOptions,
348
- bundlerConfigs: webpackConfigs
204
+ bundlerConfigs: webpackConfigs,
205
+ helpers
349
206
  });
350
207
  };
351
- // run inspect later to avoid cleaned by cleanOutput plugin
352
208
  context.hooks.onBeforeBuild.tap(({ isFirstCompile })=>{
353
- if (isFirstCompile) inspect();
354
- });
355
- context.hooks.onAfterStartDevServer.tap(inspect);
209
+ isFirstCompile && inspect();
210
+ }), context.hooks.onAfterStartDevServer.tap(inspect);
356
211
  }
357
212
  return {
358
213
  webpackConfigs
@@ -361,86 +216,65 @@ async function initConfigs({ context, pluginManager, rsbuildOptions }) {
361
216
  async function createCompiler_createCompiler(options) {
362
217
  var _context_normalizedConfig;
363
218
  core_.logger.debug('create compiler');
364
- const { context } = options;
365
- const { webpackConfigs } = await initConfigs(options);
219
+ let { helpers, context } = options, { webpackConfigs } = await initConfigs(options);
366
220
  await context.hooks.onBeforeCreateCompiler.call({
367
221
  bundlerConfigs: webpackConfigs,
368
222
  environments: context.environments
369
223
  });
370
- const { default: webpack } = await import("webpack");
371
- const compiler = 1 === webpackConfigs.length ? webpack(webpackConfigs[0]) : webpack(webpackConfigs);
372
- const done = (stats)=>{
373
- const statsOptions = (0, shared /* getStatsOptions */ .g5)(compiler);
374
- const statsJson = stats.toJson({
375
- children: true,
224
+ let { default: webpack } = await import("webpack"), compiler = webpack(1 === webpackConfigs.length ? webpackConfigs[0] : webpackConfigs), done = (stats)=>{
225
+ let statsOptions = helpers.getStatsOptions(compiler), statsJson = stats.toJson({
226
+ children: !0,
376
227
  ...'string' == typeof statsOptions ? {
377
228
  preset: statsOptions
378
229
  } : {
379
230
  preset: 'errors-warnings'
380
231
  },
381
232
  ...'object' == typeof statsOptions ? statsOptions : {}
382
- });
383
- const { message, level } = (0, shared /* formatStats */ .v1)(statsJson, stats.hasErrors());
384
- if ('error' === level) core_.logger.error(message);
385
- if ('warning' === level) core_.logger.warn(message);
233
+ }), { message, level } = helpers.formatStats(statsJson, stats.hasErrors());
234
+ 'error' === level && core_.logger.error(message), 'warning' === level && core_.logger.warn(message);
386
235
  };
387
- compiler.hooks.done.tap('rsbuild:done', (stats)=>{
236
+ return compiler.hooks.done.tap('rsbuild:done', (stats)=>{
388
237
  done(stats);
389
- });
390
- if ((null === (_context_normalizedConfig = context.normalizedConfig) || void 0 === _context_normalizedConfig ? void 0 : _context_normalizedConfig.mode) === 'development') (0, shared /* registerDevHook */ .xn)({
238
+ }), (null === (_context_normalizedConfig = context.normalizedConfig) || void 0 === _context_normalizedConfig ? void 0 : _context_normalizedConfig.mode) === 'development' && helpers.registerDevHook({
391
239
  compiler,
392
240
  context,
393
241
  bundlerConfigs: webpackConfigs,
394
- MultiStatsCtor: __WEBPACK_EXTERNAL_MODULE_webpack_lib_MultiStats_js__["default"]
395
- });
396
- await context.hooks.onAfterCreateCompiler.call({
242
+ MultiStatsCtor: __WEBPACK_EXTERNAL_MODULE_webpack_lib_MultiStats_js__.default
243
+ }), await context.hooks.onAfterCreateCompiler.call({
397
244
  compiler,
398
245
  environments: context.environments
399
- });
400
- core_.logger.debug('create compiler done');
401
- return {
246
+ }), core_.logger.debug('create compiler done'), {
402
247
  compiler,
403
248
  webpackConfigs
404
249
  };
405
250
  }
406
- const build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
407
- const { context } = initOptions;
408
- let compiler;
409
- let bundlerConfigs;
251
+ let build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
252
+ let compiler, bundlerConfigs;
253
+ let { helpers, context } = initOptions;
410
254
  if (customCompiler) compiler = customCompiler;
411
255
  else {
412
- const result = await createCompiler_createCompiler(initOptions);
413
- compiler = result.compiler;
414
- bundlerConfigs = result.webpackConfigs;
256
+ let result = await createCompiler_createCompiler(initOptions);
257
+ compiler = result.compiler, bundlerConfigs = result.webpackConfigs;
415
258
  }
416
- (0, shared /* registerBuildHook */ .Oo)({
259
+ if (helpers.registerBuildHook({
417
260
  context,
418
261
  bundlerConfigs: bundlerConfigs,
419
262
  compiler,
420
- isWatch: Boolean(watch),
421
- MultiStatsCtor: __WEBPACK_EXTERNAL_MODULE_webpack_lib_MultiStats_js__["default"]
422
- });
423
- if (watch) {
424
- const watching = compiler.watch({}, (err)=>{
425
- if (err) core_.logger.error(err);
426
- });
427
- return {
428
- close: ()=>new Promise((resolve)=>{
429
- watching.close(()=>{
430
- resolve();
431
- });
432
- })
433
- };
434
- }
435
- const { stats } = await new Promise((resolve, reject)=>{
263
+ isWatch: !!watch,
264
+ MultiStatsCtor: __WEBPACK_EXTERNAL_MODULE_webpack_lib_MultiStats_js__.default
265
+ }), watch) return compiler.watch({}, (err)=>{
266
+ err && core_.logger.error(err);
267
+ }), {
268
+ close: ()=>new Promise((resolve)=>{
269
+ compiler.close(()=>{
270
+ resolve();
271
+ });
272
+ })
273
+ };
274
+ let { stats } = await new Promise((resolve, reject)=>{
436
275
  compiler.run((err, stats)=>{
437
- if (err) reject(err);
438
- else if (null == stats ? void 0 : stats.hasErrors()) reject(new Error('Webpack build failed!'));
439
- else // When using run or watch, call close and wait for it to finish before calling run or watch again.
440
- // Concurrent compilations will corrupt the output files.
441
- compiler.close((closeErr)=>{
442
- closeErr && core_.logger.error(closeErr);
443
- resolve({
276
+ err ? reject(err) : (null == stats ? void 0 : stats.hasErrors()) ? reject(Error('Webpack build failed!')) : compiler.close((closeErr)=>{
277
+ closeErr && core_.logger.error(closeErr), resolve({
444
278
  stats
445
279
  });
446
280
  });
@@ -448,157 +282,134 @@ const build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
448
282
  });
449
283
  return {
450
284
  stats,
451
- // This close method is a noop in non-watch mode
452
- // In watch mode, it's defined above to stop watching
453
- close: async ()=>{}
285
+ close: ()=>new Promise((resolve)=>{
286
+ compiler.close(()=>{
287
+ resolve();
288
+ });
289
+ })
454
290
  };
455
291
  };
456
292
  async function applyTsConfigPathsPlugin({ chain, CHAIN_ID, mainFields, extensions, configFile }) {
457
- const { TsconfigPathsPlugin } = await import("tsconfig-paths-webpack-plugin");
293
+ let { TsconfigPathsPlugin } = await import("tsconfig-paths-webpack-plugin");
458
294
  chain.resolve.plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS).use(TsconfigPathsPlugin, [
459
295
  {
460
296
  configFile,
461
297
  extensions,
462
- // https://github.com/dividab/tsconfig-paths-webpack-plugin/pull/106
463
298
  mainFields: mainFields
464
299
  }
465
300
  ]);
466
301
  }
467
- function isWebTarget(target) {
468
- const targets = (0, shared /* castArray */ .XQ)(target);
469
- return targets.includes('web') || target.includes('web-worker');
470
- }
471
- const getMainFields = (chain, target)=>{
472
- const mainFields = chain.resolve.mainFields.values();
302
+ let getMainFields = (chain, target)=>{
303
+ var target1;
304
+ let mainFields = chain.resolve.mainFields.values();
473
305
  if (mainFields.length) return mainFields;
474
- if (isWebTarget(target)) return [
306
+ return castArray(target1 = target).includes('web') || target1.includes('web-worker') ? [
475
307
  'browser',
476
308
  'module',
477
309
  'main'
478
- ];
479
- return [
310
+ ] : [
480
311
  'module',
481
312
  'main'
482
313
  ];
483
- };
484
- /**
485
- * Handling differences between Webpack and Rspack
486
- */ const pluginAdaptor = ()=>({
314
+ }, pluginAdaptor = (helpers)=>({
487
315
  name: 'rsbuild-webpack:adaptor',
488
316
  setup (api) {
489
317
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target })=>{
490
- const { config, tsconfigPath } = environment;
491
- if (tsconfigPath && 'prefer-tsconfig' === config.source.aliasStrategy) await applyTsConfigPathsPlugin({
318
+ let { config, tsconfigPath } = environment;
319
+ tsconfigPath && 'prefer-tsconfig' === config.source.aliasStrategy && await applyTsConfigPathsPlugin({
492
320
  chain,
493
321
  CHAIN_ID,
494
322
  configFile: tsconfigPath,
495
323
  mainFields: getMainFields(chain, target),
496
324
  extensions: chain.resolve.extensions.values()
497
325
  });
498
- // enable progress bar for webpack by default
499
- const progress = config.dev.progressBar ?? true;
326
+ let progress = config.dev.progressBar ?? !0;
500
327
  if (progress) {
501
- const { ProgressPlugin } = await Promise.all(/* import() */ [
328
+ let { ProgressPlugin } = await Promise.all([
502
329
  __webpack_require__.e("997"),
503
330
  __webpack_require__.e("238")
504
331
  ]).then(__webpack_require__.bind(__webpack_require__, "./src/progress/ProgressPlugin.ts"));
505
332
  chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [
506
333
  {
507
334
  id: environment.name,
508
- ...true === progress ? {} : progress
335
+ prettyTime: helpers.prettyTime,
336
+ ...!0 === progress ? {} : progress
509
337
  }
510
338
  ]);
511
339
  }
512
- const { copy } = config.output;
340
+ let { copy } = config.output;
513
341
  if (copy) {
514
- const { default: CopyPlugin } = await import("copy-webpack-plugin");
515
- const options = Array.isArray(copy) ? {
342
+ let { default: CopyPlugin } = await import("copy-webpack-plugin"), options = Array.isArray(copy) ? {
516
343
  patterns: copy
517
344
  } : copy;
518
345
  chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
519
- // @ts-expect-error to type mismatch
520
346
  options
521
347
  ]);
522
348
  }
523
- });
524
- api.modifyWebpackConfig(async (config)=>{
525
- var _config_plugins;
526
- const copyPlugin = null === (_config_plugins = config.plugins) || void 0 === _config_plugins ? void 0 : _config_plugins.find((item)=>(null == item ? void 0 : item.constructor.name) === 'CopyPlugin');
527
- if (copyPlugin) {
528
- // If the pattern.context directory not exists, we should remove CopyPlugin.
529
- // Otherwise the CopyPlugin will cause the webpack to re-compile.
530
- const isContextNotExists = copyPlugin.patterns.every((pattern)=>'string' != typeof pattern && pattern.context && !__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(pattern.context));
531
- if (isContextNotExists) {
532
- var _config_plugins1;
533
- config.plugins = null === (_config_plugins1 = config.plugins) || void 0 === _config_plugins1 ? void 0 : _config_plugins1.filter((item)=>(null == item ? void 0 : item.constructor.name) !== 'CopyPlugin');
534
- }
535
- }
349
+ }), api.modifyWebpackConfig(async (config)=>{
350
+ var _config_plugins, _config_plugins1;
351
+ let copyPlugin = null === (_config_plugins = config.plugins) || void 0 === _config_plugins ? void 0 : _config_plugins.find((item)=>(null == item ? void 0 : item.constructor.name) === 'CopyPlugin');
352
+ copyPlugin && copyPlugin.patterns.every((pattern)=>'string' != typeof pattern && pattern.context && !__WEBPACK_EXTERNAL_MODULE_node_fs__.default.existsSync(pattern.context)) && (config.plugins = null === (_config_plugins1 = config.plugins) || void 0 === _config_plugins1 ? void 0 : _config_plugins1.filter((item)=>(null == item ? void 0 : item.constructor.name) !== 'CopyPlugin'));
536
353
  });
537
354
  }
538
- });
539
- const webpackProvider = async ({ context, pluginManager, rsbuildOptions, setCssExtractPlugin })=>{
540
- const { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
541
- setCssExtractPlugin(cssExtractPlugin);
542
- const createCompiler = async ()=>{
543
- const result = await createCompiler_createCompiler({
355
+ }), webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers })=>{
356
+ let { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
357
+ helpers.setCssExtractPlugin(cssExtractPlugin);
358
+ let createCompiler = async ()=>(await createCompiler_createCompiler({
544
359
  context,
545
360
  pluginManager,
546
- rsbuildOptions
547
- });
548
- return result.compiler;
549
- };
550
- pluginManager.addPlugins([
551
- pluginAdaptor()
552
- ]);
553
- return {
361
+ rsbuildOptions,
362
+ helpers
363
+ })).compiler;
364
+ return pluginManager.addPlugins([
365
+ pluginAdaptor(helpers)
366
+ ]), {
554
367
  bundler: 'webpack',
555
368
  createCompiler,
556
369
  async initConfigs () {
557
- const { webpackConfigs } = await initConfigs({
370
+ let { webpackConfigs } = await initConfigs({
558
371
  context,
559
372
  pluginManager,
560
- rsbuildOptions
373
+ rsbuildOptions,
374
+ helpers
561
375
  });
562
376
  return webpackConfigs;
563
377
  },
564
378
  async createDevServer (options) {
565
- const config = await (0, shared /* initRsbuildConfig */ .A9)({
379
+ let config = await helpers.initRsbuildConfig({
566
380
  context,
567
381
  pluginManager
568
382
  });
569
- return (0, shared /* createDevServer */ .PZ)({
383
+ return helpers.createDevServer({
570
384
  context,
571
385
  pluginManager,
572
386
  rsbuildOptions
573
387
  }, createCompiler, config, options);
574
388
  },
575
389
  async startDevServer (options) {
576
- const config = await (0, shared /* initRsbuildConfig */ .A9)({
390
+ let config = await helpers.initRsbuildConfig({
577
391
  context,
578
392
  pluginManager
579
393
  });
580
- const server = await (0, shared /* createDevServer */ .PZ)({
394
+ return (await helpers.createDevServer({
581
395
  context,
582
396
  pluginManager,
583
397
  rsbuildOptions
584
- }, createCompiler, config, options);
585
- return server.listen();
398
+ }, createCompiler, config, options)).listen();
586
399
  },
587
- async build (options) {
588
- return build({
400
+ build: async (options)=>build({
589
401
  context,
590
402
  pluginManager,
591
- rsbuildOptions
592
- }, options);
593
- },
594
- async inspectConfig (inspectOptions) {
595
- return await inspectConfig({
403
+ rsbuildOptions,
404
+ helpers
405
+ }, options),
406
+ inspectConfig: async (inspectOptions)=>await inspectConfig({
596
407
  context,
597
408
  pluginManager,
598
409
  rsbuildOptions,
599
- inspectOptions
600
- });
601
- }
410
+ inspectOptions,
411
+ helpers
412
+ })
602
413
  };
603
414
  };
604
415
  export { webpackProvider };