@rsbuild/webpack 1.6.0 → 1.6.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.
@@ -1,8 +1,10 @@
1
- export const __webpack_id__ = "0";
2
- export const __webpack_ids__ = [
3
- "0"
4
- ];
5
- export const __webpack_modules__ = {
1
+ import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
2
+ import { __webpack_require__ } from "./rslib-runtime.js";
3
+ import picocolors from "picocolors";
4
+ import webpack from "webpack";
5
+ import { Console } from "node:console";
6
+ import { logger } from "./161.js";
7
+ __webpack_require__.add({
6
8
  "../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js": function(module) {
7
9
  let ansiEscapes = module.exports;
8
10
  module.exports.default = ansiEscapes;
@@ -81,7 +83,7 @@ export const __webpack_modules__ = {
81
83
  };
82
84
  Object.defineProperty(module, 'exports', {
83
85
  enumerable: !0,
84
- get: function() {
86
+ get: function assembleStyles() {
85
87
  let codes = new Map(), styles = {
86
88
  modifier: {
87
89
  reset: [
@@ -412,6 +414,9 @@ export const __webpack_modules__ = {
412
414
  value: labels
413
415
  });
414
416
  }
417
+ function comparativeDistance(x, y) {
418
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
419
+ }
415
420
  convert.rgb.hsl = function(rgb) {
416
421
  let h, r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255, min = Math.min(r, g, b), max = Math.max(r, g, b), delta = max - min;
417
422
  max === min ? h = 0 : r === max ? h = (g - b) / delta : g === max ? h = 2 + (b - r) / delta : b === max && (h = 4 + (r - g) / delta), (h = Math.min(60 * h, 360)) < 0 && (h += 360);
@@ -450,7 +455,7 @@ export const __webpack_modules__ = {
450
455
  if (reversed) return reversed;
451
456
  let currentClosestDistance = 1 / 0;
452
457
  for (let keyword of Object.keys(cssKeywords)){
453
- let value = cssKeywords[keyword], distance = (rgb[0] - value[0]) ** 2 + (rgb[1] - value[1]) ** 2 + (rgb[2] - value[2]) ** 2;
458
+ let distance = comparativeDistance(rgb, cssKeywords[keyword]);
454
459
  distance < currentClosestDistance && (currentClosestDistance = distance, currentClosestKeyword = keyword);
455
460
  }
456
461
  return currentClosestKeyword;
@@ -814,6 +819,24 @@ export const __webpack_modules__ = {
814
819
  },
815
820
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
816
821
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js"), route = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js"), convert = {};
822
+ function wrapRaw(fn) {
823
+ let wrappedFn = function(...args) {
824
+ let arg0 = args[0];
825
+ return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
826
+ };
827
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
828
+ }
829
+ function wrapRounded(fn) {
830
+ let wrappedFn = function(...args) {
831
+ let arg0 = args[0];
832
+ if (null == arg0) return arg0;
833
+ arg0.length > 1 && (args = arg0);
834
+ let result = fn(args);
835
+ if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
836
+ return result;
837
+ };
838
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
839
+ }
817
840
  Object.keys(conversions).forEach((fromModel)=>{
818
841
  convert[fromModel] = {}, Object.defineProperty(convert[fromModel], 'channels', {
819
842
  value: conversions[fromModel].channels
@@ -822,58 +845,52 @@ export const __webpack_modules__ = {
822
845
  });
823
846
  let routes = route(fromModel);
824
847
  Object.keys(routes).forEach((toModel)=>{
825
- let wrappedFn, wrappedFn1, fn = routes[toModel];
826
- convert[fromModel][toModel] = (wrappedFn = function(...args) {
827
- let arg0 = args[0];
828
- if (null == arg0) return arg0;
829
- arg0.length > 1 && (args = arg0);
830
- let result = fn(args);
831
- if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
832
- return result;
833
- }, 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn), convert[fromModel][toModel].raw = (wrappedFn1 = function(...args) {
834
- let arg0 = args[0];
835
- return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
836
- }, 'conversion' in fn && (wrappedFn1.conversion = fn.conversion), wrappedFn1);
848
+ let fn = routes[toModel];
849
+ convert[fromModel][toModel] = wrapRounded(fn), convert[fromModel][toModel].raw = wrapRaw(fn);
837
850
  });
838
851
  }), module.exports = convert;
839
852
  },
840
853
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js": function(module, __unused_webpack_exports, __webpack_require__) {
841
854
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js");
842
- module.exports = function(fromModel) {
843
- let graph = function(fromModel) {
844
- let graph = function() {
845
- let graph = {}, models = Object.keys(conversions);
846
- for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
847
- distance: -1,
848
- parent: null
849
- };
850
- return graph;
851
- }(), queue = [
852
- fromModel
853
- ];
854
- for(graph[fromModel].distance = 0; queue.length;){
855
- let current = queue.pop(), adjacents = Object.keys(conversions[current]);
856
- for(let len = adjacents.length, i = 0; i < len; i++){
857
- let adjacent = adjacents[i], node = graph[adjacent];
858
- -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
859
- }
855
+ function buildGraph() {
856
+ let graph = {}, models = Object.keys(conversions);
857
+ for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
858
+ distance: -1,
859
+ parent: null
860
+ };
861
+ return graph;
862
+ }
863
+ function deriveBFS(fromModel) {
864
+ let graph = buildGraph(), queue = [
865
+ fromModel
866
+ ];
867
+ for(graph[fromModel].distance = 0; queue.length;){
868
+ let current = queue.pop(), adjacents = Object.keys(conversions[current]);
869
+ for(let len = adjacents.length, i = 0; i < len; i++){
870
+ let adjacent = adjacents[i], node = graph[adjacent];
871
+ -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
860
872
  }
861
- return graph;
862
- }(fromModel), conversion = {}, models = Object.keys(graph);
873
+ }
874
+ return graph;
875
+ }
876
+ function link(from, to) {
877
+ return function(args) {
878
+ return to(from(args));
879
+ };
880
+ }
881
+ function wrapConversion(toModel, graph) {
882
+ let path = [
883
+ graph[toModel].parent,
884
+ toModel
885
+ ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
886
+ for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = link(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
887
+ return fn.conversion = path, fn;
888
+ }
889
+ module.exports = function(fromModel) {
890
+ let graph = deriveBFS(fromModel), conversion = {}, models = Object.keys(graph);
863
891
  for(let len = models.length, i = 0; i < len; i++){
864
892
  let toModel = models[i];
865
- null !== graph[toModel].parent && (conversion[toModel] = function(toModel, graph) {
866
- let path = [
867
- graph[toModel].parent,
868
- toModel
869
- ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
870
- for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = function(from, to) {
871
- return function(args) {
872
- return to(from(args));
873
- };
874
- }(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
875
- return fn.conversion = path, fn;
876
- }(toModel, graph));
893
+ null !== graph[toModel].parent && (conversion[toModel] = wrapConversion(toModel, graph));
877
894
  }
878
895
  return conversion;
879
896
  };
@@ -1736,5 +1753,202 @@ export const __webpack_modules__ = {
1736
1753
  "../../../node_modules/.pnpm/strip-ansi@6.0.1/node_modules/strip-ansi/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
1737
1754
  let ansiRegex = __webpack_require__("../../../node_modules/.pnpm/ansi-regex@5.0.1/node_modules/ansi-regex/index.js");
1738
1755
  module.exports = (string)=>'string' == typeof string ? string.replace(ansiRegex(), '') : string;
1756
+ },
1757
+ stream: function(module) {
1758
+ module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
1759
+ }
1760
+ });
1761
+ let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js");
1762
+ var cli_truncate_default = __webpack_require__.n(cli_truncate);
1763
+ let defaultOption = {
1764
+ total: 100,
1765
+ current: 0,
1766
+ color: 'green',
1767
+ bgColor: 'gray',
1768
+ char: '━',
1769
+ width: 25,
1770
+ buildIcon: '◯',
1771
+ errorIcon: '✖',
1772
+ errorInfo: 'compile failed',
1773
+ message: '',
1774
+ done: !1,
1775
+ spaceWidth: 1,
1776
+ messageWidth: 25,
1777
+ messageColor: 'gray',
1778
+ id: '',
1779
+ maxIdLen: 16,
1780
+ hasErrors: !1
1781
+ }, ansi_escapes = __webpack_require__("../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js");
1782
+ var ansi_escapes_default = __webpack_require__.n(ansi_escapes);
1783
+ let build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js");
1784
+ var build_default = __webpack_require__.n(build);
1785
+ let colorList = [
1786
+ 'green',
1787
+ 'cyan',
1788
+ 'yellow',
1789
+ 'blue',
1790
+ 'magenta'
1791
+ ], bus = new class {
1792
+ states = [];
1793
+ log;
1794
+ restore;
1795
+ prevOutput;
1796
+ destroyed = !1;
1797
+ constructor(){
1798
+ var stream;
1799
+ let previousLineCount, previousOutput, render;
1800
+ this.prevOutput = '', this.log = (stream = process.stdout, previousLineCount = 0, previousOutput = '', (render = (str)=>{
1801
+ let output = `${str}\n`;
1802
+ output !== previousOutput && (previousOutput = output, stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output), previousLineCount = output.split('\n').length);
1803
+ }).clear = ()=>{
1804
+ stream.write(ansi_escapes_default().eraseLines(previousLineCount)), previousOutput = '', previousLineCount = 0;
1805
+ }, render.done = ()=>{
1806
+ previousOutput = '', previousLineCount = 0;
1807
+ }, render), console.Console = Console, this.restore = build_default()((type, data)=>{
1808
+ this.writeToStd(type, data);
1809
+ });
1810
+ }
1811
+ update(state) {
1812
+ let index = this.states.findIndex((i)=>i.id === state.id);
1813
+ -1 === index ? this.states.push(state) : this.states[index] = state;
1814
+ }
1815
+ writeToStd(type = 'stdout', data) {
1816
+ this.log.clear(), data && ('stdout' === type ? process.stdout.write(data) : 'stderr' === type && process.stderr.write(data)), this.log(this.prevOutput);
1817
+ }
1818
+ render() {
1819
+ let maxIdLen = Math.max(...this.states.map((i)=>i.id?.length ?? 0)) + 2, { columns = 70 } = process.stdout;
1820
+ this.prevOutput = this.states.map((i, k)=>{
1821
+ let bar = ((option)=>{
1822
+ var id;
1823
+ let left, right, mergedOptions = {
1824
+ ...defaultOption,
1825
+ ...option
1826
+ }, { total, done, buildIcon, errorIcon, errorInfo, width, current, color, bgColor, char, message, messageWidth, spaceWidth, messageColor, maxIdLen, hasErrors } = mergedOptions, space = ' '.repeat(spaceWidth), percent = clamp(Math.floor(current / total * 100), 0, 100), barColor = picocolors[color], backgroundColor = picocolors[bgColor], doneColor = hasErrors ? picocolors.red : barColor, idColor = done ? doneColor : barColor, id1 = mergedOptions.id ? idColor((left = Math.floor((maxIdLen - (id = mergedOptions.id).length) / 2), right = maxIdLen - left - id.length, ' '.repeat(left) + id + ' '.repeat(right))) : '', { columns: terminalWidth = 70 } = process.stdout;
1827
+ if (done) {
1828
+ if (hasErrors) {
1829
+ let message = picocolors.bold(doneColor(errorInfo));
1830
+ return terminalWidth >= 40 ? [
1831
+ idColor(errorIcon),
1832
+ id1,
1833
+ doneColor(`${space}${message}`)
1834
+ ].join('') : [
1835
+ id1,
1836
+ doneColor(`${message}`)
1837
+ ].join('');
1838
+ }
1839
+ return '';
1840
+ }
1841
+ let msgStr = picocolors[messageColor](cli_truncate_default()(message, messageWidth, {
1842
+ position: 'start'
1843
+ })), left1 = clamp(Math.floor(percent * width / 100), 0, width), right1 = clamp(width - left1, 0, width), barStr = `${barColor(char.repeat(left1))}${backgroundColor(char.repeat(right1))}`, percentStr = `${percent.toString().padStart(3)}%`;
1844
+ return terminalWidth >= 70 ? [
1845
+ idColor(buildIcon),
1846
+ id1,
1847
+ space,
1848
+ barStr,
1849
+ space,
1850
+ percentStr,
1851
+ space,
1852
+ msgStr
1853
+ ].join('') : terminalWidth >= 40 ? [
1854
+ idColor(buildIcon),
1855
+ id1,
1856
+ space,
1857
+ barStr,
1858
+ space,
1859
+ percentStr
1860
+ ].join('') : [
1861
+ idColor(buildIcon),
1862
+ id1,
1863
+ space,
1864
+ percentStr
1865
+ ].join('');
1866
+ })({
1867
+ maxIdLen,
1868
+ color: i.color ?? colorList[k % colorList.length],
1869
+ ...i
1870
+ });
1871
+ return bar ? cli_truncate_default()(bar, columns, {
1872
+ position: 'end'
1873
+ }) : null;
1874
+ }).filter((item)=>null !== item).join('\n'), this.writeToStd();
1875
+ }
1876
+ destroy() {
1877
+ this.destroyed || this.restore(), this.destroyed = !0;
1878
+ }
1879
+ clear() {
1880
+ this.log.clear(), this.log.done();
1881
+ }
1882
+ }();
1883
+ function createNonTTYLogger() {
1884
+ let prevPercentage = 0;
1885
+ return {
1886
+ log: ({ id, done, current, hasErrors, compileTime })=>{
1887
+ let suffix = picocolors.gray(`(${id})`);
1888
+ if (done) {
1889
+ if (100 === prevPercentage) return;
1890
+ prevPercentage = 100, hasErrors ? logger.error(`build failed in ${compileTime} ${suffix}`) : logger.ready(`built in ${compileTime} ${suffix}`);
1891
+ } else current - prevPercentage > 10 && (prevPercentage = current, logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
1892
+ }
1893
+ };
1894
+ }
1895
+ class ProgressPlugin extends webpack.ProgressPlugin {
1896
+ name = 'ProgressPlugin';
1897
+ id;
1898
+ hasCompileErrors = !1;
1899
+ compileTime = null;
1900
+ prettyTime;
1901
+ constructor(options){
1902
+ let prevPercentage, { id = 'Rsbuild' } = options, nonTTYLogger = createNonTTYLogger(), friendlyPercentage = (prevPercentage = 0, (percentage)=>{
1903
+ if (0 === percentage || 1 === percentage) return prevPercentage = 0, percentage;
1904
+ if (percentage <= prevPercentage) {
1905
+ let step = 0;
1906
+ return prevPercentage < 0.3 ? step = 0.001 : prevPercentage < 0.6 ? step = 0.002 : prevPercentage < 0.8 ? step = 0.004 : prevPercentage < 0.99 && (step = 0.002), prevPercentage += step;
1907
+ }
1908
+ return prevPercentage = percentage, percentage;
1909
+ });
1910
+ super({
1911
+ activeModules: !1,
1912
+ entries: !0,
1913
+ modules: !0,
1914
+ modulesCount: 5000,
1915
+ profile: !1,
1916
+ dependencies: !0,
1917
+ dependenciesCount: 10000,
1918
+ percentBy: null,
1919
+ handler: (originalPercentage, message)=>{
1920
+ let percentage = friendlyPercentage(originalPercentage), done = 1 === percentage;
1921
+ process.stdout.isTTY ? (bus.update({
1922
+ id,
1923
+ current: 100 * percentage,
1924
+ message,
1925
+ done,
1926
+ hasErrors: this.hasCompileErrors
1927
+ }), bus.render()) : nonTTYLogger.log({
1928
+ id,
1929
+ done,
1930
+ current: 100 * percentage,
1931
+ hasErrors: this.hasCompileErrors,
1932
+ compileTime: this.compileTime
1933
+ });
1934
+ }
1935
+ }), this.id = id, this.prettyTime = options.prettyTime;
1936
+ }
1937
+ apply(compiler) {
1938
+ super.apply(compiler);
1939
+ let startTime = null;
1940
+ compiler.hooks.compile.tap(this.name, ()=>{
1941
+ this.compileTime = null, startTime = process.hrtime();
1942
+ }), compiler.hooks.done.tap(this.name, (stat)=>{
1943
+ if (startTime) {
1944
+ this.hasCompileErrors = stat.hasErrors();
1945
+ let hrtime = process.hrtime(startTime), seconds = hrtime[0] + hrtime[1] / 1e9;
1946
+ if (this.compileTime = this.prettyTime(seconds), startTime = null, !this.hasCompileErrors) {
1947
+ let suffix = this.id ? picocolors.gray(` (${this.id})`) : '';
1948
+ logger.ready(`built in ${this.compileTime} ${suffix}`);
1949
+ }
1950
+ }
1951
+ });
1739
1952
  }
1740
- };
1953
+ }
1954
+ export { ProgressPlugin };
package/dist/161.js ADDED
@@ -0,0 +1,294 @@
1
+ import { logger } from "@rsbuild/core";
2
+ import MultiStats from "webpack/lib/MultiStats.js";
3
+ import { reduceConfigsWithContext } from "reduce-configs";
4
+ import node_fs from "node:fs";
5
+ let castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
6
+ arr
7
+ ];
8
+ async function modifyWebpackChain(context, utils, chain) {
9
+ logger.debug('modify webpack chain');
10
+ let [modifiedChain] = await context.hooks.modifyWebpackChain.callChain({
11
+ environment: utils.environment.name,
12
+ args: [
13
+ chain,
14
+ utils
15
+ ]
16
+ });
17
+ if (utils.environment.config.tools?.webpackChain) for (let item of castArray(utils.environment.config.tools.webpackChain))item(modifiedChain, utils);
18
+ return logger.debug('modify webpack chain done'), modifiedChain;
19
+ }
20
+ async function modifyWebpackConfig(context, webpackConfig, utils) {
21
+ logger.debug('modify webpack config');
22
+ let [modifiedConfig] = await context.hooks.modifyWebpackConfig.callChain({
23
+ environment: utils.environment.name,
24
+ args: [
25
+ webpackConfig,
26
+ utils
27
+ ]
28
+ });
29
+ return utils.environment.config.tools?.webpack && (modifiedConfig = reduceConfigsWithContext({
30
+ initial: modifiedConfig,
31
+ config: utils.environment.config.tools.webpack,
32
+ ctx: utils,
33
+ mergeFn: utils.mergeConfig
34
+ })), logger.debug('modify webpack config done'), modifiedConfig;
35
+ }
36
+ async function getChainUtils(target, environment, environments, helpers) {
37
+ let { default: webpack } = await import("webpack");
38
+ return {
39
+ ...helpers.getChainUtils(target, environment, environments),
40
+ name: ({
41
+ web: 'client',
42
+ node: 'server',
43
+ 'web-worker': 'web-worker'
44
+ })[target] || '',
45
+ webpack,
46
+ HtmlWebpackPlugin: helpers.getHTMLPlugin()
47
+ };
48
+ }
49
+ async function generateWebpackConfig({ target, context, environment, helpers }) {
50
+ let chainUtils = await getChainUtils(target, context.environments[environment], context.environments, helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
51
+ ...chainUtils,
52
+ bundler: {
53
+ BannerPlugin,
54
+ DefinePlugin,
55
+ IgnorePlugin,
56
+ ProvidePlugin,
57
+ SourceMapDevToolPlugin,
58
+ HotModuleReplacementPlugin
59
+ }
60
+ }), webpackConfig = (await modifyWebpackChain(context, chainUtils, bundlerChain)).toConfig(), configUtils = helpers.getConfigUtils(()=>webpackConfig, chainUtils);
61
+ return webpackConfig = await modifyWebpackConfig(context, webpackConfig, configUtils);
62
+ }
63
+ async function initConfigs({ context, pluginManager, rsbuildOptions, helpers }) {
64
+ let normalizedConfig = await helpers.initRsbuildConfig({
65
+ context,
66
+ pluginManager
67
+ }), webpackConfigs = await Promise.all(Object.entries(normalizedConfig.environments).map(([environment, config])=>generateWebpackConfig({
68
+ target: config.output.target,
69
+ context,
70
+ environment,
71
+ helpers
72
+ })));
73
+ if ('verbose' === logger.level) {
74
+ let inspect = async ()=>{
75
+ await helpers.inspectConfig({
76
+ context,
77
+ bundler: 'webpack',
78
+ pluginManager,
79
+ inspectOptions: {
80
+ verbose: !0,
81
+ writeToDisk: !0
82
+ },
83
+ rsbuildOptions,
84
+ bundlerConfigs: webpackConfigs
85
+ });
86
+ };
87
+ context.hooks.onBeforeBuild.tap(async ({ isFirstCompile })=>{
88
+ isFirstCompile && await inspect();
89
+ }), context.hooks.onAfterStartDevServer.tap(inspect);
90
+ }
91
+ return {
92
+ webpackConfigs
93
+ };
94
+ }
95
+ async function createCompiler_createCompiler(options) {
96
+ logger.debug('creating compiler');
97
+ let HOOK_NAME = 'rsbuild:compiler', { helpers, context } = options, { webpackConfigs } = await initConfigs(options);
98
+ await context.hooks.onBeforeCreateCompiler.callBatch({
99
+ bundlerConfigs: webpackConfigs,
100
+ environments: context.environments
101
+ });
102
+ let { default: webpack } = await import("webpack"), compiler = webpack(1 === webpackConfigs.length ? webpackConfigs[0] : webpackConfigs);
103
+ return compiler.hooks.run.tap(HOOK_NAME, ()=>{
104
+ context.buildState.status = 'building';
105
+ }), compiler.hooks.watchRun.tap(HOOK_NAME, ()=>{
106
+ context.buildState.status = 'building';
107
+ }), compiler.hooks.invalid.tap(HOOK_NAME, ()=>{
108
+ context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1;
109
+ }), compiler.hooks.done.tap(HOOK_NAME, (statsInstance)=>{
110
+ let stats = helpers.getRsbuildStats(statsInstance, compiler, context.action), hasErrors = statsInstance.hasErrors();
111
+ context.buildState.stats = stats, context.buildState.status = 'done', context.buildState.hasErrors = hasErrors, context.socketServer?.onBuildDone();
112
+ let { message, level } = helpers.formatStats(stats, hasErrors);
113
+ 'error' === level ? logger.error(message) : 'warning' === level && logger.warn(message);
114
+ }), 'dev' === context.action && helpers.registerDevHook({
115
+ compiler,
116
+ context,
117
+ bundlerConfigs: webpackConfigs,
118
+ MultiStatsCtor: MultiStats
119
+ }), await context.hooks.onAfterCreateCompiler.callBatch({
120
+ compiler,
121
+ environments: context.environments
122
+ }), logger.debug('compiler created'), {
123
+ compiler,
124
+ webpackConfigs
125
+ };
126
+ }
127
+ let build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
128
+ let compiler, bundlerConfigs, { helpers, context } = initOptions;
129
+ if (customCompiler) compiler = customCompiler, bundlerConfigs = customCompiler.options;
130
+ else {
131
+ let result = await createCompiler_createCompiler(initOptions);
132
+ compiler = result.compiler, bundlerConfigs = result.webpackConfigs;
133
+ }
134
+ if (helpers.registerBuildHook({
135
+ context,
136
+ bundlerConfigs: bundlerConfigs,
137
+ compiler,
138
+ isWatch: !!watch,
139
+ MultiStatsCtor: MultiStats
140
+ }), watch) return compiler.watch({}, (err)=>{
141
+ err && logger.error(err);
142
+ }), {
143
+ close: ()=>new Promise((resolve)=>{
144
+ compiler.close(()=>{
145
+ resolve();
146
+ });
147
+ })
148
+ };
149
+ let { stats } = await new Promise((resolve, reject)=>{
150
+ compiler.run((err, stats)=>{
151
+ err ? reject(err) : context.buildState.hasErrors ? reject(Error('webpack build failed.')) : compiler.close((closeErr)=>{
152
+ closeErr && logger.error(closeErr), resolve({
153
+ stats
154
+ });
155
+ });
156
+ });
157
+ });
158
+ return {
159
+ stats,
160
+ close: async ()=>{}
161
+ };
162
+ };
163
+ async function applyTsConfigPathsPlugin({ chain, CHAIN_ID, mainFields, extensions, configFile }) {
164
+ let { TsconfigPathsPlugin } = await import("tsconfig-paths-webpack-plugin");
165
+ chain.resolve.plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS).use(TsconfigPathsPlugin, [
166
+ {
167
+ configFile,
168
+ extensions,
169
+ mainFields: mainFields
170
+ }
171
+ ]);
172
+ }
173
+ function isWebTarget(target) {
174
+ return castArray(target).includes('web') || target.includes('web-worker');
175
+ }
176
+ let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers })=>{
177
+ let { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
178
+ if (helpers.setCssExtractPlugin(cssExtractPlugin), helpers.setHTMLPlugin) {
179
+ let { default: htmlPlugin } = await import("html-webpack-plugin");
180
+ helpers.setHTMLPlugin(htmlPlugin);
181
+ }
182
+ let createCompiler = async ()=>(await createCompiler_createCompiler({
183
+ context,
184
+ pluginManager,
185
+ rsbuildOptions,
186
+ helpers
187
+ })).compiler;
188
+ return pluginManager.addPlugins([
189
+ {
190
+ name: 'rsbuild-webpack:adaptor',
191
+ setup (api) {
192
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target })=>{
193
+ let mainFields, { config, tsconfigPath } = environment, aliasStrategy = config.source.aliasStrategy ?? config.resolve.aliasStrategy;
194
+ tsconfigPath && 'prefer-tsconfig' === aliasStrategy && await applyTsConfigPathsPlugin({
195
+ chain,
196
+ CHAIN_ID,
197
+ configFile: tsconfigPath,
198
+ mainFields: (mainFields = chain.resolve.mainFields.values()).length ? mainFields : isWebTarget(target) ? [
199
+ 'browser',
200
+ 'module',
201
+ 'main'
202
+ ] : [
203
+ 'module',
204
+ 'main'
205
+ ],
206
+ extensions: chain.resolve.extensions.values()
207
+ });
208
+ let { progressBar } = config.dev;
209
+ if (progressBar) {
210
+ let { ProgressPlugin } = await import("./0~999.js").then((mod)=>({
211
+ ProgressPlugin: mod.ProgressPlugin
212
+ }));
213
+ chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [
214
+ {
215
+ id: environment.name,
216
+ prettyTime: helpers.prettyTime,
217
+ ...!0 === progressBar ? {} : progressBar
218
+ }
219
+ ]);
220
+ }
221
+ let { copy } = config.output;
222
+ if (copy) {
223
+ let { default: CopyPlugin } = await import("copy-webpack-plugin"), options = Array.isArray(copy) ? {
224
+ patterns: copy
225
+ } : copy;
226
+ chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
227
+ options
228
+ ]);
229
+ }
230
+ }), api.modifyWebpackConfig(async (config)=>{
231
+ let copyPlugin = config.plugins?.find((item)=>item?.constructor.name === 'CopyPlugin');
232
+ copyPlugin && copyPlugin.patterns.every((pattern)=>'string' != typeof pattern && pattern.context && !node_fs.existsSync(pattern.context)) && (config.plugins = config.plugins?.filter((item)=>item?.constructor.name !== 'CopyPlugin'));
233
+ });
234
+ }
235
+ }
236
+ ]), {
237
+ bundler: 'webpack',
238
+ createCompiler,
239
+ async initConfigs () {
240
+ let { webpackConfigs } = await initConfigs({
241
+ context,
242
+ pluginManager,
243
+ rsbuildOptions,
244
+ helpers
245
+ });
246
+ return webpackConfigs;
247
+ },
248
+ async createDevServer (options) {
249
+ let config = await helpers.initRsbuildConfig({
250
+ context,
251
+ pluginManager
252
+ });
253
+ return helpers.createDevServer({
254
+ context,
255
+ pluginManager,
256
+ rsbuildOptions
257
+ }, createCompiler, config, options);
258
+ },
259
+ async startDevServer (options) {
260
+ let config = await helpers.initRsbuildConfig({
261
+ context,
262
+ pluginManager
263
+ });
264
+ return (await helpers.createDevServer({
265
+ context,
266
+ pluginManager,
267
+ rsbuildOptions
268
+ }, createCompiler, config, options)).listen();
269
+ },
270
+ build: async (options)=>build({
271
+ context,
272
+ pluginManager,
273
+ rsbuildOptions,
274
+ helpers
275
+ }, options),
276
+ async inspectConfig (inspectOptions) {
277
+ let bundlerConfigs = (await initConfigs({
278
+ context,
279
+ pluginManager,
280
+ rsbuildOptions,
281
+ helpers
282
+ })).webpackConfigs;
283
+ return await helpers.inspectConfig({
284
+ context,
285
+ pluginManager,
286
+ bundler: 'webpack',
287
+ bundlerConfigs,
288
+ rsbuildOptions,
289
+ inspectOptions
290
+ });
291
+ }
292
+ };
293
+ };
294
+ export { logger, webpackProvider };