@nx/webpack 17.0.3 → 17.0.5

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 (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/generators.json +2 -2
  4. package/index.d.ts +3 -1
  5. package/index.js +7 -2
  6. package/migrations.json +6 -0
  7. package/package.json +6 -5
  8. package/plugin.d.ts +1 -0
  9. package/plugin.js +5 -0
  10. package/src/executors/dev-server/dev-server.impl.js +31 -17
  11. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +2 -3
  12. package/src/executors/dev-server/lib/get-dev-server-config.js +18 -26
  13. package/src/executors/dev-server/schema.d.ts +8 -8
  14. package/src/executors/webpack/lib/normalize-options.d.ts +1 -2
  15. package/src/executors/webpack/lib/normalize-options.js +9 -53
  16. package/src/executors/webpack/schema.d.ts +10 -7
  17. package/src/executors/webpack/schema.json +30 -50
  18. package/src/executors/webpack/webpack.impl.js +36 -16
  19. package/src/generators/configuration/configuration.d.ts +3 -2
  20. package/src/generators/configuration/configuration.js +95 -23
  21. package/src/generators/configuration/schema.d.ts +1 -0
  22. package/src/generators/configuration/schema.json +1 -1
  23. package/src/generators/init/init.d.ts +1 -0
  24. package/src/generators/init/init.js +48 -23
  25. package/src/generators/init/schema.d.ts +4 -2
  26. package/src/generators/init/schema.json +18 -13
  27. package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +2 -0
  28. package/src/migrations/update-17-2-1/webpack-config-setup.js +31 -0
  29. package/src/plugins/generate-package-json-plugin.d.ts +6 -4
  30. package/src/plugins/generate-package-json-plugin.js +11 -14
  31. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +8 -0
  32. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +31 -0
  33. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +5 -0
  34. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +318 -0
  35. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +5 -0
  36. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +372 -0
  37. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +53 -0
  38. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +78 -0
  39. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +1 -0
  40. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +35 -0
  41. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +3 -0
  42. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +42 -0
  43. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +4 -0
  44. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +148 -0
  45. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +73 -0
  46. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +117 -0
  47. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +216 -0
  48. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +2 -0
  49. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +17 -0
  50. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +48 -0
  51. package/src/plugins/plugin.d.ts +9 -0
  52. package/src/plugins/plugin.js +132 -0
  53. package/src/utils/config.d.ts +11 -6
  54. package/src/utils/config.js +48 -13
  55. package/src/utils/ensure-dependencies.d.ts +6 -0
  56. package/src/utils/ensure-dependencies.js +27 -0
  57. package/src/utils/get-client-environment.js +4 -1
  58. package/src/utils/has-plugin.d.ts +2 -0
  59. package/src/utils/has-plugin.js +11 -0
  60. package/src/utils/module-federation/dependencies.js +15 -3
  61. package/src/utils/module-federation/get-remotes-for-host.d.ts +2 -1
  62. package/src/utils/module-federation/get-remotes-for-host.js +11 -7
  63. package/src/utils/module-federation/remotes.js +1 -1
  64. package/src/utils/module-federation/secondary-entry-points.js +1 -1
  65. package/src/utils/module-federation/typescript.js +14 -9
  66. package/src/utils/versions.d.ts +1 -1
  67. package/src/utils/versions.js +2 -2
  68. package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
  69. package/src/utils/webpack/interpolate-env-variables-to-index.js +4 -1
  70. package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
  71. package/src/utils/webpack/read-webpack-options.d.ts +10 -0
  72. package/src/utils/webpack/read-webpack-options.js +41 -0
  73. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
  74. package/src/utils/webpack/{custom-webpack.js → resolve-user-defined-webpack-config.js} +14 -8
  75. package/src/utils/with-nx.d.ts +4 -58
  76. package/src/utils/with-nx.js +22 -362
  77. package/src/utils/with-web.d.ts +2 -2
  78. package/src/utils/with-web.js +9 -488
  79. package/src/executors/webpack/lib/get-webpack-config.d.ts +0 -5
  80. package/src/executors/webpack/lib/get-webpack-config.js +0 -16
  81. package/src/utils/webpack/custom-webpack.d.ts +0 -2
@@ -1,27 +1,32 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "$id": "NxWebpackInit",
4
4
  "cli": "nx",
5
5
  "title": "Init Webpack Plugin",
6
6
  "description": "Initialize the Webpack Plugin.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "uiFramework": {
10
- "type": "string",
11
- "description": "UI Framework to use for Webpack.",
12
- "enum": ["react", "none"],
13
- "x-prompt": "What UI framework plugin should Webpack use?"
14
- },
15
- "compiler": {
16
- "type": "string",
17
- "enum": ["babel", "swc", "tsc"],
18
- "description": "The compiler to initialize for.",
19
- "default": "babel"
20
- },
21
9
  "skipFormat": {
22
10
  "description": "Skip formatting files.",
23
11
  "type": "boolean",
24
12
  "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ },
25
+ "updatePackageScripts": {
26
+ "type": "boolean",
27
+ "x-priority": "internal",
28
+ "description": "Update `package.json` scripts with inferred targets",
29
+ "default": false
25
30
  }
26
31
  },
