@nx/webpack 17.0.4 → 17.0.6

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 (80) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +2 -2
  4. package/index.d.ts +1 -3
  5. package/index.js +2 -7
  6. package/migrations.json +0 -6
  7. package/package.json +5 -6
  8. package/src/executors/dev-server/dev-server.impl.js +17 -31
  9. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +3 -2
  10. package/src/executors/dev-server/lib/get-dev-server-config.js +26 -18
  11. package/src/executors/dev-server/schema.d.ts +8 -8
  12. package/src/executors/webpack/lib/get-webpack-config.d.ts +5 -0
  13. package/src/executors/webpack/lib/get-webpack-config.js +16 -0
  14. package/src/executors/webpack/lib/normalize-options.d.ts +2 -1
  15. package/src/executors/webpack/lib/normalize-options.js +53 -9
  16. package/src/executors/webpack/schema.d.ts +7 -10
  17. package/src/executors/webpack/schema.json +50 -30
  18. package/src/executors/webpack/webpack.impl.js +16 -36
  19. package/src/generators/configuration/configuration.d.ts +2 -3
  20. package/src/generators/configuration/configuration.js +23 -95
  21. package/src/generators/configuration/schema.d.ts +0 -1
  22. package/src/generators/configuration/schema.json +1 -1
  23. package/src/generators/init/init.d.ts +0 -1
  24. package/src/generators/init/init.js +23 -48
  25. package/src/generators/init/schema.d.ts +2 -4
  26. package/src/generators/init/schema.json +13 -18
  27. package/src/plugins/generate-package-json-plugin.d.ts +4 -6
  28. package/src/plugins/generate-package-json-plugin.js +14 -11
  29. package/src/utils/config.d.ts +6 -11
  30. package/src/utils/config.js +13 -48
  31. package/src/utils/get-client-environment.js +1 -4
  32. package/src/utils/module-federation/dependencies.js +3 -15
  33. package/src/utils/module-federation/get-remotes-for-host.js +1 -1
  34. package/src/utils/module-federation/remotes.js +1 -1
  35. package/src/utils/module-federation/secondary-entry-points.js +1 -1
  36. package/src/utils/module-federation/typescript.js +9 -14
  37. package/src/utils/versions.d.ts +0 -1
  38. package/src/utils/versions.js +1 -2
  39. package/src/utils/webpack/custom-webpack.d.ts +2 -0
  40. package/src/utils/webpack/{resolve-user-defined-webpack-config.js → custom-webpack.js} +8 -14
  41. package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
  42. package/src/utils/webpack/interpolate-env-variables-to-index.js +1 -4
  43. package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
  44. package/src/utils/with-nx.d.ts +58 -4
  45. package/src/utils/with-nx.js +362 -22
  46. package/src/utils/with-web.d.ts +2 -2
  47. package/src/utils/with-web.js +488 -9
  48. package/plugin.d.ts +0 -1
  49. package/plugin.js +0 -5
  50. package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +0 -2
  51. package/src/migrations/update-17-2-1/webpack-config-setup.js +0 -31
  52. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +0 -8
  53. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +0 -31
  54. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +0 -5
  55. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +0 -318
  56. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +0 -5
  57. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +0 -372
  58. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +0 -53
  59. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +0 -78
  60. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +0 -1
  61. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +0 -35
  62. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +0 -3
  63. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +0 -42
  64. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +0 -4
  65. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +0 -148
  66. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +0 -73
  67. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +0 -117
  68. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +0 -216
  69. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +0 -2
  70. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +0 -17
  71. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +0 -48
  72. package/src/plugins/plugin.d.ts +0 -9
  73. package/src/plugins/plugin.js +0 -132
  74. package/src/utils/ensure-dependencies.d.ts +0 -6
  75. package/src/utils/ensure-dependencies.js +0 -28
  76. package/src/utils/has-plugin.d.ts +0 -2
  77. package/src/utils/has-plugin.js +0 -11
  78. package/src/utils/webpack/read-webpack-options.d.ts +0 -10
  79. package/src/utils/webpack/read-webpack-options.js +0 -41
  80. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +0 -3
