@nx/webpack 17.2.0-beta.6 → 17.2.0-beta.9

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 (39) hide show
  1. package/package.json +4 -4
  2. package/plugin.d.ts +1 -0
  3. package/plugin.js +5 -0
  4. package/src/executors/dev-server/dev-server.impl.js +16 -25
  5. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +2 -3
  6. package/src/executors/dev-server/lib/get-dev-server-config.js +18 -26
  7. package/src/executors/dev-server/schema.d.ts +8 -8
  8. package/src/executors/webpack/lib/normalize-options.js +6 -2
  9. package/src/executors/webpack/schema.d.ts +5 -3
  10. package/src/executors/webpack/schema.json +26 -51
  11. package/src/executors/webpack/webpack.impl.js +21 -19
  12. package/src/generators/configuration/configuration.js +69 -18
  13. package/src/generators/init/init.js +28 -2
  14. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +146 -127
  15. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +15 -5
  16. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +2 -1
  17. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +25 -2
  18. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +3 -1
  19. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +132 -3
  20. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +1 -2
  21. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +9 -17
  22. package/src/plugins/plugin.d.ts +9 -0
  23. package/src/plugins/plugin.js +127 -0
  24. package/src/utils/config.d.ts +11 -6
  25. package/src/utils/config.js +48 -13
  26. package/src/utils/has-plugin.d.ts +2 -0
  27. package/src/utils/has-plugin.js +11 -0
  28. package/src/utils/versions.d.ts +1 -0
  29. package/src/utils/versions.js +2 -1
  30. package/src/utils/webpack/read-webpack-options.d.ts +10 -0
  31. package/src/utils/webpack/read-webpack-options.js +41 -0
  32. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +1 -0
  33. package/src/utils/webpack/{custom-webpack.js → resolve-user-defined-webpack-config.js} +3 -8
  34. package/src/utils/with-nx.d.ts +4 -5
  35. package/src/utils/with-nx.js +7 -1
  36. package/src/utils/with-web.d.ts +2 -2
  37. package/src/executors/webpack/lib/get-webpack-config.d.ts +0 -5
  38. package/src/executors/webpack/lib/get-webpack-config.js +0 -16
  39. package/src/utils/webpack/custom-webpack.d.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "17.2.0-beta.6",
3
+ "version": "17.2.0-beta.9",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
6
6
  "repository": {
@@ -62,9 +62,9 @@
62
62
  "webpack-dev-server": "^4.9.3",
63
63
  "webpack-node-externals": "^3.0.0",
64
64
  "webpack-subresource-integrity": "^5.1.0",
65
- "@nx/devkit": "17.2.0-beta.6",
66
- "@nx/js": "17.2.0-beta.6",
67
- "@nrwl/webpack": "17.2.0-beta.6"
65
+ "@nx/devkit": "17.2.0-beta.9",
66
+ "@nx/js": "17.2.0-beta.9",
67
+ "@nrwl/webpack": "17.2.0-beta.9"
68
68
  },
69
69
  "publishConfig": {
70
70
  "access": "public"
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes } from './src/plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = void 0;
4
+ var plugin_1 = require("./src/plugins/plugin");
5
+ Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
@@ -9,49 +9,40 @@ const WebpackDevServer = require("webpack-dev-server");
9
9
  const get_dev_server_config_1 = require("./lib/get-dev-server-config");
10
10
  const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
11
11
  const run_webpack_1 = require("../../utils/run-webpack");
12
- const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
12
+ const resolve_user_defined_webpack_config_1 = require("../../utils/webpack/resolve-user-defined-webpack-config");
13
13
  const normalize_options_1 = require("../webpack/lib/normalize-options");
