@workleap/webpack-configs 1.5.2 → 1.5.4

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 (42) hide show
  1. package/CHANGELOG.md +35 -23
  2. package/README.md +2 -2
  3. package/dist/build.d.ts +18 -19
  4. package/dist/build.js +219 -3
  5. package/dist/build.js.map +1 -0
  6. package/dist/dev.d.ts +16 -17
  7. package/dist/dev.js +208 -3
  8. package/dist/dev.js.map +1 -0
  9. package/dist/index.d.ts +6 -12
  10. package/dist/index.js +15 -7
  11. package/dist/index.js.map +1 -0
  12. package/dist/transformers/applyTransformers.d.ts +4 -7
  13. package/dist/transformers/applyTransformers.js +20 -1
  14. package/dist/transformers/applyTransformers.js.map +1 -0
  15. package/dist/transformers/moduleRules.d.ts +15 -17
  16. package/dist/transformers/moduleRules.js +166 -1
  17. package/dist/transformers/moduleRules.js.map +1 -0
  18. package/dist/transformers/plugins.d.ts +11 -14
  19. package/dist/transformers/plugins.js +69 -1
  20. package/dist/transformers/plugins.js.map +1 -0
  21. package/dist/types.d.ts +1 -1
  22. package/dist/types.js +6 -1
  23. package/dist/types.js.map +1 -0
  24. package/dist/utils.d.ts +4 -6
  25. package/dist/utils.js +22 -1
  26. package/dist/utils.js.map +1 -0
  27. package/package.json +21 -24
  28. package/src/build.ts +240 -0
  29. package/src/dev.ts +233 -0
  30. package/src/index.ts +7 -0
  31. package/src/transformers/applyTransformers.ts +28 -0
  32. package/src/transformers/moduleRules.ts +229 -0
  33. package/src/transformers/plugins.ts +102 -0
  34. package/src/types.ts +1 -0
  35. package/src/utils.ts +19 -0
  36. package/dist/chunk-2YARCRX5.js +0 -15
  37. package/dist/chunk-34O5ZLZ6.js +0 -154
  38. package/dist/chunk-5ACA7GOB.js +0 -17
  39. package/dist/chunk-6F4PWJZI.js +0 -1
  40. package/dist/chunk-CW54GSNS.js +0 -197
  41. package/dist/chunk-JPURRV2F.js +0 -71
  42. package/dist/chunk-JU2EHEXW.js +0 -186