@@ -1,318 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyBaseConfig = void 0;
4
- const path = require("path");
5
- const license_webpack_plugin_1 = require("license-webpack-plugin");
6
- const CopyWebpackPlugin = require("copy-webpack-plugin");
7
- const webpack_1 = require("webpack");
8
- const js_1 = require("@nx/js");
9
- const stats_json_plugin_1 = require("../../stats-json-plugin");
10
- const generate_package_json_plugin_1 = require("../../generate-package-json-plugin");
11
- const hash_format_1 = require("../../../utils/hash-format");
12
- const nx_tsconfig_paths_webpack_plugin_1 = require("../../nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin");
13
- const get_terser_ecma_version_1 = require("./get-terser-ecma-version");
14
- const compiler_loaders_1 = require("./compiler-loaders");
15
- const TerserPlugin = require("terser-webpack-plugin");
16
- const nodeExternals = require("webpack-node-externals");
17
- const IGNORED_WEBPACK_WARNINGS = [
18
- /The comment file/i,
19
- /could not find any license/i,
20
- ];
21
- const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
22
- const mainFields = ['module', 'main'];
23
- function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
24
- // Defaults that was applied from executor schema previously.
25
- options.compiler ??= 'babel';
26
- options.deleteOutputPath ??= true;
27
- options.externalDependencies ??= 'all';
28
- options.fileReplacements ??= [];
29
- options.memoryLimit ??= 2048;
30
- options.transformers ??= [];
31
- applyNxIndependentConfig(options, config);
32
- // Some of the options only work during actual tasks, not when reading the webpack config during CreateNodes.
33
- if (!process.env['NX_TASK_TARGET_PROJECT'])
34
- return;
35
- applyNxDependentConfig(options, config, { useNormalizedEntry });
36
- }
37
- exports.applyBaseConfig = applyBaseConfig;
38
- function applyNxIndependentConfig(options, config) {
39
- const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
40
- config.context = path.join(options.root, options.projectRoot);
41
- config.target ??= options.target;
42
- config.node = false;
43
- config.mode =
44
- // When the target is Node avoid any optimizations, such as replacing `process.env.NODE_ENV` with build time value.
45
- config.target === 'node'
46
- ? 'none'
47
- : // Otherwise, make sure it matches `process.env.NODE_ENV`.
48
- // When mode is development or production, webpack will automatically
49
- // configure DefinePlugin to replace `process.env.NODE_ENV` with the
50
- // build-time value. Thus, we need to make sure it's the same value to
51
- // avoid conflicts.
52
- //
53
- // When the NODE_ENV is something else (e.g. test), then set it to none
54
- // to prevent extra behavior from webpack.
55
- process.env.NODE_ENV === 'development' ||
56
- process.env.NODE_ENV === 'production'
57
- ? process.env.NODE_ENV
58
- : 'none';
59
- // When target is Node, the Webpack mode will be set to 'none' which disables in memory caching and causes a full rebuild on every change.
60
- // So to mitigate this we enable in memory caching when target is Node and in watch mode.
61
- config.cache =
62
- options.target === 'node' && options.watch ? { type: 'memory' } : undefined;
63
- config.devtool =
64
- options.sourceMap === 'hidden'
65
- ? 'hidden-source-map'
66
- : options.sourceMap
67
- ? 'source-map'
68
- : false;
69
- config.output = {
70
- ...config.output,
71
- libraryTarget: (config.output?.libraryTarget ??
72
- options.target === 'node')
73
- ? 'commonjs'
74
- : undefined,
75
- path: config.output?.path ??
76
- (options.outputPath
77
- ? path.join(options.root, options.outputPath)
78
- : undefined),
79
- filename: config.output?.filename ?? options.outputHashing
80
- ? `[name]${hashFormat.script}.js`
81
- : '[name].js',
82
- chunkFilename: config.output?.chunkFilename ?? options.outputHashing
83
- ? `[name]${hashFormat.chunk}.js`
84
- : '[name].js',
85
- hashFunction: config.output?.hashFunction ?? 'xxhash64',
86
- // Disabled for performance
87
- pathinfo: config.output?.pathinfo ?? false,
88
- // Use CJS for Node since it has the widest support.
89
- scriptType: config.output?.scriptType ?? options.target === 'node'
90
- ? undefined
91
- : 'module',
92
- };
93
- config.watch = options.watch;
94
- config.watchOptions = {
95
- poll: options.poll,
96
- };
97
- config.profile = options.statsJson;
98
- config.performance = {
99
- ...config.performance,
100
- hints: false,
101
- };
102
- config.experiments = { ...config.experiments, cacheUnaffected: true };
103
- config.ignoreWarnings = [
104
- (x) => IGNORED_WEBPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
105
- ];
106
- config.optimization = {
107
- ...config.optimization,
108
- sideEffects: true,
109
- minimize: typeof options.optimization === 'object'
110
- ? !!options.optimization.scripts
111
- : !!options.optimization,
112
- minimizer: [
113
- options.compiler !== 'swc'
114
- ? new TerserPlugin({
115
- parallel: true,
116
- terserOptions: {
117
- keep_classnames: true,
118
- ecma: (0, get_terser_ecma_version_1.getTerserEcmaVersion)(path.join(options.root, options.projectRoot)),
119
- safari10: true,
120
- format: {
121
- ascii_only: true,
122
- comments: false,
123
- webkit: true,
124
- },
125
- },
126
- extractComments: false,
127
- })
128
- : new TerserPlugin({
129
- minify: TerserPlugin.swcMinify,
130
- // `terserOptions` options will be passed to `swc`
131
- terserOptions: {
132
- module: true,
133
- mangle: false,
134
- },
135
- }),
136
- ],
137
- runtimeChunk: false,
138
- concatenateModules: true,
139
- };
140
- config.stats = {
141
- hash: true,
142
- timings: false,
143
- cached: false,
144
- cachedAssets: false,
145
- modules: false,
146
- warnings: true,
147
- errors: true,
148
- colors: !options.verbose && !options.statsJson,
149
- chunks: !options.verbose,
150
- assets: !!options.verbose,
151
- chunkOrigins: !!options.verbose,
152
- chunkModules: !!options.verbose,
153
- children: !!options.verbose,
154
- reasons: !!options.verbose,
155
- version: !!options.verbose,
156
- errorDetails: !!options.verbose,
157
- moduleTrace: !!options.verbose,
158
- usedExports: !!options.verbose,
159
- };
160
- }
161
- function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
162
- const tsConfig = options.tsConfig ?? (0, js_1.getRootTsConfigPath)();
163
- const plugins = [
164
- new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ tsConfig }),
165
- ];
166
- const executorContext = {
167
- projectName: options.projectName,
168
- targetName: options.targetName,
169
- projectGraph: options.projectGraph,
170
- configurationName: options.configurationName,
171
- root: options.root,
172
- };
173
- if (!options?.skipTypeChecking) {
174
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
175
- plugins.push(new ForkTsCheckerWebpackPlugin({
176
- typescript: {
177
- configFile: path.isAbsolute(tsConfig)
178
- ? tsConfig
179
- : path.join(options.root, tsConfig),
180
- memoryLimit: options.memoryLimit || 2018,
181
- },
182
- }));
183
- }
184
- const entries = [];
185
- if (options.main) {
186
- const mainEntry = options.outputFileName
187
- ? path.parse(options.outputFileName).name
188
- : 'main';
189
- entries.push({
190
- name: mainEntry,
191
- import: [path.resolve(options.root, options.main)],
192
- });
193
- }
194
- if (options.additionalEntryPoints) {
195
- for (const { entryName, entryPath } of options.additionalEntryPoints) {
196
- entries.push({
197
- name: entryName,
198
- import: [path.resolve(options.root, entryPath)],
199
- });
200
- }
201
- }
202
- if (options.polyfills) {
203
- entries.push({
204
- name: 'polyfills',
205
- import: [path.resolve(options.root, options.polyfills)],
206
- });
207
- }
208
- config.entry ??= {};
209
- entries.forEach((entry) => {
210
- if (useNormalizedEntry) {
211
- config.entry[entry.name] = { import: entry.import };
212
- }
213
- else {
214
- config.entry[entry.name] = entry.import;
215
- }
216
- });
217
- if (options.progress) {
218
- plugins.push(new webpack_1.ProgressPlugin({ profile: options.verbose }));
219
- }
220
- if (options.extractLicenses) {
221
- plugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
222
- stats: {
223
- warnings: false,
224
- errors: false,
225
- },
226
- perChunkOutput: false,
227
- outputFilename: `3rdpartylicenses.txt`,
228
- }));
229
- }
230
- if (Array.isArray(options.assets) && options.assets.length > 0) {
231
- plugins.push(new CopyWebpackPlugin({
232
- patterns: options.assets.map((asset) => {
233
- return {
234
- context: asset.input,
235
- // Now we remove starting slash to make Webpack place it from the output root.
236
- to: asset.output,
237
- from: asset.glob,
238
- globOptions: {
239
- ignore: [
240
- '.gitkeep',
241
- '**/.DS_Store',
242
- '**/Thumbs.db',
243
- ...(asset.ignore ?? []),
244
- ],
245
- dot: true,
246
- },
247
- };
248
- }),
249
- }));
250
- }
251
- if (options.generatePackageJson && executorContext) {
252
- plugins.push(new generate_package_json_plugin_1.GeneratePackageJsonPlugin({ ...options, tsConfig }));
253
- }
254
- if (options.statsJson) {
255
- plugins.push(new stats_json_plugin_1.StatsJsonPlugin());
256
- }
257
- const externals = [];
258
- if (options.target === 'node' && options.externalDependencies === 'all') {
259
- const modulesDir = `${options.root}/node_modules`;
260
- externals.push(nodeExternals({ modulesDir }));
261
- }
262
- else if (Array.isArray(options.externalDependencies)) {
263
- externals.push(function (ctx, callback) {
264
- if (options.externalDependencies.includes(ctx.request)) {
265
- // not bundled
266
- return callback(null, `commonjs ${ctx.request}`);
267
- }
268
- // bundled
269
- callback();
270
- });
271
- }
272
- config.resolve = {
273
- ...config.resolve,
274
- extensions: [...(config?.resolve?.extensions ?? []), ...extensions],
275
- alias: {
276
- ...(config.resolve?.alias ?? {}),
277
- ...(options.fileReplacements?.reduce((aliases, replacement) => ({
278
- ...aliases,
279
- [replacement.replace]: replacement.with,
280
- }), {}) ?? {}),
281
- },
282
- mainFields: config.resolve?.mainFields ?? mainFields,
283
- };
284
- config.externals = externals;
285
- config.module = {
286
- ...config.module,
287
- // Enabled for performance
288
- unsafeCache: true,
289
- rules: [
290
- ...(config?.module?.rules ?? []),
291
- options.sourceMap && {
292
- test: /\.js$/,
293
- enforce: 'pre',
294
- loader: require.resolve('source-map-loader'),
295
- },
296
- {
297
- // There's an issue resolving paths without fully specified extensions
298
- // See: https://github.com/graphql/graphql-js/issues/2721
299
- // TODO(jack): Add a flag to turn this option on like Next.js does via experimental flag.
300
- // See: https://github.com/vercel/next.js/pull/29880
301
- test: /\.m?jsx?$/,
302
- resolve: {
303
- fullySpecified: false,
304
- },
305
- },
306
- // There's an issue when using buildable libs and .js files (instead of .ts files),
307
- // where the wrong type is used (commonjs vs esm) resulting in export-imports throwing errors.
308
- // See: https://github.com/nrwl/nx/issues/10990
309
- {
310
- test: /\.js$/,
311
- type: 'javascript/auto',
312
- },
313
- (0, compiler_loaders_1.createLoaderFromCompiler)(options),
314
- ].filter((r) => !!r),
315
- };
316
- config.plugins ??= [];
317
- config.plugins.push(...plugins);
318
- }
@@ -1,5 +0,0 @@
1
- import { Configuration, WebpackOptionsNormalized } from 'webpack';
2
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
3
- export declare function applyWebConfig(options: NormalizedNxWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
4
- useNormalizedEntry?: boolean;
5
- }): void;
@@ -1,372 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyWebConfig = void 0;
4
- const path = require("path");
5
- const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
6
- const webpack_1 = require("webpack");
7
- const write_index_html_plugin_1 = require("../../write-index-html-plugin");
8
- const hash_format_1 = require("../../../utils/hash-format");
9
- const get_client_environment_1 = require("../../../utils/get-client-environment");
10
- const normalize_entry_1 = require("../../../utils/webpack/normalize-entry");
11
- const stylesheet_loaders_1 = require("./stylesheet-loaders");
12
- const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
13
- const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
14
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
15
- function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
16
- if (!process.env['NX_TASK_TARGET_PROJECT'])
17
- return;
18
- // Defaults that was applied from executor schema previously.
19
- options.runtimeChunk ??= true; // need this for HMR and other things to work
20
- options.extractCss ??= true;
21
- options.generateIndexHtml ??= true;
22
- options.styles ??= [];
23
- options.scripts ??= [];
24
- const plugins = [];
25
- const stylesOptimization = typeof options.optimization === 'object'
26
- ? options.optimization.styles
27
- : options.optimization;
28
- if (Array.isArray(options.scripts)) {
29
- plugins.push(...(0, instantiate_script_plugins_1.instantiateScriptPlugins)(options));
30
- }
31
- if (options.index && options.generateIndexHtml) {
32
- plugins.push(new write_index_html_plugin_1.WriteIndexHtmlPlugin({
33
- crossOrigin: options.crossOrigin,
34
- sri: options.subresourceIntegrity,
35
- outputPath: path.basename(options.index),
36
- indexPath: path.join(options.root, options.index),
37
- baseHref: options.baseHref,
38
- deployUrl: options.deployUrl,
39
- scripts: options.scripts,
40
- styles: options.styles,
41
- }));
42
- }
43
- if (options.subresourceIntegrity) {
44
- plugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin());
45
- }
46
- const minimizer = [new webpack_1.ids.HashedModuleIdsPlugin()];
47
- if (stylesOptimization) {
48
- minimizer.push(new CssMinimizerPlugin({
49
- test: /\.(?:css|scss|sass|less|styl)$/,
50
- }));
51
- }
52
- if (!options.ssr) {
53
- plugins.push(new webpack_1.DefinePlugin((0, get_client_environment_1.getClientEnvironment)(process.env.NODE_ENV).stringified));
54
- }
55
- const entries = {};
56
- const globalStylePaths = [];
57
- // Determine hashing format.
58
- const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
59
- const includePaths = [];
60
- if (options?.stylePreprocessorOptions?.includePaths?.length > 0) {
61
- options.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(options.root, includePath)));
62
- }
63
- let lessPathOptions = {};
64
- if (includePaths.length > 0) {
65
- lessPathOptions = {
66
- paths: includePaths,
67
- };
68
- }
69
- // Process global styles.
70
- if (options.styles.length > 0) {
71
- (0, normalize_entry_1.normalizeExtraEntryPoints)(options.styles, 'styles').forEach((style) => {
72
- const resolvedPath = path.resolve(options.root, style.input);
73
- // Add style entry points.
74
- if (entries[style.bundleName]) {
75
- entries[style.bundleName].import.push(resolvedPath);
76
- }
77
- else {
78
- entries[style.bundleName] = { import: [resolvedPath] };
79
- }
80
- // Add global css paths.
81
- globalStylePaths.push(resolvedPath);
82
- });
83
- }
84
- const cssModuleRules = [
85
- {
86
- test: /\.module\.css$/,
87
- exclude: globalStylePaths,
88
- use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
89
- },
90
- {
91
- test: /\.module\.(scss|sass)$/,
92
- exclude: globalStylePaths,
93
- use: [
94
- ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
95
- {
96
- loader: require.resolve('sass-loader'),
97
- options: {
98
- implementation: require('sass'),
99
- sassOptions: {
100
- fiber: false,
101
- precision: 8,
102
- includePaths,
103
- },
104
- },
105
- },
106
- ],
107
- },
108
- {
109
- test: /\.module\.less$/,
110
- exclude: globalStylePaths,
111
- use: [
112
- ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
113
- {
114
- loader: require.resolve('less-loader'),
115
- options: {
116
- lessOptions: {
117
- paths: includePaths,
118
- },
119
- },
120
- },
121
- ],
122
- },
123
- {
124
- test: /\.module\.styl$/,
125
- exclude: globalStylePaths,
126
- use: [
127
- ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
128
- {
129
- loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
130
- options: {
131
- stylusOptions: {
132
- include: includePaths,
133
- },
134
- },
135
- },
136
- ],
137
- },
138
- ];
139
- const globalCssRules = [
140
- {
141
- test: /\.css$/,
142
- exclude: globalStylePaths,
143
- use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
144
- },
145
- {
146
- test: /\.scss$|\.sass$/,
147
- exclude: globalStylePaths,
148
- use: [
149
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
150
- {
151
- loader: require.resolve('sass-loader'),
152
- options: {
153
- implementation: require('sass'),
154
- sourceMap: !!options.sourceMap,
155
- sassOptions: {
156
- fiber: false,
157
- // bootstrap-sass requires a minimum precision of 8
158
- precision: 8,
159
- includePaths,
160
- },
161
- },
162
- },
163
- ],
164
- },
165
- {
166
- test: /\.less$/,
167
- exclude: globalStylePaths,
168
- use: [
169
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
170
- {
171
- loader: require.resolve('less-loader'),
172
- options: {
173
- sourceMap: !!options.sourceMap,
174
- lessOptions: {
175
- javascriptEnabled: true,
176
- ...lessPathOptions,
177
- },
178
- },
179
- },
180
- ],
181
- },
182
- {
183
- test: /\.styl$/,
184
- exclude: globalStylePaths,
185
- use: [
186
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
187
- {
188
- loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
189
- options: {
190
- sourceMap: !!options.sourceMap,
191
- stylusOptions: {
192
- include: includePaths,
193
- },
194
- },
195
- },
196
- ],
197
- },
198
- ];
199
- const globalStyleRules = [
200
- {
201
- test: /\.css$/,
202
- include: globalStylePaths,
203
- use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
204
- },
205
- {
206
- test: /\.scss$|\.sass$/,
207
- include: globalStylePaths,
208
- use: [
209
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
210
- {
211
- loader: require.resolve('sass-loader'),
212
- options: {
213
- implementation: require('sass'),
214
- sourceMap: !!options.sourceMap,
215
- sassOptions: {
216
- fiber: false,
217
- // bootstrap-sass requires a minimum precision of 8
218
- precision: 8,
219
- includePaths,
220
- },
221
- },
222
- },
223
- ],
224
- },
225
- {
226
- test: /\.less$/,
227
- include: globalStylePaths,
228
- use: [
229
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
230
- {
231
- loader: require.resolve('less-loader'),
232
- options: {
233
- sourceMap: !!options.sourceMap,
234
- lessOptions: {
235
- javascriptEnabled: true,
236
- ...lessPathOptions,
237
- },
238
- },
239
- },
240
- ],
241
- },
242
- {
243
- test: /\.styl$/,
244
- include: globalStylePaths,
245
- use: [
246
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
247
- {
248
- loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
249
- options: {
250
- sourceMap: !!options.sourceMap,
251
- stylusOptions: {
252
- include: includePaths,
253
- },
254
- },
255
- },
256
- ],
257
- },
258
- ];
259
- const rules = [
260
- {
261
- test: /\.css$|\.scss$|\.sass$|\.less$|\.styl$/,
262
- oneOf: [...cssModuleRules, ...globalCssRules, ...globalStyleRules],
263
- },
264
- ];
265
- if (options.extractCss) {
266
- plugins.push(
267
- // extract global css from js files into own css file
268
- new MiniCssExtractPlugin({
269
- filename: `[name]${hashFormat.extract}.css`,
270
- }));
271
- }
272
- config.output = {
273
- ...config.output,
274
- crossOriginLoading: options.subresourceIntegrity
275
- ? 'anonymous'
276
- : false,
277
- };
278
- // In case users customize their webpack config with unsupported entry.
279
- if (typeof config.entry === 'function')
280
- throw new Error('Entry function is not supported. Use an object.');
281
- if (typeof config.entry === 'string')
282
- throw new Error('Entry string is not supported. Use an object.');
283
- if (Array.isArray(config.entry))
284
- throw new Error('Entry array is not supported. Use an object.');
285
- Object.entries(entries).forEach(([entryName, entryData]) => {
286
- if (useNormalizedEntry) {
287
- config.entry[entryName] = { import: entryData.import };
288
- }
289
- else {
290
- config.entry[entryName] = entryData.import;
291
- }
292
- });
293
- config.optimization = {
294
- ...config.optimization,
295
- minimizer: [...config.optimization.minimizer, ...minimizer],
296
- emitOnErrors: false,
297
- moduleIds: 'deterministic',
298
- runtimeChunk: options.runtimeChunk ? { name: 'runtime' } : false,
299
- splitChunks: {
300
- defaultSizeTypes: config.optimization.splitChunks !== false
301
- ? config.optimization.splitChunks?.defaultSizeTypes
302
- : ['...'],
303
- maxAsyncRequests: Infinity,
304
- cacheGroups: {
305
- default: !!options.commonChunk && {
306
- chunks: 'async',
307
- minChunks: 2,
308
- priority: 10,
309
- },
310
- common: !!options.commonChunk && {
311
- name: 'common',
312
- chunks: 'async',
313
- minChunks: 2,
314
- enforce: true,
315
- priority: 5,
316
- },
317
- vendors: false,
318
- vendor: !!options.vendorChunk && {
319
- name: 'vendor',
320
- chunks: (chunk) => chunk.name === 'main',
321
- enforce: true,
322
- test: /[\\/]node_modules[\\/]/,
323
- },
324
- },
325
- },
326
- };
327
- config.resolve.mainFields = ['browser', 'module', 'main'];
328
- config.module = {
329
- ...config.module,
330
- rules: [
331
- ...(config.module.rules ?? []),
332
- // Images: Inline small images, and emit a separate file otherwise.
333
- {
334
- test: /\.(avif|bmp|gif|ico|jpe?g|png|webp)$/,
335
- type: 'asset',
336
- parser: {
337
- dataUrlCondition: {
338
- maxSize: 10_000, // 10 kB
339
- },
340
- },
341
- generator: {
342
- filename: `[name]${hashFormat.file}[ext]`,
343
- },
344
- },
345
- // SVG: same as image but we need to separate it so it can be swapped for SVGR in the React plugin.
346
- {
347
- test: /\.svg$/,
348
- type: 'asset',
349
- parser: {
350
- dataUrlCondition: {
351
- maxSize: 10_000, // 10 kB
352
- },
353
- },
354
- generator: {
355
- filename: `[name]${hashFormat.file}[ext]`,
356
- },
357
- },
358
- // Fonts: Emit separate file and export the URL.
359
- {
360
- test: /\.(eot|otf|ttf|woff|woff2)$/,
361
- type: 'asset/resource',
362
- generator: {
363
- filename: `[name]${hashFormat.file}[ext]`,
364
- },
365
- },
366
- ...rules,
367
- ],
368
- };
369
- config.plugins ??= [];
370
- config.plugins.push(...plugins);
371
- }
372
- exports.applyWebConfig = applyWebConfig;