14
- const path_1 = require("path");
14
+ const config_1 = require("../../utils/config");
15
+ const js_1 = require("@nx/js");
15
16
  async function* devServerExecutor(serveOptions, context) {
16
17
  // Default to dev mode so builds are faster and HMR mode works better.
17
18
  process.env.NODE_ENV ??= 'development';
18
19
  const { root: projectRoot, sourceRoot } = context.projectsConfigurations.projects[context.projectName];
19
20
  const buildOptions = (0, normalize_options_1.normalizeOptions)(getBuildOptions(serveOptions, context), context.root, projectRoot, sourceRoot);
20
- if (!buildOptions.index) {
21
- throw new Error(`Cannot run dev-server without "index" option. Check the build options for ${context.projectName}.`);
22
- }
21
+ // TODO(jack): Figure out a way to port this into NxWebpackPlugin
23
22
  if (!buildOptions.buildLibsFromSource) {
23
+ if (!buildOptions.tsConfig) {
24
+ throw new Error(`Cannot find "tsConfig" to remap paths for. Set this option in project.json.`);
25
+ }
24
26
  const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // should be generalized
25
27
  context.configurationName);
26
28
  buildOptions.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(buildOptions.tsConfig, context.root, target.data.root, dependencies);
27
29
  }
28
- let config = (0, get_dev_server_config_1.getDevServerConfig)(context, buildOptions, serveOptions);
30
+ let config;
31
+ const devServer = (0, get_dev_server_config_1.getDevServerOptions)(context.root, serveOptions, buildOptions);
29
32
  if (buildOptions.webpackConfig) {
30
- let tsconfigPath = buildOptions.tsConfig.startsWith(context.root)
31
- ? buildOptions.tsConfig
32
- : (0, path_1.join)(context.root, buildOptions.tsConfig);
33
- let customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(buildOptions.webpackConfig, tsconfigPath);
34
- if (typeof customWebpack.then === 'function') {
35
- customWebpack = await customWebpack;
33
+ let userDefinedWebpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)(buildOptions.webpackConfig, (0, js_1.getRootTsConfigPath)());
34
+ if (typeof userDefinedWebpackConfig.then === 'function') {
35
+ userDefinedWebpackConfig = await userDefinedWebpackConfig;
36
36
  }
37
- if (typeof customWebpack === 'function') {
38
- // Old behavior, call the webpack function that is specific to Nx
39
- config = await customWebpack(config, {
37
+ // Only add the dev server option if user is composable plugin.
38
+ // Otherwise, user should define `devServer` option directly in their webpack config.
39
+ if ((0, config_1.isNxWebpackComposablePlugin)(userDefinedWebpackConfig)) {
40
+ config = await userDefinedWebpackConfig({ devServer }, {
40
41
  options: buildOptions,
41
42
  context,
42
43
  configuration: serveOptions.buildTarget.split(':')[2],
43
44
  });
44
45
  }
45
- else if (customWebpack) {
46
- // New behavior, use the config object as is with devServer defaults
47
- config = {
48
- devServer: {
49
- ...customWebpack.devServer,
50
- ...config.devServer,
51
- },
52
- ...customWebpack,
53
- };
54
- }
55
46
  }
56
47
  return yield* (0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
57
48
  console.info(stats.toString(config.stats));
@@ -1,5 +1,4 @@
1
- import { ExecutorContext } from '@nx/devkit';
2
- import type { Configuration as WebpackConfiguration } from 'webpack';
1
+ import type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
3
2
  import { WebDevServerOptions } from '../schema';
4
3
  import { NormalizedWebpackExecutorOptions } from '../../webpack/schema';
5
- export declare function getDevServerConfig(context: ExecutorContext, buildOptions: NormalizedWebpackExecutorOptions, serveOptions: WebDevServerOptions): Partial<WebpackConfiguration>;
4
+ export declare function getDevServerOptions(root: string, serveOptions: WebDevServerOptions, buildOptions: NormalizedWebpackExecutorOptions): WebpackDevServerConfiguration;
@@ -1,21 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDevServerConfig = void 0;
3
+ exports.getDevServerOptions = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path = require("path");
6
6
  const fs_1 = require("fs");
7
- const get_webpack_config_1 = require("../../webpack/lib/get-webpack-config");
8
7
  const serve_path_1 = require("./serve-path");
9
- function getDevServerConfig(context, buildOptions, serveOptions) {
10
- const workspaceRoot = context.root;
11
- const webpackConfig = buildOptions.isolatedConfig
12
- ? {}
13
- : (0, get_webpack_config_1.getWebpackConfig)(context, buildOptions);
14
- webpackConfig.devServer = getDevServerPartial(workspaceRoot, serveOptions, buildOptions);
15
- return webpackConfig;
16
- }
17
- exports.getDevServerConfig = getDevServerConfig;
18
- function getDevServerPartial(root, options, buildOptions) {
8
+ function getDevServerOptions(root, serveOptions, buildOptions) {
19
9
  const servePath = (0, serve_path_1.buildServePath)(buildOptions);
20
10
  let scriptsOptimization;
21
11
  let stylesOptimization;
@@ -30,11 +20,12 @@ function getDevServerPartial(root, options, buildOptions) {
30
20
  scriptsOptimization = stylesOptimization = false;
31
21
  }
32
22
  const config = {
33
- host: options.host,
34
- port: options.port,
23
+ host: serveOptions.host,
24
+ port: serveOptions.port,
35
25
  headers: { 'Access-Control-Allow-Origin': '*' },
36
26
  historyApiFallback: {
37
- index: `${servePath}${path.basename(buildOptions.index)}`,
27
+ index: buildOptions.index &&
28
+ `${servePath}${path.basename(buildOptions.index)}`,
38
29
  disableDotRule: true,
39
30
  htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
40
31
  },
@@ -42,7 +33,7 @@ function getDevServerPartial(root, options, buildOptions) {
42
33
  const isHttps = server.options.https || server.options.server?.type === 'https';
43
34
  devkit_1.logger.info(`NX Web Development Server is listening at ${isHttps ? 'https' : 'http'}://${server.options.host}:${server.options.port}${(0, serve_path_1.buildServePath)(buildOptions)}`);
44
35
  },
45
- open: options.open,
36
+ open: serveOptions.open,
46
37
  static: false,
47
38
  compress: scriptsOptimization || stylesOptimization,
48
39
  devMiddleware: {
@@ -50,31 +41,32 @@ function getDevServerPartial(root, options, buildOptions) {
50
41
  stats: false,
51
42
  },
52
43
  client: {
53
- webSocketURL: options.publicHost,
44
+ webSocketURL: serveOptions.publicHost,
54
45
  overlay: {
55
46
  errors: !(scriptsOptimization || stylesOptimization),
56
47
  warnings: false,
57
48
  },
58
49
  },
59
- liveReload: options.hmr ? false : options.liveReload,
60
- hot: options.hmr,
50
+ liveReload: serveOptions.hmr ? false : serveOptions.liveReload,
51
+ hot: serveOptions.hmr,
61
52
  };
62
- if (options.ssl) {
53
+ if (serveOptions.ssl) {
63
54
  config.server = {
64
55
  type: 'https',
65
56
  };
66
- if (options.sslKey && options.sslCert) {
67
- config.server.options = getSslConfig(root, options);
57
+ if (serveOptions.sslKey && serveOptions.sslCert) {
58
+ config.server.options = getSslConfig(root, serveOptions);
68
59
  }
69
60
  }
70
- if (options.proxyConfig) {
71
- config.proxy = getProxyConfig(root, options);
61
+ if (serveOptions.proxyConfig) {
62
+ config.proxy = getProxyConfig(root, serveOptions);
72
63
  }
73
- if (options.allowedHosts) {
74
- config.allowedHosts = options.allowedHosts.split(',');
64
+ if (serveOptions.allowedHosts) {
65
+ config.allowedHosts = serveOptions.allowedHosts.split(',');
75
66
  }
76
67
  return config;
77
68
  }
69
+ exports.getDevServerOptions = getDevServerOptions;
78
70
  function getSslConfig(root, options) {
79
71
  return {
80
72
  key: (0, fs_1.readFileSync)(path.resolve(root, options.sslKey), 'utf-8'),
@@ -1,17 +1,17 @@
1
1
  export interface WebDevServerOptions {
2
- host: string;
3
- port: number;
2
+ host?: string;
3
+ port?: number;
4
4
  publicHost?: string;
5
- ssl: boolean;
5
+ ssl?: boolean;
6
6
  sslKey?: string;
7
7
  sslCert?: string;
8
8
  proxyConfig?: string;
9
9
  buildTarget: string;
10
- open: boolean;
11
- liveReload: boolean;
12
- hmr: boolean;
13
- watch: boolean;
14
- allowedHosts: string;
10
+ open?: boolean;
11
+ liveReload?: boolean;
12
+ hmr?: boolean;
13
+ watch?: boolean;
14
+ allowedHosts?: string;
15
15
  memoryLimit?: number;
16
16
  baseHref?: string;
17
17
  }
@@ -4,15 +4,15 @@ exports.normalizePluginPath = exports.normalizeOptions = void 0;
4
4
  const path_1 = require("path");
5
5
  const normalize_options_1 = require("../../../plugins/nx-webpack-plugin/lib/normalize-options");
6
6
  function normalizeOptions(options, root, projectRoot, sourceRoot) {
7
- return {
7
+ const normalizedOptions = {
8
8
  ...options,
9
9
  root,
10
10
  projectRoot,
11
11
  sourceRoot,
12
12
  target: options.target ?? 'web',
13
13
  outputFileName: options.outputFileName ?? 'main.js',
14
- assets: (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot),
15
14
  webpackConfig: normalizePluginPath(options.webpackConfig, root),
15
+ fileReplacements: (0, normalize_options_1.normalizeFileReplacements)(root, options.fileReplacements),
16
16
  optimization: typeof options.optimization !== 'object'
17
17
  ? {
18
18
  scripts: options.optimization,
@@ -20,6 +20,10 @@ function normalizeOptions(options, root, projectRoot, sourceRoot) {
20
20
  }
21
21
  : options.optimization,
22
22
  };
23
+ if (options.assets) {
24
+ normalizedOptions.assets = (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot);
25
+ }
26
+ return normalizedOptions;
23
27
  }
24
28
  exports.normalizeOptions = normalizeOptions;
25
29
  function normalizePluginPath(pluginPath, root) {
@@ -47,8 +47,10 @@ export interface WebpackExecutorOptions {
47
47
  extractLicenses?: boolean;
48
48
  fileReplacements?: FileReplacement[];
49
49
  generatePackageJson?: boolean;
50
+ // TODO(v18): Remove this option
51
+ /** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
50
52
  isolatedConfig?: boolean;
51
- main: string;
53
+ main?: string;
52
54
  memoryLimit?: number;
53
55
  namedChunks?: boolean;
54
56
  optimization?: boolean | OptimizationOptions;
@@ -61,9 +63,9 @@ export interface WebpackExecutorOptions {
61
63
  runtimeChunk?: boolean;
62
64
  sourceMap?: boolean | 'hidden';
63
65
  statsJson?: boolean;
64
- target?: 'node' | 'web' | 'webworker';
66
+ target?: string;
65
67
  transformers?: TransformerEntry[];
66
- tsConfig: string;
68
+ tsConfig?: string;
67
69
  vendorChunk?: boolean;
68
70
  verbose?: boolean;
69
71
  watch?: boolean;
@@ -27,8 +27,7 @@
27
27
  "compiler": {
28
28
  "type": "string",
29
29
  "description": "The compiler to use.",
30
- "enum": ["babel", "swc", "tsc"],
31
- "default": "babel"
30
+ "enum": ["babel", "swc", "tsc"]
32
31
  },
33
32
  "outputPath": {
34
33
  "type": "string",
@@ -40,8 +39,7 @@
40
39
  "type": "string",
41
40
  "alias": "platform",
42
41
  "description": "Target platform for the build, same as the Webpack target option.",
43
- "enum": ["node", "web", "webworker"],
44
- "default": "web"
42
+ "enum": ["node", "web", "webworker"]
45
43
  },
46
44
  "deleteOutputPath": {
47
45
  "type": "boolean",
@@ -50,8 +48,7 @@
50
48
  },
51
49
  "watch": {
52
50
  "type": "boolean",
53
- "description": "Enable re-building when files change.",
54
- "default": false
51
+ "description": "Enable re-building when files change."
55
52
  },
56
53
  "baseHref": {
57
54
  "type": "string",
@@ -63,22 +60,18 @@
63
60
  },
64
61
  "vendorChunk": {
65
62
  "type": "boolean",
66
- "description": "Use a separate bundle containing only vendor libraries.",
67
- "default": true
63
+ "description": "Use a separate bundle containing only vendor libraries."
68
64
  },
69
65
  "commonChunk": {
70
66
  "type": "boolean",
71
- "description": "Use a separate bundle containing code used across multiple bundles.",
72
- "default": true
67
+ "description": "Use a separate bundle containing code used across multiple bundles."
73
68
  },
74
69
  "runtimeChunk": {
75
70
  "type": "boolean",
76
- "description": "Use a separate bundle containing the runtime.",
77
- "default": true
71
+ "description": "Use a separate bundle containing the runtime."
78
72
  },
79
73
  "sourceMap": {
80
74
  "description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
81
- "default": true,
82
75
  "oneOf": [
83
76
  {
84
77
  "type": "boolean"
@@ -90,13 +83,11 @@
90
83
  },
91
84
  "progress": {
92
85
  "type": "boolean",
93
- "description": "Log progress to the console while building.",
94
- "default": false
86
+ "description": "Log progress to the console while building."
95
87
  },
96
88
  "assets": {
97
89
  "type": "array",
98
90
  "description": "List of static application assets.",
99
- "default": [],
100
91
  "items": {
101
92
  "$ref": "#/definitions/assetPattern"
102
93
  }
@@ -112,26 +103,22 @@
112
103
  "description": "External Scripts which will be included before the main application entry.",
113
104
  "items": {
114
105
  "$ref": "#/definitions/extraEntryPoint"
115
- },
116
- "default": []
106
+ }
117
107
  },
118
108
  "styles": {
119
109
  "type": "array",
120
110
  "description": "External Styles which will be included with the application",
121
111
  "items": {
122
112
  "$ref": "#/definitions/extraEntryPoint"
123
- },
124
- "default": []
113
+ }
125
114
  },
126
115
  "namedChunks": {
127
116
  "type": "boolean",
128
- "description": "Names the produced bundles according to their entry file.",
129
- "default": true
117
+ "description": "Names the produced bundles according to their entry file."
130
118
  },
131
119
  "outputHashing": {
132
120
  "type": "string",
133
121
  "description": "Define the output filename cache-busting hashing mode.",
134
- "default": "none",
135
122
  "enum": ["none", "all", "media", "bundles"]
136
123
  },
137
124
  "stylePreprocessorOptions": {
@@ -143,8 +130,7 @@
143
130
  "type": "array",
144
131
  "items": {
145
132
  "type": "string"
146
- },
147
- "default": []
133
+ }
148
134
  }
149
135
  },
150
136
  "additionalProperties": false
@@ -175,13 +161,11 @@
175
161
  },
176
162
  "generatePackageJson": {
177
163
  "type": "boolean",
178
- "description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated.",
179
- "default": false
164
+ "description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated."
180
165
  },
181
166
  "transformers": {
182
167
  "type": "array",
183
168
  "description": "List of TypeScript Compiler Transfomers Plugins.",
184
- "default": [],
185
169
  "aliases": ["tsPlugins"],
186
170
  "items": {
187
171
  "$ref": "#/definitions/transformerPattern"
@@ -223,18 +207,15 @@
223
207
  }
224
208
  }
225
209
  ],
226
- "description": "Dependencies to keep external to the bundle. (`all` (default), `none`, or an array of module names)",
227
- "default": "all"
210
+ "description": "Dependencies to keep external to the bundle. (`all` (default), `none`, or an array of module names)"
228
211
  },
229
212
  "extractCss": {
230
213
  "type": "boolean",
231
- "description": "Extract CSS into a `.css` file.",
232
- "default": true
214
+ "description": "Extract CSS into a `.css` file."
233
215
  },
234
216
  "subresourceIntegrity": {
235
217
  "type": "boolean",
236
- "description": "Enables the use of subresource integrity validation.",
237
- "default": false
218
+ "description": "Enables the use of subresource integrity validation."
238
219
  },
239
220
  "polyfills": {
240
221
  "type": "string",
@@ -244,28 +225,25 @@
244
225
  },
245
226
  "verbose": {
246
227
  "type": "boolean",
247
- "description": "Emits verbose output",
248
- "default": false
228
+ "description": "Emits verbose output"
249
229
  },
250
230
  "statsJson": {
251
231
  "type": "boolean",
252
- "description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or `<https://webpack.github.io/analyse>`.",
253
- "default": false
232
+ "description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or `<https://webpack.github.io/analyse>`."
254
233
  },
255
234
  "isolatedConfig": {
256
235
  "type": "boolean",
257
236
  "description": "Do not apply Nx webpack plugins automatically. Plugins need to be applied in the project's webpack.config.js file (e.g. withNx, withReact, etc.).",
258
- "default": true
237
+ "default": true,
238
+ "x-deprecated": "Automatic configuration of Webpack is deprecated in favor of an explicit 'webpack.config.js' file. This option will be removed in Nx 18. See https://nx.dev/recipes/webpack/webpack-config-setup."
259
239
  },
260
240
  "extractLicenses": {
261
241
  "type": "boolean",
262
- "description": "Extract all licenses in a separate file, in the case of production builds only.",
263
- "default": false
242
+ "description": "Extract all licenses in a separate file, in the case of production builds only."
264
243
  },
265
244
  "memoryLimit": {
266
245
  "type": "number",
267
- "description": "Memory limit for type checking service process in `MB`.",
268
- "default": 2048
246
+ "description": "Memory limit for type checking service process in `MB`."
269
247
  },
270
248
  "fileReplacements": {
271
249
  "description": "Replace files with other files in the build.",
@@ -286,18 +264,16 @@
286
264
  },
287
265
  "additionalProperties": false,
288
266
  "required": ["replace", "with"]
289
- },
290
- "default": []
267
+ }
291
268
  },
292
269
  "buildLibsFromSource": {
293
270
  "type": "boolean",
294
- "description": "Read buildable libraries from source instead of building them separately.",
271
+ "description": "Read buildable libraries from source instead of building them separately. If set to `false`, the `tsConfig` option must also be set to remap paths.",
295
272
  "default": true
296
273
  },
297
274
  "generateIndexHtml": {
298
275
  "type": "boolean",
299
- "description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`.",
300
- "default": true
276
+ "description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`."
301
277
  },
302
278
  "postcssConfig": {
303
279
  "type": "string",
@@ -312,8 +288,7 @@
312
288
  },
313
289
  "babelUpwardRootMode": {
314
290
  "type": "boolean",
315
- "description": "Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode",
316
- "default": false
291
+ "description": "Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode"
317
292
  },
318
293
  "babelConfig": {
319
294
  "type": "string",
@@ -321,7 +296,7 @@
321
296
  "x-completion-type": "file"
322
297
  }
323
298
  },
324
- "required": ["tsConfig", "main"],
299
+ "required": [],
325
300
  "definitions": {
326
301
  "assetPattern": {
327
302
  "oneOf": [
@@ -7,38 +7,39 @@ const rxjs_1 = require("rxjs");
7
7
  const operators_1 = require("rxjs/operators");
8
8
  const path_1 = require("path");
9
9
  const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
10
- const get_webpack_config_1 = require("./lib/get-webpack-config");
11
10
  const run_webpack_1 = require("./lib/run-webpack");
12
11
  const fs_1 = require("../../utils/fs");
13
- const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
12
+ const resolve_user_defined_webpack_config_1 = require("../../utils/webpack/resolve-user-defined-webpack-config");
14
13
  const normalize_options_1 = require("./lib/normalize-options");
15
- async function getWebpackConfigs(options, projectRoot, context) {
14
+ const config_1 = require("../../utils/config");
15
+ const with_nx_1 = require("../../utils/with-nx");
16
+ const js_1 = require("@nx/js");
17
+ const with_web_1 = require("../../utils/with-web");
18
+ async function getWebpackConfigs(options, context) {
16
19
  if (options.isolatedConfig && !options.webpackConfig) {
17
20
  throw new Error(`Using "isolatedConfig" without a "webpackConfig" is not supported.`);
18
21
  }
19
- let customWebpack = null;
20
- if (options.webpackConfig && options.tsConfig) {
21
- customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(options.webpackConfig, options.tsConfig.startsWith(context.root)
22
- ? options.tsConfig
23
- : (0, path_1.join)(context.root, options.tsConfig));
24
- if (typeof customWebpack.then === 'function') {
25
- customWebpack = await customWebpack;
22
+ let userDefinedWebpackConfig = null;
23
+ if (options.webpackConfig) {
24
+ userDefinedWebpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)(options.webpackConfig, (0, js_1.getRootTsConfigPath)());
25
+ if (typeof userDefinedWebpackConfig.then === 'function') {
26
+ userDefinedWebpackConfig = await userDefinedWebpackConfig;
26
27
  }
27
28
  }
28
29
  const config = options.isolatedConfig
29
30
  ? {}
30
- : (0, get_webpack_config_1.getWebpackConfig)(context, options);
31
- if (typeof customWebpack === 'function') {
31
+ : (0, config_1.composePlugins)((0, with_nx_1.withNx)(options), (0, with_web_1.withWeb)(options));
32
+ if ((0, config_1.isNxWebpackComposablePlugin)(userDefinedWebpackConfig)) {
32
33
  // Old behavior, call the Nx-specific webpack config function that user exports
33
- return await customWebpack(config, {
34
+ return await userDefinedWebpackConfig(config, {
34
35
  options,
35
36
  context,
36
37
  configuration: context.configurationName, // backwards compat
37
38
  });
38
39
  }
39
- else if (customWebpack) {
40
+ else if (userDefinedWebpackConfig) {
40
41
  // New behavior, we want the webpack config to export object
41
- return customWebpack;
42
+ return userDefinedWebpackConfig;
42
43
  }
43
44
  else {
44
45
  // Fallback case, if we cannot find a webpack config path
@@ -46,8 +47,8 @@ async function getWebpackConfigs(options, projectRoot, context) {
46
47
  }
47
48
  }
48
49
  async function* webpackExecutor(_options, context) {
49
- // Pass to NxWebpackPlugin so we can get the CLI overrides.
50
- process.env['NX_WEBPACK_EXECUTOR_RAW_OPTIONS'] = JSON.stringify(_options);
50
+ // Default to production build.
51
+ process.env['NODE_ENV'] ||= 'production';
51
52
  const metadata = context.projectsConfigurations.projects[context.projectName];
52
53
  const sourceRoot = metadata.sourceRoot;
53
54
  const options = (0, normalize_options_1.normalizeOptions)(_options, context.root, metadata.root, sourceRoot);
@@ -68,7 +69,6 @@ async function* webpackExecutor(_options, context) {
68
69
  devkit_1.logger.error(`Missing SWC dependencies: @swc/core, swc-loader. Make sure you install them first.`);
69
70
  return {
70
71
  success: false,
71
- outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
72
72
  options,
73
73
  };
74
74
  }
@@ -85,7 +85,7 @@ async function* webpackExecutor(_options, context) {
85
85
  devkit_1.logger.warn((0, devkit_1.stripIndents) `The project ${context.projectName} is using the 'generatePackageJson' option which is deprecated for library projects. It should only be used for applications.
86
86
  For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`);
87
87
  }
88
- const configs = await getWebpackConfigs(options, metadata.root, context);
88
+ const configs = await getWebpackConfigs(options, context);
89
89
  return yield* (0, rxjs_for_await_1.eachValueFrom)((0, rxjs_1.of)(configs).pipe((0, operators_1.mergeMap)((config) => (Array.isArray(config) ? (0, rxjs_1.from)(config) : (0, rxjs_1.of)(config))),
90
90
  // Run build sequentially and bail when first one fails.
91
91
  (0, operators_1.mergeScan)((acc, config) => {
@@ -101,6 +101,8 @@ async function* webpackExecutor(_options, context) {
101
101
  // Collect build results as an array.
102
102
  (0, operators_1.bufferCount)(Array.isArray(configs) ? configs.length : 1), (0, operators_1.switchMap)(async (results) => {
103
103
  const success = results.every((result) => Boolean(result) && !result.hasErrors());
104
+ // TODO(jack): This should read output from webpack config if provided.
105
+ // The outfile is only used by NestJS, where `@nx/js:node` executor requires it to run the file.
104
106
  return {
105
107
  success,
106
108
  outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),