package/dist/dev.js CHANGED
@@ -1,3 +1,208 @@
1
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-JU2EHEXW.js';
2
- import './chunk-2YARCRX5.js';
3
- import './chunk-5ACA7GOB.js';
1
+ import * as __WEBPACK_EXTERNAL_MODULE__pmmmwh_react_refresh_webpack_plugin_143c1848__ from "@pmmmwh/react-refresh-webpack-plugin";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_html_webpack_plugin_e07f62c9__ from "html-webpack-plugin";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_webpack__ from "webpack";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__transformers_applyTransformers_js_6bf4bd94__ from "./transformers/applyTransformers.js";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
8
+ import * as __WEBPACK_EXTERNAL_MODULE_webpack_dev_server_0dd3124e__ from "webpack-dev-server";
9
+
10
+ ;// CONCATENATED MODULE: external "@pmmmwh/react-refresh-webpack-plugin"
11
+
12
+ ;// CONCATENATED MODULE: external "html-webpack-plugin"
13
+
14
+ ;// CONCATENATED MODULE: external "node:module"
15
+
16
+ ;// CONCATENATED MODULE: external "node:path"
17
+
18
+ ;// CONCATENATED MODULE: external "webpack"
19
+
20
+ ;// CONCATENATED MODULE: external "./transformers/applyTransformers.js"
21
+
22
+ ;// CONCATENATED MODULE: external "./utils.js"
23
+
24
+ ;// CONCATENATED MODULE: external "webpack-dev-server"
25
+
26
+ ;// CONCATENATED MODULE: ./src/dev.ts?__rslib_entry__
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ // Add the "devServer" option to WebpackConfig typings.
35
+
36
+ // Aliases
37
+ const DefinePlugin = __WEBPACK_EXTERNAL_MODULE_webpack__["default"].DefinePlugin;
38
+ // Using node:module.createRequire until
39
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve
40
+ // is available
41
+ const dev_rslib_entry_require = (0,__WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
42
+ function defineDevHtmlWebpackPluginConfig(options = {}) {
43
+ const { template = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve("./public/index.html"), ...rest } = options;
44
+ return {
45
+ ...rest,
46
+ template
47
+ };
48
+ }
49
+ function defineFastRefreshPluginConfig(options = {}) {
50
+ return options;
51
+ }
52
+ function preflight() {
53
+ if (!dev_rslib_entry_require.resolve("webpack-dev-server")) {
54
+ throw new Error("[webpack-configs] To use the \"dev\" config, install https://www.npmjs.com/package/webpack-dev-server as a \"devDependency\".");
55
+ }
56
+ }
57
+ function trySetSwcFastRefresh(config, enabled) {
58
+ if (config?.jsc?.transform?.react) {
59
+ config.jsc.transform.react.refresh = enabled;
60
+ }
61
+ return config;
62
+ }
63
+ function trySetFastRefreshOverlay(options, overlay) {
64
+ if (overlay === false && (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isNil)(options.overlay)) {
65
+ options.overlay = false;
66
+ }
67
+ return options;
68
+ }
69
+ function defineDevConfig(swcConfig, options = {}) {
70
+ preflight();
71
+ const { entry = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve("./src/index.tsx"), https = false, host = "localhost", port = 8080, publicPath, cache = true, moduleRules = [], plugins = [], htmlWebpackPlugin = defineDevHtmlWebpackPluginConfig(), fastRefresh = true, cssModules = false, overlay, svgr = true, // Using an empty object literal as the default value to ensure
72
+ // "process.env" is always available.
73
+ environmentVariables = {}, transformers = [], verbose = false } = options;
74
+ const config = {
75
+ mode: "development",
76
+ target: "web",
77
+ devtool: "eval-cheap-module-source-map",
78
+ devServer: {
79
+ // According to the Fast Refresh plugin documentation, hot should be "true" to enable Fast Refresh:
80
+ // https://github.com/pmmmwh/react-refresh-webpack-plugin#usage.
81
+ hot: true,
82
+ host,
83
+ port,
84
+ historyApiFallback: true,
85
+ client: overlay === false || fastRefresh ? {
86
+ overlay: false
87
+ } : undefined,
88
+ server: https ? {
89
+ type: "https",
90
+ options: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isObject)(https) ? https : undefined
91
+ } : undefined
92
+ },
93
+ entry,
94
+ output: {
95
+ // The trailing / is very important, otherwise paths will not be resolved correctly.
96
+ publicPath: publicPath ?? `${https ? "https" : "http"}://${host}:${port}/`
97
+ },
98
+ cache: cache && {
99
+ type: "memory",
100
+ maxGenerations: 1
101
+ },
102
+ // See: https://webpack.js.org/guides/build-performance/#avoid-extra-optimization-steps
103
+ optimization: {
104
+ // Keep "runtimeChunk" to false, otherwise it breaks module federation
105
+ // (at least for the remote application).
106
+ runtimeChunk: false,
107
+ removeAvailableModules: false,
108
+ removeEmptyChunks: false,
109
+ splitChunks: false
110
+ },
111
+ infrastructureLogging: verbose ? {
112
+ appendOnly: true,
113
+ level: "verbose",
114
+ debug: /PackFileCache/
115
+ } : undefined,
116
+ module: {
117
+ rules: [
118
+ {
119
+ test: /\.(js|jsx|ts|tsx)$/i,
120
+ exclude: /node_modules/,
121
+ loader: dev_rslib_entry_require.resolve("swc-loader"),
122
+ options: trySetSwcFastRefresh(swcConfig, fastRefresh !== false)
123
+ },
124
+ {
125
+ // https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten
126
+ test: /\.js$/i,
127
+ include: /node_modules/,
128
+ resolve: {
129
+ fullySpecified: false
130
+ }
131
+ },
132
+ {
133
+ test: /\.css$/i,
134
+ use: [
135
+ {
136
+ loader: dev_rslib_entry_require.resolve("style-loader")
137
+ },
138
+ {
139
+ loader: dev_rslib_entry_require.resolve("css-loader"),
140
+ options: cssModules ? {
141
+ // Must match the number of loaders applied before this one.
142
+ importLoaders: 1,
143
+ modules: true
144
+ } : undefined
145
+ },
146
+ {
147
+ loader: dev_rslib_entry_require.resolve("postcss-loader")
148
+ }
149
+ ]
150
+ },
151
+ ...svgr ? [
152
+ {
153
+ test: /\.svg$/i,
154
+ loader: dev_rslib_entry_require.resolve("@svgr/webpack"),
155
+ options: (0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isObject)(svgr) ? svgr : undefined
156
+ },
157
+ {
158
+ test: /\.(png|jpe?g|gif)$/i,
159
+ type: "asset/resource"
160
+ }
161
+ ] : [
162
+ {
163
+ test: /\.(png|jpe?g|gif|svg)$/i,
164
+ type: "asset/resource"
165
+ }
166
+ ],
167
+ ...moduleRules
168
+ ]
169
+ },
170
+ resolve: {
171
+ extensions: [
172
+ ".js",
173
+ ".jsx",
174
+ ".ts",
175
+ ".tsx",
176
+ ".css"
177
+ ],
178
+ alias: {
179
+ // Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.
180
+ // View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.
181
+ "@swc/helpers": __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(dev_rslib_entry_require.resolve("@swc/helpers/package.json"))
182
+ }
183
+ },
184
+ plugins: [
185
+ htmlWebpackPlugin && new __WEBPACK_EXTERNAL_MODULE_html_webpack_plugin_e07f62c9__["default"]((0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isObject)(htmlWebpackPlugin) ? htmlWebpackPlugin : defineDevHtmlWebpackPluginConfig()),
186
+ // Stringify the environment variables because the plugin does a direct text replacement. Otherwise, "production" would become production
187
+ // after replacement and cause an undefined var error.
188
+ // For more information, view: https://webpack.js.org/plugins/define-plugin/.
189
+ new DefinePlugin({
190
+ "process.env": Object.keys(environmentVariables).reduce((acc, key)=>{
191
+ acc[key] = JSON.stringify(environmentVariables[key]);
192
+ return acc;
193
+ }, {})
194
+ }),
195
+ fastRefresh && new __WEBPACK_EXTERNAL_MODULE__pmmmwh_react_refresh_webpack_plugin_143c1848__["default"](trySetFastRefreshOverlay((0,__WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isObject)(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig(), overlay)),
196
+ ...plugins
197
+ ].filter(Boolean)
198
+ };
199
+ const transformedConfig = (0,__WEBPACK_EXTERNAL_MODULE__transformers_applyTransformers_js_6bf4bd94__.applyTransformers)(config, transformers, {
200
+ environment: "dev",
201
+ verbose
202
+ });
203
+ return transformedConfig;
204
+ }
205
+
206
+ export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig };
207
+
208
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sources":["webpack://@workleap/webpack-configs/./src/dev.ts"],"sourcesContent":["import ReactRefreshWebpackPlugin from \"@pmmmwh/react-refresh-webpack-plugin\";\nimport type { ReactRefreshPluginOptions } from \"@pmmmwh/react-refresh-webpack-plugin/types/lib/types.d.ts\";\nimport type { Config as SvgrOptions } from \"@svgr/core\";\nimport type { Config as SwcConfig } from \"@swc/core\";\nimport HtmlWebpackPlugin from \"html-webpack-plugin\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport webpack from \"webpack\";\nimport type { ServerOptions } from \"webpack-dev-server\";\nimport { applyTransformers, type WebpackConfigTransformer } from \"./transformers/applyTransformers.ts\";\nimport { isNil, isObject } from \"./utils.ts\";\n\n// Add the \"devServer\" option to WebpackConfig typings.\nimport \"webpack-dev-server\";\nimport type { WebpackConfig } from \"./types.ts\";\n\n// Aliases\nconst DefinePlugin = webpack.DefinePlugin;\n\n// Using node:module.createRequire until\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve\n// is available\nconst require = createRequire(import.meta.url);\n\nexport function defineDevHtmlWebpackPluginConfig(options: HtmlWebpackPlugin.Options = {}): HtmlWebpackPlugin.Options {\n const {\n template = path.resolve(\"./public/index.html\"),\n ...rest\n } = options;\n\n return {\n ...rest,\n template\n };\n}\n\nexport function defineFastRefreshPluginConfig(options: ReactRefreshPluginOptions = {}) {\n return options;\n}\n\nexport interface DefineDevConfigOptions {\n entry?: string;\n https?: boolean | ServerOptions | undefined;\n host?: string;\n port?: number;\n publicPath?: `${string}/` | \"auto\";\n cache?: boolean;\n moduleRules?: NonNullable<WebpackConfig[\"module\"]>[\"rules\"];\n plugins?: WebpackConfig[\"plugins\"];\n htmlWebpackPlugin?: boolean | HtmlWebpackPlugin.Options;\n fastRefresh?: boolean | ReactRefreshPluginOptions;\n cssModules?: boolean;\n overlay?: false;\n svgr?: boolean | SvgrOptions;\n environmentVariables?: Record<string, unknown>;\n transformers?: WebpackConfigTransformer[];\n verbose?: boolean;\n}\n\nfunction preflight() {\n if (!require.resolve(\"webpack-dev-server\")) {\n throw new Error(\"[webpack-configs] To use the \\\"dev\\\" config, install https://www.npmjs.com/package/webpack-dev-server as a \\\"devDependency\\\".\");\n }\n}\n\nfunction trySetSwcFastRefresh(config: SwcConfig, enabled: boolean) {\n if (config?.jsc?.transform?.react) {\n config.jsc.transform.react.refresh = enabled;\n }\n\n return config;\n}\n\nfunction trySetFastRefreshOverlay(options: ReactRefreshPluginOptions, overlay?: boolean) {\n if (overlay === false && isNil(options.overlay)) {\n options.overlay = false;\n }\n\n return options;\n}\n\nexport function defineDevConfig(swcConfig: SwcConfig, options: DefineDevConfigOptions = {}) {\n preflight();\n\n const {\n entry = path.resolve(\"./src/index.tsx\"),\n https = false,\n host = \"localhost\",\n port = 8080,\n publicPath,\n cache = true,\n moduleRules = [],\n plugins = [],\n htmlWebpackPlugin = defineDevHtmlWebpackPluginConfig(),\n fastRefresh = true,\n cssModules = false,\n overlay,\n svgr = true,\n // Using an empty object literal as the default value to ensure\n // \"process.env\" is always available.\n environmentVariables = {},\n transformers = [],\n verbose = false\n } = options;\n\n const config: WebpackConfig = {\n mode: \"development\",\n target: \"web\",\n devtool: \"eval-cheap-module-source-map\",\n devServer: {\n // According to the Fast Refresh plugin documentation, hot should be \"true\" to enable Fast Refresh:\n // https://github.com/pmmmwh/react-refresh-webpack-plugin#usage.\n hot: true,\n host,\n port,\n historyApiFallback: true,\n client: (overlay === false || fastRefresh) ? {\n overlay: false\n } : undefined,\n server: https ? {\n type: \"https\",\n options: isObject(https) ? https : undefined\n } : undefined\n },\n entry,\n output: {\n // The trailing / is very important, otherwise paths will not be resolved correctly.\n publicPath: publicPath ?? `${https ? \"https\" : \"http\"}://${host}:${port}/`\n },\n cache: cache && {\n type: \"memory\",\n maxGenerations: 1\n },\n // See: https://webpack.js.org/guides/build-performance/#avoid-extra-optimization-steps\n optimization: {\n // Keep \"runtimeChunk\" to false, otherwise it breaks module federation\n // (at least for the remote application).\n runtimeChunk: false,\n removeAvailableModules: false,\n removeEmptyChunks: false,\n splitChunks: false\n },\n infrastructureLogging: verbose ? {\n appendOnly: true,\n level: \"verbose\",\n debug: /PackFileCache/\n } : undefined,\n module: {\n rules: [\n {\n test: /\\.(js|jsx|ts|tsx)$/i,\n exclude: /node_modules/,\n loader: require.resolve(\"swc-loader\"),\n options: trySetSwcFastRefresh(swcConfig, fastRefresh !== false)\n },\n {\n // https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten\n test: /\\.js$/i,\n include: /node_modules/,\n resolve: {\n fullySpecified: false\n }\n },\n {\n test: /\\.css$/i,\n use: [\n { loader: require.resolve(\"style-loader\") },\n {\n loader: require.resolve(\"css-loader\"),\n options: cssModules\n ? {\n // Must match the number of loaders applied before this one.\n importLoaders: 1,\n modules: true\n }\n : undefined\n },\n { loader: require.resolve(\"postcss-loader\") }\n ]\n },\n ...(svgr\n ? [\n {\n test: /\\.svg$/i,\n loader: require.resolve(\"@svgr/webpack\"),\n options: isObject(svgr) ? svgr : undefined\n },\n {\n test: /\\.(png|jpe?g|gif)$/i,\n type: \"asset/resource\"\n }\n ]\n : [\n {\n test: /\\.(png|jpe?g|gif|svg)$/i,\n type: \"asset/resource\"\n }\n ]),\n ...moduleRules\n ]\n },\n resolve: {\n extensions: [\".js\", \".jsx\", \".ts\", \".tsx\", \".css\"],\n alias: {\n // Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.\n // View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.\n \"@swc/helpers\": path.dirname(require.resolve(\"@swc/helpers/package.json\"))\n }\n },\n plugins: [\n htmlWebpackPlugin && new HtmlWebpackPlugin(isObject(htmlWebpackPlugin) ? htmlWebpackPlugin : defineDevHtmlWebpackPluginConfig()),\n // Stringify the environment variables because the plugin does a direct text replacement. Otherwise, \"production\" would become production\n // after replacement and cause an undefined var error.\n // For more information, view: https://webpack.js.org/plugins/define-plugin/.\n new DefinePlugin({\n \"process.env\": Object.keys(environmentVariables).reduce((acc, key) => {\n acc[key] = JSON.stringify(environmentVariables[key]);\n\n return acc;\n }, {} as Record<string, string>)\n }),\n fastRefresh && new ReactRefreshWebpackPlugin(trySetFastRefreshOverlay(isObject(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig(), overlay)),\n ...plugins\n ].filter(Boolean)\n };\n\n const transformedConfig = applyTransformers(config, transformers, {\n environment: \"dev\",\n verbose\n });\n\n return transformedConfig;\n}\n"],"names":["ReactRefreshWebpackPlugin","HtmlWebpackPlugin","createRequire","path","webpack","applyTransformers","isNil","isObject","DefinePlugin","require","defineDevHtmlWebpackPluginConfig","options","template","rest","defineFastRefreshPluginConfig","preflight","Error","trySetSwcFastRefresh","config","enabled","trySetFastRefreshOverlay","overlay","defineDevConfig","swcConfig","entry","https","host","port","publicPath","cache","moduleRules","plugins","htmlWebpackPlugin","fastRefresh","cssModules","svgr","environmentVariables","transformers","verbose","undefined","Object","acc","key","JSON","Boolean","transformedConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAA6E;AAIzB;AACR;AACf;AACC;AAEyE;AAC1D;AAE7C,uDAAuD;AAC3B;AAG5B,UAAU;AACV,MAAM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,2DAAQA,CAAC4B,QAAQA,OAAOI;oBACrC;oBACA;wBACI,MAAM;wBACN,MAAM;oBACV;iBACH,GACC;oBACE;wBACI,MAAM;wBACN,MAAM;oBACV;iBACH;mBACFT;aACN;QACL;QACA,SAAS;YACL,YAAY;gBAAC;gBAAO;gBAAQ;gBAAO;gBAAQ;aAAO;YAClD,OAAO;gBACH,2FAA2F;gBAC3F,6HAA6H;gBAC7H,gBAAgB3B,iEAAY,CAACM,uBAAOA,CAAC,OAAO,CAAC;YACjD;QACJ;QACA,SAAS;YACLuB,qBAAqB,IAAI/B,mEAAiBA,CAACM,2DAAQA,CAACyB,qBAAqBA,oBAAoBtB;YAC7F,yIAAyI;YACzI,sDAAsD;YACtD,6EAA6E;YAC7E,IAAIF,aAAa;gBACb,eAAegC,OAAO,IAAI,CAACJ,sBAAsB,MAAM,CAAC,CAACK,KAAKC;oBAC1DD,GAAG,CAACC,IAAI,GAAGC,KAAK,SAAS,CAACP,oBAAoB,CAACM,IAAI;oBAEnD,OAAOD;gBACX,GAAG,CAAC;YACR;YACAR,eAAe,IAAIjC,oFAAyBA,CAACoB,yBAAyBb,2DAAQA,CAAC0B,eAAeA,cAAcnB,iCAAiCO;eAC1IU;SACN,CAAC,MAAM,CAACa;IACb;IAEA,MAAMC,oBAAoBxC,6FAAiBA,CAACa,QAAQmB,cAAc;QAC9D,aAAa;QACbC;IACJ;IAEA,OAAOO;AACX"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- export { DefineBuildConfigOptions, OptimizeOption, WebpackOptimization, defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig, getOptimizationConfig } from './build.js';
2
- export { DefineDevConfigOptions, defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './dev.js';
3
- export { WebpackConfigTransformer, WebpackConfigTransformerContext } from './transformers/applyTransformers.js';
4
- export { AssetModuleType, ModuleRuleMatch, ModuleRuleMatcher, WithModuleRuleMatcherInfo, addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './transformers/moduleRules.js';
5
- export { PluginMatch, PluginMatcher, WebpackPlugin, WithPluginMatcherInfo, addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from './transformers/plugins.js';
6
- export { Configuration as WebpackConfig } from 'webpack';
7
- import '@svgr/core';
8
- import '@swc/core';
9
- import 'html-webpack-plugin';
10
- import 'mini-css-extract-plugin';
11
- import '@pmmmwh/react-refresh-webpack-plugin/types/lib/types.d.ts';
12
- import 'webpack-dev-server';
1
+ export * from "./build.ts";
2
+ export * from "./dev.ts";
3
+ export type { WebpackConfigTransformer, WebpackConfigTransformerContext } from "./transformers/applyTransformers.ts";
4
+ export * from "./transformers/moduleRules.ts";
5
+ export * from "./transformers/plugins.ts";
6
+ export * from "./types.ts";
package/dist/index.js CHANGED
@@ -1,7 +1,15 @@
1
- export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig, getOptimizationConfig } from './chunk-CW54GSNS.js';
2
- export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig } from './chunk-JU2EHEXW.js';
3
- import './chunk-6F4PWJZI.js';
4
- import './chunk-2YARCRX5.js';
5
- import './chunk-5ACA7GOB.js';
6
- export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from './chunk-34O5ZLZ6.js';
7
- export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin } from './chunk-JPURRV2F.js';
1
+ export * from "./build.js";
2
+ export * from "./dev.js";
3
+ export * from "./transformers/moduleRules.js";
4
+ export * from "./transformers/plugins.js";
5
+ export * from "./types.js";
6
+
7
+ ;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["webpack://@workleap/webpack-configs/./src/index.ts"],"sourcesContent":["export * from \"./build.ts\";\nexport * from \"./dev.ts\";\nexport type { WebpackConfigTransformer, WebpackConfigTransformerContext } from \"./transformers/applyTransformers.ts\";\nexport * from \"./transformers/moduleRules.ts\";\nexport * from \"./transformers/plugins.ts\";\nexport * from \"./types.ts\";\n\n"],"names":[],"mappings":";;;;;;;AAA2B;AACF;AAEqB;AACJ;AACf"}
@@ -1,10 +1,7 @@
1
- import { Configuration } from 'webpack';
2
-
3
- interface WebpackConfigTransformerContext {
1
+ import type { WebpackConfig } from "../types.ts";
2
+ export interface WebpackConfigTransformerContext {
4
3
  environment: "dev" | "build";
5
4
  verbose: boolean;
6
5
  }
7
- type WebpackConfigTransformer = (config: Configuration, context: WebpackConfigTransformerContext) => Configuration;
8
- declare function applyTransformers(config: Configuration, transformers: WebpackConfigTransformer[], context: WebpackConfigTransformerContext): Configuration;
9
-
10
- export { type WebpackConfigTransformer, type WebpackConfigTransformerContext, applyTransformers };
6
+ export type WebpackConfigTransformer = (config: WebpackConfig, context: WebpackConfigTransformerContext) => WebpackConfig;
7
+ export declare function applyTransformers(config: WebpackConfig, transformers: WebpackConfigTransformer[], context: WebpackConfigTransformerContext): WebpackConfig;
@@ -1 +1,20 @@
1
- export { applyTransformers } from '../chunk-5ACA7GOB.js';
1
+
2
+ ;// CONCATENATED MODULE: ./src/transformers/applyTransformers.ts?__rslib_entry__
3
+ function applyTransformers(config, transformers, context) {
4
+ let count = 0;
5
+ const transformedConfig = transformers.reduce((acc, transformer)=>{
6
+ const newConfig = transformer(acc, context);
7
+ count += 1;
8
+ return newConfig;
9
+ }, config);
10
+ if (context.verbose) {
11
+ if (count > 0) {
12
+ console.log(`[webpack-configs] Applied ${count} configuration transformers.`);
13
+ }
14
+ }
15
+ return transformedConfig;
16
+ }
17
+
18
+ export { applyTransformers };
19
+
20
+ //# sourceMappingURL=applyTransformers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers/applyTransformers.js","sources":["webpack://@workleap/webpack-configs/./src/transformers/applyTransformers.ts"],"sourcesContent":["import type { WebpackConfig } from \"../types.ts\";\n\nexport interface WebpackConfigTransformerContext {\n environment: \"dev\" | \"build\";\n verbose: boolean;\n}\n\nexport type WebpackConfigTransformer = (config: WebpackConfig, context: WebpackConfigTransformerContext) => WebpackConfig;\n\nexport function applyTransformers(config: WebpackConfig, transformers: WebpackConfigTransformer[], context: WebpackConfigTransformerContext) {\n let count = 0;\n\n const transformedConfig = transformers.reduce((acc, transformer) => {\n const newConfig = transformer(acc, context);\n\n count += 1;\n\n return newConfig;\n }, config);\n\n if (context.verbose) {\n if (count > 0) {\n console.log(`[webpack-configs] Applied ${count} configuration transformers.`);\n }\n }\n\n return transformedConfig;\n}\n"],"names":["applyTransformers","config","transformers","context","count","transformedConfig","acc","transformer","newConfig","console"],"mappings":";;AASO,SAASA,kBAAkBC,MAAqB,EAAEC,YAAwC,EAAEC,OAAwC;IACvI,IAAIC,QAAQ;IAEZ,MAAMC,oBAAoBH,aAAa,MAAM,CAAC,CAACI,KAAKC;QAChD,MAAMC,YAAYD,YAAYD,KAAKH;QAEnCC,SAAS;QAET,OAAOI;IACX,GAAGP;IAEH,IAAIE,QAAQ,OAAO,EAAE;QACjB,IAAIC,QAAQ,GAAG;YACXK,QAAQ,GAAG,CAAC,CAAC,0BAA0B,EAAEL,MAAM,4BAA4B,CAAC;QAChF;IACJ;IAEA,OAAOC;AACX"}
@@ -1,26 +1,24 @@
1
- import { RuleSetRule, RuleSetUseItem, Configuration } from 'webpack';
2
-
3
- type ModuleRuleMatcher = (moduleRule: RuleSetRule | RuleSetUseItem, index: number, array: RuleSetRule[] | RuleSetUseItem[]) => boolean;
4
- type WithModuleRuleMatcherInfo = {
1
+ import type { RuleSetRule, RuleSetUseItem } from "webpack";
2
+ import type { WebpackConfig } from "../types.ts";
3
+ export type ModuleRuleMatcher = (moduleRule: RuleSetRule | RuleSetUseItem, index: number, array: RuleSetRule[] | RuleSetUseItem[]) => boolean;
4
+ export type WithModuleRuleMatcherInfo = {
5
5
  info: {
6
6
  type: string;
7
7
  value: string;
8
8
  };
9
9
  } & ModuleRuleMatcher;
10
- declare function matchLoaderName(name: string): ModuleRuleMatcher;
11
- type AssetModuleType = "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/sync" | "webassembly/async" | "asset" | "asset/source" | "asset/resource" | "asset/inline";
12
- declare function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher;
13
- declare function matchTest(test: string | RegExp): ModuleRuleMatcher;
14
- interface ModuleRuleMatch {
10
+ export declare function matchLoaderName(name: string): ModuleRuleMatcher;
11
+ export type AssetModuleType = "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/sync" | "webassembly/async" | "asset" | "asset/source" | "asset/resource" | "asset/inline";
12
+ export declare function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher;
13
+ export declare function matchTest(test: string | RegExp): ModuleRuleMatcher;
14
+ export interface ModuleRuleMatch {
15
15
  moduleRule: RuleSetRule | RuleSetUseItem;
16
16
  index: number;
17
17
  parent: RuleSetRule[] | RuleSetUseItem[];
18
18
  }
19
- declare function findModuleRule(config: Configuration, matcher: ModuleRuleMatcher): ModuleRuleMatch | undefined;
20
- declare function findModuleRules(config: Configuration, matcher: ModuleRuleMatcher): ModuleRuleMatch[] | undefined;
21
- declare function addBeforeModuleRule(config: Configuration, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]): void;
22
- declare function addAfterModuleRule(config: Configuration, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]): void;
23
- declare function replaceModuleRule(config: Configuration, matcher: ModuleRuleMatcher, newModuleRule: RuleSetRule | RuleSetUseItem): void;
24
- declare function removeModuleRules(config: Configuration, matcher: ModuleRuleMatcher): void;
25
-
26
- export { type AssetModuleType, type ModuleRuleMatch, type ModuleRuleMatcher, type WithModuleRuleMatcherInfo, addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule };
19
+ export declare function findModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher): ModuleRuleMatch | undefined;
20
+ export declare function findModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher): ModuleRuleMatch[] | undefined;
21
+ export declare function addBeforeModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]): void;
22
+ export declare function addAfterModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]): void;
23
+ export declare function replaceModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRule: RuleSetRule | RuleSetUseItem): void;
24
+ export declare function removeModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher): void;
@@ -1 +1,166 @@
1
- export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule } from '../chunk-34O5ZLZ6.js';
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
+
3
+ ;// CONCATENATED MODULE: external "node:path"
4
+
5
+ ;// CONCATENATED MODULE: ./src/transformers/moduleRules.ts?__rslib_entry__
6
+
7
+ function isNameMatchingLoader(loader, name) {
8
+ return loader === name || loader.indexOf(`${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep}${name}${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep}`) !== -1 || loader.indexOf(`@${name}${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep}`) !== -1;
9
+ }
10
+ function matchLoaderName(name) {
11
+ const matcher = (moduleRule)=>{
12
+ if (typeof moduleRule === "string") {
13
+ return isNameMatchingLoader(moduleRule, name);
14
+ } else {
15
+ if ("loader" in moduleRule && moduleRule.loader) {
16
+ return isNameMatchingLoader(moduleRule.loader, name);
17
+ }
18
+ }
19
+ return false;
20
+ };
21
+ // Add contextual information about the matcher for debugging.
22
+ matcher.info = {
23
+ type: matchLoaderName.name,
24
+ value: name
25
+ };
26
+ return matcher;
27
+ }
28
+ function matchAssetModuleType(type) {
29
+ const matcher = (moduleRule)=>{
30
+ if (typeof moduleRule !== "string" && "type" in moduleRule) {
31
+ return moduleRule.type === type;
32
+ }
33
+ return false;
34
+ };
35
+ // Add contextual information about the matcher for debugging.
36
+ matcher.info = {
37
+ type: matchAssetModuleType.name,
38
+ value: type
39
+ };
40
+ return matcher;
41
+ }
42
+ function matchTest(test) {
43
+ const matcher = (moduleRule)=>{
44
+ if (typeof moduleRule !== "string" && "test" in moduleRule) {
45
+ if (typeof moduleRule.test === "object" && typeof test === "object") {
46
+ // Assuming it's regular expressions.
47
+ return moduleRule.test.toString() === test.toString();
48
+ }
49
+ return moduleRule.test === test;
50
+ }
51
+ return false;
52
+ };
53
+ // Add contextual information about the matcher for debugging.
54
+ matcher.info = {
55
+ type: matchTest.name,
56
+ value: test.toString()
57
+ };
58
+ return matcher;
59
+ }
60
+ function toMatch(moduleRule, index, parent) {
61
+ return {
62
+ moduleRule,
63
+ index,
64
+ parent
65
+ };
66
+ }
67
+ function isRuleSetRule(value) {
68
+ return value.use !== undefined || value.oneOf !== undefined;
69
+ }
70
+ function findModuleRulesRecursively(moduleRules, matcher, parent, matches) {
71
+ moduleRules.forEach((x, index, array)=>{
72
+ if (x) {
73
+ if (matcher(x, index, array)) {
74
+ matches.push(toMatch(x, index, parent));
75
+ } else {
76
+ if (isRuleSetRule(x)) {
77
+ if (x.use) {
78
+ findModuleRulesRecursively(x.use, matcher, x.use, matches);
79
+ } else if (x.oneOf) {
80
+ // This error seems to have been introduced by either TS 5.2. or webpack 5.88.1 (https://github.com/webpack/webpack/releases/tag/v5.88.1),
81
+ // I am not sure what changed thought.
82
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
+ // @ts-ignore
84
+ findModuleRulesRecursively(x.oneOf, matcher, x.oneOf, matches);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ });
90
+ }
91
+ function findModuleRule(config, matcher) {
92
+ const moduleRules = config.module?.rules;
93
+ if (!moduleRules) {
94
+ return;
95
+ }
96
+ const matches = [];
97
+ findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
98
+ if (matches.length > 1) {
99
+ const matcherInfo = matcher.info;
100
+ throw new Error(`[webpack-configs] Found more than 1 matching module rule.\n[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"\n[webpack-configs] Matches: "${JSON.stringify(matches.map((x)=>x.moduleRule))}"`);
101
+ }
102
+ return matches[0];
103
+ }
104
+ function findModuleRules(config, matcher) {
105
+ const moduleRules = config.module?.rules;
106
+ if (!moduleRules) {
107
+ return;
108
+ }
109
+ const matches = [];
110
+ findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
111
+ return matches;
112
+ }
113
+ function addBeforeModuleRule(config, matcher, newModuleRules) {
114
+ const match = findModuleRule(config, matcher);
115
+ if (match) {
116
+ match.parent.splice(match.index, 0, ...newModuleRules);
117
+ } else {
118
+ const matcherInfo = matcher.info;
119
+ throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\n[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
120
+ }
121
+ }
122
+ function addAfterModuleRule(config, matcher, newModuleRules) {
123
+ const match = findModuleRule(config, matcher);
124
+ if (match) {
125
+ match.parent.splice(match.index + 1, 0, ...newModuleRules);
126
+ } else {
127
+ const matcherInfo = matcher.info;
128
+ throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\n[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
129
+ }
130
+ }
131
+ function replaceModuleRule(config, matcher, newModuleRule) {
132
+ const match = findModuleRule(config, matcher);
133
+ if (match) {
134
+ match.parent[match.index] = newModuleRule;
135
+ } else {
136
+ const matcherInfo = matcher.info;
137
+ throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.\n[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
138
+ }
139
+ }
140
+ function removeModuleRules(config, matcher) {
141
+ const moduleRules = config.module?.rules;
142
+ if (!moduleRules) {
143
+ return;
144
+ }
145
+ const matches = [];
146
+ findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
147
+ if (matches.length > 0) {
148
+ // Must keep the initial parent arrays' length to calculate the adjustment
149
+ // once the first match has been deleted.
150
+ const initialParentLengths = new Map(matches.map((x)=>[
151
+ x.parent,
152
+ x.parent.length
153
+ ]));
154
+ matches.forEach((x)=>{
155
+ const positionAdjustment = initialParentLengths.get(x.parent) - x.parent.length;
156
+ x.parent.splice(x.index - positionAdjustment, 1);
157
+ });
158
+ } else {
159
+ const matcherInfo = matcher.info;
160
+ throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.\n[webpack-configs] Matcher: "${matcherInfo}"`);
161
+ }
162
+ }
163
+
164
+ export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule };
165
+
166
+ //# sourceMappingURL=moduleRules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers/moduleRules.js","sources":["webpack://@workleap/webpack-configs/./src/transformers/moduleRules.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { RuleSetRule, RuleSetUseItem } from \"webpack\";\nimport type { WebpackConfig } from \"../types.ts\";\n\nexport type ModuleRuleMatcher = (moduleRule: RuleSetRule | RuleSetUseItem, index: number, array: RuleSetRule[] | RuleSetUseItem[]) => boolean;\n\nexport type WithModuleRuleMatcherInfo = {\n info: {\n type: string;\n value: string;\n };\n} & ModuleRuleMatcher;\n\nfunction isNameMatchingLoader(loader: string, name: string) {\n return loader === name || loader.indexOf(`${path.sep}${name}${path.sep}`) !== -1 || loader.indexOf(`@${name}${path.sep}`) !== -1;\n}\n\nexport function matchLoaderName(name: string): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule === \"string\") {\n return isNameMatchingLoader(moduleRule, name);\n } else {\n if (\"loader\" in moduleRule && moduleRule.loader) {\n return isNameMatchingLoader(moduleRule.loader, name);\n }\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchLoaderName.name,\n value: name\n };\n\n return matcher;\n}\n\nexport type AssetModuleType =\n | \"javascript/auto\"\n | \"javascript/dynamic\"\n | \"javascript/esm\"\n | \"json\"\n | \"webassembly/sync\"\n | \"webassembly/async\"\n | \"asset\"\n | \"asset/source\"\n | \"asset/resource\"\n | \"asset/inline\";\n\nexport function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"type\" in moduleRule) {\n return moduleRule.type === type;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchAssetModuleType.name,\n value: type\n };\n\n return matcher;\n}\n\nexport function matchTest(test: string | RegExp): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"test\" in moduleRule) {\n if (typeof moduleRule.test === \"object\" && typeof test === \"object\") {\n // Assuming it's regular expressions.\n return moduleRule.test.toString() === test.toString();\n }\n\n return moduleRule.test === test;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchTest.name,\n value: test.toString()\n };\n\n return matcher;\n}\n\nexport interface ModuleRuleMatch {\n moduleRule: RuleSetRule | RuleSetUseItem;\n index: number;\n parent: RuleSetRule[] | RuleSetUseItem[];\n}\n\nfunction toMatch(moduleRule: RuleSetRule | RuleSetUseItem, index: number, parent: RuleSetRule[] | RuleSetUseItem[]) {\n return {\n moduleRule,\n index,\n parent\n };\n}\n\nfunction isRuleSetRule(value: RuleSetRule | RuleSetUseItem): value is RuleSetRule {\n return (value as RuleSetRule).use !== undefined || (value as RuleSetRule).oneOf !== undefined;\n}\n\nfunction findModuleRulesRecursively(moduleRules: RuleSetRule[] | RuleSetUseItem[], matcher: ModuleRuleMatcher, parent: RuleSetRule[] | RuleSetUseItem[], matches: ModuleRuleMatch[]) {\n moduleRules.forEach((x, index, array) => {\n if (x) {\n if (matcher(x, index, array)) {\n matches.push(toMatch(x, index, parent));\n } else {\n if (isRuleSetRule(x)) {\n if (x.use) {\n findModuleRulesRecursively(x.use as RuleSetUseItem[], matcher, x.use as RuleSetUseItem[], matches);\n } else if (x.oneOf) {\n // This error seems to have been introduced by either TS 5.2. or webpack 5.88.1 (https://github.com/webpack/webpack/releases/tag/v5.88.1),\n // I am not sure what changed thought.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n findModuleRulesRecursively(x.oneOf, matcher, x.oneOf, matches);\n }\n }\n }\n }\n });\n}\n\nexport function findModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 1) {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Found more than 1 matching module rule.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"\\n[webpack-configs] Matches: \"${JSON.stringify(matches.map(x => x.moduleRule))}\"`);\n }\n\n return matches[0];\n}\n\nexport function findModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n return matches;\n}\n\nexport function addBeforeModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function addAfterModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index + 1, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function replaceModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRule: RuleSetRule | RuleSetUseItem) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent[match.index] = newModuleRule;\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function removeModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 0) {\n // Must keep the initial parent arrays' length to calculate the adjustment\n // once the first match has been deleted.\n const initialParentLengths = new Map<RuleSetRule[] | RuleSetUseItem[], number>(matches.map(x => [x.parent, x.parent.length]));\n\n matches.forEach(x => {\n const positionAdjustment = initialParentLengths.get(x.parent)! - x.parent.length;\n\n x.parent.splice(x.index - positionAdjustment, 1);\n });\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.\\n[webpack-configs] Matcher: \"${matcherInfo}\"`);\n }\n}\n"],"names":["path","isNameMatchingLoader","loader","name","matchLoaderName","matcher","moduleRule","matchAssetModuleType","type","matchTest","test","toMatch","index","parent","isRuleSetRule","value","undefined","findModuleRulesRecursively","moduleRules","matches","x","array","findModuleRule","config","matcherInfo","Error","JSON","findModuleRules","addBeforeModuleRule","newModuleRules","match","addAfterModuleRule","replaceModuleRule","newModuleRule","removeModuleRules","initialParentLengths","Map","positionAdjustment"],"mappings":";;;;;AAA6B;AAa7B,SAASC,qBAAqBC,MAAc,EAAEC,IAAY;IACtD,OAAOD,WAAWC,QAAQD,OAAO,OAAO,CAAC,GAAGF,6DAAQ,GAAGG,OAAOH,6DAAQ,EAAE,MAAM,CAAC,KAAKE,OAAO,OAAO,CAAC,CAAC,CAAC,EAAEC,OAAOH,6DAAQ,EAAE,MAAM,CAAC;AACnI;AAEO,SAASI,gBAAgBD,IAAY;IACxC,MAAME,UAAqCC,CAAAA;QACvC,IAAI,OAAOA,eAAe,UAAU;YAChC,OAAOL,qBAAqBK,YAAYH;QAC5C,OAAO;YACH,IAAI,YAAYG,cAAcA,WAAW,MAAM,EAAE;gBAC7C,OAAOL,qBAAqBK,WAAW,MAAM,EAAEH;YACnD;QACJ;QAEA,OAAO;IACX;IAEA,8DAA8D;IAC9DE,QAAQ,IAAI,GAAG;QACX,MAAMD,gBAAgB,IAAI;QAC1B,OAAOD;IACX;IAEA,OAAOE;AACX;AAcO,SAASE,qBAAqBC,IAAqB;IACtD,MAAMH,UAAqCC,CAAAA;QACvC,IAAI,OAAOA,eAAe,YAAY,UAAUA,YAAY;YACxD,OAAOA,WAAW,IAAI,KAAKE;QAC/B;QAEA,OAAO;IACX;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configuration["plugins"]>[number];
4
- type PluginMatcher = (plugin: WebpackPlugin, index: number, array: WebpackPlugin[]) => boolean;
5
- type WithPluginMatcherInfo = {
1
+ import type { WebpackConfig } from "../types.ts";
2
+ export type WebpackPlugin = NonNullable<WebpackConfig["plugins"]>[number];
3
+ export type PluginMatcher = (plugin: WebpackPlugin, index: number, array: WebpackPlugin[]) => boolean;
4
+ export type WithPluginMatcherInfo = {
6
5
  info: {
7
6
  type: string;
8
7
  value: string;
9
8
  };
10
9
  } & PluginMatcher;
11
- declare function matchConstructorName(name: string): PluginMatcher;
12
- interface PluginMatch {
10
+ export declare function matchConstructorName(name: string): PluginMatcher;
11
+ export interface PluginMatch {
13
12
  plugin: WebpackPlugin;
14
13
  index: number;
15
14
  }
16
- declare function findPlugin(config: Configuration, matcher: PluginMatcher): PluginMatch;
17
- declare function replacePlugin(config: Configuration, matcher: PluginMatcher, newPlugin: WebpackPlugin): void;
18
- declare function addBeforePlugin(config: Configuration, matcher: PluginMatcher, newPlugins: WebpackPlugin[]): void;
19
- declare function addAfterPlugin(config: Configuration, matcher: PluginMatcher, newPlugins: WebpackPlugin[]): void;
20
- declare function removePlugin(config: Configuration, matcher: PluginMatcher): void;
21
-
22
- export { type PluginMatch, type PluginMatcher, type WebpackPlugin, type WithPluginMatcherInfo, addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin };
15
+ export declare function findPlugin(config: WebpackConfig, matcher: PluginMatcher): PluginMatch;
16
+ export declare function replacePlugin(config: WebpackConfig, matcher: PluginMatcher, newPlugin: WebpackPlugin): void;
17
+ export declare function addBeforePlugin(config: WebpackConfig, matcher: PluginMatcher, newPlugins: WebpackPlugin[]): void;
18
+ export declare function addAfterPlugin(config: WebpackConfig, matcher: PluginMatcher, newPlugins: WebpackPlugin[]): void;
19
+ export declare function removePlugin(config: WebpackConfig, matcher: PluginMatcher): void;