@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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,9 +1,4 @@
1
- <p style="text-align: center;">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
- <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
- </picture>
6
- </p>
1
+ <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
7
2
 
8
3
  <div style="text-align: center;">
9
4
 
@@ -20,9 +15,9 @@
20
15
 
21
16
  <hr>
22
17
 
23
- # Nx: Smart Monorepos · Fast CI
18
+ # Nx: Smart, Fast and Extensible Build System
24
19
 
25
- Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
20
+ Nx is a next generation build system with first class monorepo support and powerful integrations.
26
21
 
27
22
  This package is a [Webpack plugin for Nx](https://nx.dev/packages/webpack).
28
23
 
@@ -64,5 +59,5 @@ npx nx@latest init
64
59
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
65
60
 
66
61
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
- width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
62
+ width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
68
63
 
package/generators.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "version": "0.1",
4
4
  "generators": {
5
5
  "init": {
6
- "factory": "./src/generators/init/init#webpackInitGeneratorInternal",
6
+ "factory": "./src/generators/init/init#webpackInitGenerator",
7
7
  "schema": "./src/generators/init/schema.json",
8
8
  "description": "Initialize the `@nrwl/webpack` plugin.",
9
9
  "aliases": ["ng-add"],
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "configuration": {
13
13
  "aliases": ["webpack-project"],
14
- "factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
14
+ "factory": "./src/generators/configuration/configuration",
15
15
  "schema": "./src/generators/configuration/schema.json",
16
16
  "description": "Add webpack configuration to a project.",
17
17
  "hidden": true
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { configurationGenerator };
4
4
  export declare const webpackProjectGenerator: typeof configurationGenerator;
5
5
  export * from './src/utils/create-copy-plugin';
6
6
  export * from './src/utils/config';
7
- export { webpackInitGenerator } from './src/generators/init/init';
7
+ export * from './src/generators/init/init';
8
8
  export type { WebDevServerOptions } from './src/executors/dev-server/schema';
9
9
  export * from './src/executors/dev-server/dev-server.impl';
10
10
  export * from './src/executors/webpack/lib/normalize-options';
@@ -14,5 +14,3 @@ export * from './src/utils/get-css-module-local-ident';
14
14
  export * from './src/utils/with-nx';
15
15
  export * from './src/utils/with-web';
16
16
  export * from './src/utils/module-federation/public-api';
17
- export { NxWebpackPlugin } from './src/plugins/nx-webpack-plugin/nx-webpack-plugin';
18
- export { NxTsconfigPathsWebpackPlugin } from './src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NxTsconfigPathsWebpackPlugin = exports.NxWebpackPlugin = exports.webpackInitGenerator = exports.webpackProjectGenerator = exports.configurationGenerator = void 0;
3
+ exports.webpackProjectGenerator = exports.configurationGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const configuration_1 = require("./src/generators/configuration/configuration");
6
6
  Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
@@ -9,8 +9,7 @@ Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get
9
9
  exports.webpackProjectGenerator = configuration_1.configurationGenerator;
10
10
  tslib_1.__exportStar(require("./src/utils/create-copy-plugin"), exports);
11
11
  tslib_1.__exportStar(require("./src/utils/config"), exports);
12
- var init_1 = require("./src/generators/init/init");
13
- Object.defineProperty(exports, "webpackInitGenerator", { enumerable: true, get: function () { return init_1.webpackInitGenerator; } });
12
+ tslib_1.__exportStar(require("./src/generators/init/init"), exports);
14
13
  tslib_1.__exportStar(require("./src/executors/dev-server/dev-server.impl"), exports);
15
14
  tslib_1.__exportStar(require("./src/executors/webpack/lib/normalize-options"), exports);
16
15
  tslib_1.__exportStar(require("./src/executors/webpack/webpack.impl"), exports);
@@ -18,7 +17,3 @@ tslib_1.__exportStar(require("./src/utils/get-css-module-local-ident"), exports)
18
17
  tslib_1.__exportStar(require("./src/utils/with-nx"), exports);
19
18
  tslib_1.__exportStar(require("./src/utils/with-web"), exports);
20
19
  tslib_1.__exportStar(require("./src/utils/module-federation/public-api"), exports);
21
- var nx_webpack_plugin_1 = require("./src/plugins/nx-webpack-plugin/nx-webpack-plugin");
22
- Object.defineProperty(exports, "NxWebpackPlugin", { enumerable: true, get: function () { return nx_webpack_plugin_1.NxWebpackPlugin; } });
23
- var nx_tsconfig_paths_webpack_plugin_1 = require("./src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin");
24
- Object.defineProperty(exports, "NxTsconfigPathsWebpackPlugin", { enumerable: true, get: function () { return nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin; } });
package/migrations.json CHANGED
@@ -29,12 +29,6 @@
29
29
  "version": "16.0.0-beta.1",
30
30
  "description": "Replace @nrwl/webpack with @nx/webpack",
31
31
  "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
32
- },
33
- "update-17-2-1-webpack-config-setup": {
34
- "cli": "nx",
35
- "version": "17.2.1-beta.0",
36
- "description": "Add webpack.config.js file when webpackConfig is not defined",
37
- "implementation": "./src/migrations/update-17-2-1/webpack-config-setup"
38
32
  }
39
33
  },
40
34
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "17.0.4",
3
+ "version": "v17.0.6",
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": {
@@ -29,8 +29,7 @@
29
29
  "migrations": "./migrations.json"
30
30
  },
31
31
  "dependencies": {
32
- "@babel/core": "^7.23.2",
33
- "ajv": "^8.12.0",
32
+ "@babel/core": "^7.22.9",
34
33
  "autoprefixer": "^10.4.9",
35
34
  "babel-loader": "^9.1.2",
36
35
  "browserslist": "^4.21.4",
@@ -63,9 +62,9 @@
63
62
  "webpack-dev-server": "^4.9.3",
64
63
  "webpack-node-externals": "^3.0.0",
65
64
  "webpack-subresource-integrity": "^5.1.0",
66
- "@nx/devkit": "17.0.4",
67
- "@nx/js": "17.0.4",
68
- "@nrwl/webpack": "17.0.4"
65
+ "@nx/devkit": "v17.0.6",
66
+ "@nx/js": "v17.0.6",
67
+ "@nrwl/webpack": "v17.0.6"
69
68
  },
70
69
  "publishConfig": {
71
70
  "access": "public"
@@ -9,50 +9,36 @@ 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 resolve_user_defined_webpack_config_1 = require("../../utils/webpack/resolve-user-defined-webpack-config");
12
+ const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
13
13
  const normalize_options_1 = require("../webpack/lib/normalize-options");
14
- const config_1 = require("../../utils/config");
15
- const js_1 = require("@nx/js");
14
+ const path_1 = require("path");
16
15
  async function* devServerExecutor(serveOptions, context) {
17
16
  // Default to dev mode so builds are faster and HMR mode works better.
18
17
  process.env.NODE_ENV ??= 'development';
19
18
  const { root: projectRoot, sourceRoot } = context.projectsConfigurations.projects[context.projectName];
20
19
  const buildOptions = (0, normalize_options_1.normalizeOptions)(getBuildOptions(serveOptions, context), context.root, projectRoot, sourceRoot);
21
- process.env.NX_BUILD_LIBS_FROM_SOURCE = `${buildOptions.buildLibsFromSource}`;
22
- process.env.NX_BUILD_TARGET = serveOptions.buildTarget;
23
- // TODO(jack): Figure out a way to port this into NxWebpackPlugin
20
+ if (!buildOptions.index) {
21
+ throw new Error(`Cannot run dev-server without "index" option. Check the build options for ${context.projectName}.`);
22
+ }
24
23
  if (!buildOptions.buildLibsFromSource) {
25
- if (!buildOptions.tsConfig) {
26
- throw new Error(`Cannot find "tsConfig" to remap paths for. Set this option in project.json.`);
27
- }
28
24
  const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // should be generalized
29
25
  context.configurationName);
30
26
  buildOptions.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(buildOptions.tsConfig, context.root, target.data.root, dependencies);
31
- process.env.NX_TSCONFIG_PATH = buildOptions.tsConfig;
32
27
  }
33
- let config;
34
- const devServer = (0, get_dev_server_config_1.getDevServerOptions)(context.root, serveOptions, buildOptions);
28
+ let config = (0, get_dev_server_config_1.getDevServerConfig)(context, buildOptions, serveOptions);
35
29
  if (buildOptions.webpackConfig) {
36
- let userDefinedWebpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)(buildOptions.webpackConfig, (0, js_1.getRootTsConfigPath)());
37
- if (typeof userDefinedWebpackConfig.then === 'function') {
38
- userDefinedWebpackConfig = await userDefinedWebpackConfig;
39
- }
40
- // Only add the dev server option if user is composable plugin.
41
- // Otherwise, user should define `devServer` option directly in their webpack config.
42
- if (typeof userDefinedWebpackConfig === 'function' &&
43
- ((0, config_1.isNxWebpackComposablePlugin)(userDefinedWebpackConfig) ||
44
- !buildOptions.standardWebpackConfigFunction)) {
45
- config = await userDefinedWebpackConfig({ devServer }, {
46
- options: buildOptions,
47
- context,
48
- configuration: serveOptions.buildTarget.split(':')[2],
49
- });
50
- }
51
- else if (userDefinedWebpackConfig) {
52
- // New behavior, we want the webpack config to export object
53
- config = userDefinedWebpackConfig;
54
- config.devServer ??= devServer;
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;
55
36
  }
37
+ config = await customWebpack(config, {
38
+ options: buildOptions,
39
+ context,
40
+ configuration: serveOptions.buildTarget.split(':')[2],
41
+ });
56
42
  }
57
43
  return yield* (0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
58
44
  console.info(stats.toString(config.stats));
@@ -1,4 +1,5 @@
1
- import type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import type { Configuration as WebpackConfiguration } from 'webpack';
2
3
  import { WebDevServerOptions } from '../schema';
3
4
  import { NormalizedWebpackExecutorOptions } from '../../webpack/schema';
4
- export declare function getDevServerOptions(root: string, serveOptions: WebDevServerOptions, buildOptions: NormalizedWebpackExecutorOptions): WebpackDevServerConfiguration;
5
+ export declare function getDevServerConfig(context: ExecutorContext, buildOptions: NormalizedWebpackExecutorOptions, serveOptions: WebDevServerOptions): Partial<WebpackConfiguration>;
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDevServerOptions = void 0;
3
+ exports.getDevServerConfig = 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");
7
8
  const serve_path_1 = require("./serve-path");
8
- function getDevServerOptions(root, serveOptions, buildOptions) {
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) {
9
19
  const servePath = (0, serve_path_1.buildServePath)(buildOptions);
10
20
  let scriptsOptimization;
11
21
  let stylesOptimization;
@@ -20,12 +30,11 @@ function getDevServerOptions(root, serveOptions, buildOptions) {
20
30
  scriptsOptimization = stylesOptimization = false;
21
31
  }
22
32
  const config = {
23
- host: serveOptions.host,
24
- port: serveOptions.port,
33
+ host: options.host,
34
+ port: options.port,
25
35
  headers: { 'Access-Control-Allow-Origin': '*' },
26
36
  historyApiFallback: {
27
- index: buildOptions.index &&
28
- `${servePath}${path.basename(buildOptions.index)}`,
37
+ index: `${servePath}${path.basename(buildOptions.index)}`,
29
38
  disableDotRule: true,
30
39
  htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
31
40
  },
@@ -33,7 +42,7 @@ function getDevServerOptions(root, serveOptions, buildOptions) {
33
42
  const isHttps = server.options.https || server.options.server?.type === 'https';
34
43
  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)}`);
35
44
  },
36
- open: serveOptions.open,
45
+ open: options.open,
37
46
  static: false,
38
47
  compress: scriptsOptimization || stylesOptimization,
39
48
  devMiddleware: {
@@ -41,32 +50,31 @@ function getDevServerOptions(root, serveOptions, buildOptions) {
41
50
  stats: false,
42
51
  },
43
52
  client: {
44
- webSocketURL: serveOptions.publicHost,
53
+ webSocketURL: options.publicHost,
45
54
  overlay: {
46
55
  errors: !(scriptsOptimization || stylesOptimization),
47
56
  warnings: false,
48
57
  },
49
58
  },
50
- liveReload: serveOptions.hmr ? false : serveOptions.liveReload, // disable liveReload if hmr is enabled
51
- hot: serveOptions.hmr,
59
+ liveReload: options.hmr ? false : options.liveReload,
60
+ hot: options.hmr,
52
61
  };
53
- if (serveOptions.ssl) {
62
+ if (options.ssl) {
54
63
  config.server = {
55
64
  type: 'https',
56
65
  };
57
- if (serveOptions.sslKey && serveOptions.sslCert) {
58
- config.server.options = getSslConfig(root, serveOptions);
66
+ if (options.sslKey && options.sslCert) {
67
+ config.server.options = getSslConfig(root, options);
59
68
  }
60
69
  }
61
- if (serveOptions.proxyConfig) {
62
- config.proxy = getProxyConfig(root, serveOptions);
70
+ if (options.proxyConfig) {
71
+ config.proxy = getProxyConfig(root, options);
63
72
  }
64
- if (serveOptions.allowedHosts) {
65
- config.allowedHosts = serveOptions.allowedHosts.split(',');
73
+ if (options.allowedHosts) {
74
+ config.allowedHosts = options.allowedHosts.split(',');
66
75
  }
67
76
  return config;
68
77
  }
69
- exports.getDevServerOptions = getDevServerOptions;
70
78
  function getSslConfig(root, options) {
71
79
  return {
72
80
  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
  }
@@ -0,0 +1,5 @@
1
+ import type { Configuration } from 'webpack';
2
+ import { ExecutorContext } from '@nx/devkit';
3
+ import { NormalizedWebpackExecutorOptions } from '../schema';
4
+ /** @deprecated Use withNx, withWeb, or withReact */
5
+ export declare function getWebpackConfig(context: ExecutorContext, options: NormalizedWebpackExecutorOptions): Configuration;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebpackConfig = void 0;
4
+ const with_nx_1 = require("../../../utils/with-nx");
5
+ const with_web_1 = require("../../../utils/with-web");
6
+ const config_1 = require("../../../utils/config");
7
+ /** @deprecated Use withNx, withWeb, or withReact */
8
+ // TODO(jack): Remove in Nx 16
9
+ function getWebpackConfig(context, options) {
10
+ const config = {};
11
+ const configure = options.target === 'web'
12
+ ? (0, config_1.composePluginsSync)((0, with_nx_1.withNx)(), (0, with_web_1.withWeb)())
13
+ : (0, with_nx_1.withNx)();
14
+ return configure(config, { options, context });
15
+ }
16
+ exports.getWebpackConfig = getWebpackConfig;
@@ -1,3 +1,4 @@
1
- import type { NormalizedWebpackExecutorOptions, WebpackExecutorOptions } from '../schema';
1
+ import type { AssetGlobPattern, NormalizedWebpackExecutorOptions, WebpackExecutorOptions } from '../schema';
2
2
  export declare function normalizeOptions(options: WebpackExecutorOptions, root: string, projectRoot: string, sourceRoot: string): NormalizedWebpackExecutorOptions;
3
3
  export declare function normalizePluginPath(pluginPath: void | string, root: string): string;
4
+ export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string): AssetGlobPattern[];
@@ -1,32 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizePluginPath = exports.normalizeOptions = void 0;
3
+ exports.normalizeAssets = exports.normalizePluginPath = exports.normalizeOptions = void 0;
4
4
  const path_1 = require("path");
5
- const normalize_options_1 = require("../../../plugins/nx-webpack-plugin/lib/normalize-options");
5
+ const fs_1 = require("fs");
6
+ const devkit_1 = require("@nx/devkit");
6
7
  function normalizeOptions(options, root, projectRoot, sourceRoot) {
7
- const normalizedOptions = {
8
+ return {
8
9
  ...options,
9
10
  root,
10
11
  projectRoot,
11
12
  sourceRoot,
12
13
  target: options.target ?? 'web',
14
+ main: (0, path_1.resolve)(root, options.main),
15
+ outputPath: (0, path_1.resolve)(root, options.outputPath),
13
16
  outputFileName: options.outputFileName ?? 'main.js',
17
+ tsConfig: (0, path_1.resolve)(root, options.tsConfig),
18
+ fileReplacements: normalizeFileReplacements(root, options.fileReplacements),
19
+ assets: normalizeAssets(options.assets, root, sourceRoot),
14
20
  webpackConfig: normalizePluginPath(options.webpackConfig, root),
15
- fileReplacements: (0, normalize_options_1.normalizeFileReplacements)(root, options.fileReplacements),
16
21
  optimization: typeof options.optimization !== 'object'
17
22
  ? {
18
23
  scripts: options.optimization,
19
24
  styles: options.optimization,
20
25
  }
21
26
  : options.optimization,
27
+ polyfills: options.polyfills ? (0, path_1.resolve)(root, options.polyfills) : undefined,
22
28
  };
23
- if (options.assets) {
24
- normalizedOptions.assets = (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot, projectRoot, false // executor assets are relative to workspace root for consistency
25
- );
26
- }
27
- return normalizedOptions;
28
29
  }
29
30
  exports.normalizeOptions = normalizeOptions;
31
+ function normalizeFileReplacements(root, fileReplacements) {
32
+ return fileReplacements.map((fileReplacement) => ({
33
+ replace: (0, path_1.resolve)(root, fileReplacement.replace),
34
+ with: (0, path_1.resolve)(root, fileReplacement.with),
35
+ }));
36
+ }
30
37
  function normalizePluginPath(pluginPath, root) {
31
38
  if (!pluginPath) {
32
39
  return '';
@@ -39,3 +46,40 @@ function normalizePluginPath(pluginPath, root) {
39
46
  }
40
47
  }
41
48
  exports.normalizePluginPath = normalizePluginPath;
49
+ function normalizeAssets(assets, root, sourceRoot) {
50
+ return assets.map((asset) => {
51
+ if (typeof asset === 'string') {
52
+ const assetPath = (0, devkit_1.normalizePath)(asset);
53
+ const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
54
+ const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot);
55
+ if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
56
+ throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`);
57
+ }
58
+ const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory();
59
+ const input = isDirectory
60
+ ? resolvedAssetPath
61
+ : (0, path_1.dirname)(resolvedAssetPath);
62
+ const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input));
63
+ const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath);
64
+ return {
65
+ input,
66
+ output,
67
+ glob,
68
+ };
69
+ }
70
+ else {
71
+ if (asset.output.startsWith('..')) {
72
+ throw new Error('An asset cannot be written to a location outside of the output path.');
73
+ }
74
+ const assetPath = (0, devkit_1.normalizePath)(asset.input);
75
+ const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
76
+ return {
77
+ ...asset,
78
+ input: resolvedAssetPath,
79
+ // Now we remove starting slash to make Webpack place it from the output root.
80
+ output: asset.output.replace(/^\//, ''),
81
+ };
82
+ }
83
+ });
84
+ }
85
+ exports.normalizeAssets = normalizeAssets;
@@ -47,11 +47,8 @@ export interface WebpackExecutorOptions {
47
47
  extractLicenses?: boolean;
48
48
  fileReplacements?: FileReplacement[];
49
49
  generatePackageJson?: boolean;
50
- // TODO(v19): Remove this option
51
- /** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
52
50
  isolatedConfig?: boolean;
53
- standardWebpackConfigFunction?: boolean;
54
- main?: string;
51
+ main: string;
55
52
  memoryLimit?: number;
56
53
  namedChunks?: boolean;
57
54
  optimization?: boolean | OptimizationOptions;
@@ -64,9 +61,9 @@ export interface WebpackExecutorOptions {
64
61
  runtimeChunk?: boolean;
65
62
  sourceMap?: boolean | 'hidden';
66
63
  statsJson?: boolean;
67
- target?: string;
64
+ target?: 'node' | 'web' | 'webworker';
68
65
  transformers?: TransformerEntry[];
69
- tsConfig?: string;
66
+ tsConfig: string;
70
67
  vendorChunk?: boolean;
71
68
  verbose?: boolean;
72
69
  watch?: boolean;
@@ -89,8 +86,8 @@ export interface WebpackExecutorOptions {
89
86
  export interface NormalizedWebpackExecutorOptions
90
87
  extends WebpackExecutorOptions {
91
88
  outputFileName: string;
92
- assets: AssetGlobPattern[];
93
- root: string;
94
- projectRoot: string;
95
- sourceRoot: string;
89
+ assets?: AssetGlobPattern[];
90
+ root?: string;
91
+ projectRoot?: string;
92
+ sourceRoot?: string;
96
93
  }