27
32
  "required": []
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
+ async function default_1(tree) {
6
+ const update = (options, projectName, targetName, configurationName) => {
7
+ // Only handle webpack config for default configuration
8
+ if (configurationName)
9
+ return;
10
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
11
+ if (!options.webpackConfig && options.isolatedConfig !== false) {
12
+ options.webpackConfig = `${projectConfiguration.root}/webpack.config.js`;
13
+ tree.write(options.webpackConfig, `
14
+ const { composePlugins, withNx } = require('@nx/webpack');
15
+
16
+ // Nx plugins for webpack.
17
+ module.exports = composePlugins(withNx(), (config) => {
18
+ // Note: This was added by an Nx migration. Webpack builds are required to have a corresponding Webpack config file.
19
+ // See: https://nx.dev/recipes/webpack/webpack-config-setup
20
+ return config;
21
+ });
22
+ `);
23
+ projectConfiguration.targets[targetName].options = options;
24
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
25
+ }
26
+ };
27
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/webpack:webpack', update);
28
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', update);
29
+ await (0, devkit_1.formatFiles)(tree);
30
+ }
31
+ exports.default = default_1;
@@ -1,12 +1,14 @@
1
1
  import { type Compiler, type WebpackPluginInstance } from 'webpack';
2
- import { ExecutorContext } from '@nx/devkit';
2
+ import { type ProjectGraph } from '@nx/devkit';
3
3
  export declare class GeneratePackageJsonPlugin implements WebpackPluginInstance {
4
4
  private readonly options;
5
- private readonly context;
6
- private readonly projectGraph;
7
5
  constructor(options: {
8
6
  tsConfig: string;
9
7
  outputFileName: string;
10
- }, context: ExecutorContext);
8
+ root: string;
9
+ projectName: string;
10
+ targetName: string;
11
+ projectGraph: ProjectGraph;
12
+ });
11
13
  apply(compiler: Compiler): void;
12
14
  }
@@ -4,13 +4,10 @@ exports.GeneratePackageJsonPlugin = void 0;
4
4
  const webpack_1 = require("webpack");
5
5
  const js_1 = require("@nx/js");
6
6
  const devkit_1 = require("@nx/devkit");
7
- const js_2 = require("@nx/js");
8
7
  const pluginName = 'GeneratePackageJsonPlugin';
9
8
  class GeneratePackageJsonPlugin {
10
- constructor(options, context) {
9
+ constructor(options) {
11
10
  this.options = options;
12
- this.context = context;
13
- this.projectGraph = context.projectGraph;
14
11
  }
15
12
  apply(compiler) {
16
13
  compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
@@ -18,28 +15,28 @@ class GeneratePackageJsonPlugin {
18
15
  name: pluginName,
19
16
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
20
17
  }, () => {
21
- const helperDependencies = (0, js_2.getHelperDependenciesFromProjectGraph)(this.context.root, this.context.projectName, this.projectGraph);
22
- const importHelpers = !!(0, js_2.readTsConfig)(this.options.tsConfig).options
18
+ const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.options.root, this.options.projectName, this.options.projectGraph);
19
+ const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
23
20
  .importHelpers;
24
21
  const shouldAddHelperDependency = importHelpers &&
25
- helperDependencies.every((dep) => dep.target !== js_2.HelperDependency.tsc);
22
+ helperDependencies.every((dep) => dep.target !== js_1.HelperDependency.tsc);
26
23
  if (shouldAddHelperDependency) {
27
24
  helperDependencies.push({
28
25
  type: 'static',
29
- source: this.context.projectName,
30
- target: js_2.HelperDependency.tsc,
26
+ source: this.options.projectName,
27
+ target: js_1.HelperDependency.tsc,
31
28
  });
32
29
  }
33
- const packageJson = (0, js_1.createPackageJson)(this.context.projectName, this.projectGraph, {
34
- target: this.context.targetName,
35
- root: this.context.root,
30
+ const packageJson = (0, js_1.createPackageJson)(this.options.projectName, this.options.projectGraph, {
31
+ target: this.options.targetName,
32
+ root: this.options.root,
36
33
  isProduction: true,
37
34
  helperDependencies: helperDependencies.map((dep) => dep.target),
38
35
  });
39
36
  packageJson.main = packageJson.main ?? this.options.outputFileName;
40
37
  compilation.emitAsset('package.json', new webpack_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
41
- const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
42
- compilation.emitAsset((0, js_2.getLockFileName)(packageManager), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
38
+ const packageManager = (0, devkit_1.detectPackageManager)(this.options.root);
39
+ compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.options.projectGraph, packageManager)));
43
40
  });
44
41
  });
45
42
  }
@@ -0,0 +1,8 @@
1
+ import { Compiler } from 'webpack';
2
+ export declare class NxTsconfigPathsWebpackPlugin {
3
+ private options;
4
+ constructor(options: {
5
+ tsConfig: string;
6
+ });
7
+ apply(compiler: Compiler): void;
8
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxTsconfigPathsWebpackPlugin = void 0;
4
+ const path = require("path");
5
+ const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
6
+ const devkit_1 = require("@nx/devkit");
7
+ class NxTsconfigPathsWebpackPlugin {
8
+ constructor(options) {
9
+ this.options = options;
10
+ if (!this.options.tsConfig)
11
+ throw new Error(`Missing "tsConfig" option. Set this option in your Nx webpack plugin.`);
12
+ }
13
+ apply(compiler) {
14
+ const extensions = new Set([
15
+ ...['.ts', '.tsx', '.mjs', '.js', '.jsx'],
16
+ ...(compiler.options?.resolve?.extensions ?? []),
17
+ ]);
18
+ compiler.options.resolve = {
19
+ ...compiler.options.resolve,
20
+ plugins: compiler.options.resolve?.plugins ?? [],
21
+ };
22
+ compiler.options.resolve.plugins.push(new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
23
+ configFile: !path.isAbsolute(this.options.tsConfig)
24
+ ? path.join(devkit_1.workspaceRoot, this.options.tsConfig)
25
+ : this.options.tsConfig,
26
+ extensions: Array.from(extensions),
27
+ mainFields: ['module', 'main'],
28
+ }));
29
+ }
30
+ }
31
+ exports.NxTsconfigPathsWebpackPlugin = NxTsconfigPathsWebpackPlugin;
@@ -0,0 +1,5 @@
1
+ import { Configuration, WebpackOptionsNormalized } from 'webpack';
2
+ import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
3
+ export declare function applyBaseConfig(options: NormalizedNxWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
4
+ useNormalizedEntry?: boolean;
5
+ }): void;
@@ -0,0 +1,318 @@
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
+ }
@@ -0,0 +1,5 @@
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;