@nx/webpack 17.0.3 → 17.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) 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 +28 -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.js +1 -1
  62. package/src/utils/module-federation/remotes.js +1 -1
  63. package/src/utils/module-federation/secondary-entry-points.js +1 -1
  64. package/src/utils/module-federation/typescript.js +14 -9
  65. package/src/utils/versions.d.ts +1 -0
  66. package/src/utils/versions.js +2 -1
  67. package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
  68. package/src/utils/webpack/interpolate-env-variables-to-index.js +4 -1
  69. package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
  70. package/src/utils/webpack/read-webpack-options.d.ts +10 -0
  71. package/src/utils/webpack/read-webpack-options.js +41 -0
  72. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
  73. package/src/utils/webpack/{custom-webpack.js → resolve-user-defined-webpack-config.js} +14 -8
  74. package/src/utils/with-nx.d.ts +4 -58
  75. package/src/utils/with-nx.js +22 -362
  76. package/src/utils/with-web.d.ts +2 -2
  77. package/src/utils/with-web.js +9 -488
  78. package/src/executors/webpack/lib/get-webpack-config.d.ts +0 -5
  79. package/src/executors/webpack/lib/get-webpack-config.js +0 -16
  80. package/src/utils/webpack/custom-webpack.d.ts +0 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 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,4 +1,9 @@
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>
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>
2
7
 
3
8
  <div style="text-align: center;">
4
9
 
@@ -15,9 +20,9 @@
15
20
 
16
21
  <hr>
17
22
 
18
- # Nx: Smart, Fast and Extensible Build System
23
+ # Nx: Smart Monorepos · Fast CI
19
24
 
20
- Nx is a next generation build system with first class monorepo support and powerful integrations.
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.
21
26
 
22
27
  This package is a [Webpack plugin for Nx](https://nx.dev/packages/webpack).
23
28
 
@@ -59,5 +64,5 @@ npx nx@latest init
59
64
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
60
65
 
61
66
  <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"
62
- width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
63
68
 
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#webpackInitGenerator",
6
+ "factory": "./src/generators/init/init#webpackInitGeneratorInternal",
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",
14
+ "factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
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 * from './src/generators/init/init';
7
+ export { webpackInitGenerator } 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,3 +14,5 @@ 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.webpackProjectGenerator = exports.configurationGenerator = void 0;
3
+ exports.NxTsconfigPathsWebpackPlugin = exports.NxWebpackPlugin = exports.webpackInitGenerator = 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,7 +9,8 @@ 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
- tslib_1.__exportStar(require("./src/generators/init/init"), exports);
12
+ var init_1 = require("./src/generators/init/init");
13
+ Object.defineProperty(exports, "webpackInitGenerator", { enumerable: true, get: function () { return init_1.webpackInitGenerator; } });
13
14
  tslib_1.__exportStar(require("./src/executors/dev-server/dev-server.impl"), exports);
14
15
  tslib_1.__exportStar(require("./src/executors/webpack/lib/normalize-options"), exports);
15
16
  tslib_1.__exportStar(require("./src/executors/webpack/webpack.impl"), exports);
@@ -17,3 +18,7 @@ tslib_1.__exportStar(require("./src/utils/get-css-module-local-ident"), exports)
17
18
  tslib_1.__exportStar(require("./src/utils/with-nx"), exports);
18
19
  tslib_1.__exportStar(require("./src/utils/with-web"), exports);
19
20
  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,6 +29,12 @@
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"
32
38
  }
33
39
  },
34
40
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "17.0.3",
3
+ "version": "17.0.4",
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,7 +29,8 @@
29
29
  "migrations": "./migrations.json"
30
30
  },
31
31
  "dependencies": {
32
- "@babel/core": "^7.22.9",
32
+ "@babel/core": "^7.23.2",
33
+ "ajv": "^8.12.0",
33
34
  "autoprefixer": "^10.4.9",
34
35
  "babel-loader": "^9.1.2",
35
36
  "browserslist": "^4.21.4",
@@ -62,9 +63,9 @@
62
63
  "webpack-dev-server": "^4.9.3",
63
64
  "webpack-node-externals": "^3.0.0",
64
65
  "webpack-subresource-integrity": "^5.1.0",
65
- "@nx/devkit": "17.0.3",
66
- "@nx/js": "17.0.3",
67
- "@nrwl/webpack": "17.0.3"
66
+ "@nx/devkit": "17.0.4",
67
+ "@nx/js": "17.0.4",
68
+ "@nrwl/webpack": "17.0.4"
68
69
  },
69
70
  "publishConfig": {
70
71
  "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,36 +9,50 @@ 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
+ 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
23
24
  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
+ }
24
28
  const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // should be generalized
25
29
  context.configurationName);
26
30
  buildOptions.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(buildOptions.tsConfig, context.root, target.data.root, dependencies);
31
+ process.env.NX_TSCONFIG_PATH = buildOptions.tsConfig;
27
32
  }
28
- let config = (0, get_dev_server_config_1.getDevServerConfig)(context, buildOptions, serveOptions);
33
+ let config;
34
+ const devServer = (0, get_dev_server_config_1.getDevServerOptions)(context.root, serveOptions, buildOptions);
29
35
  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;
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;
36
55
  }
37
- config = await customWebpack(config, {
38
- options: buildOptions,
39
- context,
40
- configuration: serveOptions.buildTarget.split(':')[2],
41
- });
42
56
  }
43
57
  return yield* (0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
44
58
  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, // disable liveReload if hmr is enabled
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
  }
@@ -1,4 +1,3 @@
1
- import type { AssetGlobPattern, NormalizedWebpackExecutorOptions, WebpackExecutorOptions } from '../schema';
1
+ import type { 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,39 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeAssets = exports.normalizePluginPath = exports.normalizeOptions = void 0;
3
+ exports.normalizePluginPath = exports.normalizeOptions = void 0;
4
4
  const path_1 = require("path");
5
- const fs_1 = require("fs");
6
- const devkit_1 = require("@nx/devkit");
5
+ const normalize_options_1 = require("../../../plugins/nx-webpack-plugin/lib/normalize-options");
7
6
  function normalizeOptions(options, root, projectRoot, sourceRoot) {
8
- return {
7
+ const normalizedOptions = {
9
8
  ...options,
10
9
  root,
11
10
  projectRoot,
12
11
  sourceRoot,
13
12
  target: options.target ?? 'web',
14
- main: (0, path_1.resolve)(root, options.main),
15
- outputPath: (0, path_1.resolve)(root, options.outputPath),
16
13
  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),
20
14
  webpackConfig: normalizePluginPath(options.webpackConfig, root),
15
+ fileReplacements: (0, normalize_options_1.normalizeFileReplacements)(root, options.fileReplacements),
21
16
  optimization: typeof options.optimization !== 'object'
22
17
  ? {
23
18
  scripts: options.optimization,
24
19
  styles: options.optimization,
25
20
  }
26
21
  : options.optimization,
27
- polyfills: options.polyfills ? (0, path_1.resolve)(root, options.polyfills) : undefined,
28
22
  };
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;
29
28
  }
30
29
  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
- }
37
30
  function normalizePluginPath(pluginPath, root) {
38
31
  if (!pluginPath) {
39
32
  return '';
@@ -46,40 +39,3 @@ function normalizePluginPath(pluginPath, root) {
46
39
  }
47
40
  }
48
41
  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,8 +47,11 @@ 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) */
50
52
  isolatedConfig?: boolean;
51
- main: string;
53
+ standardWebpackConfigFunction?: boolean;
54
+ main?: string;
52
55
  memoryLimit?: number;
53
56
  namedChunks?: boolean;
54
57
  optimization?: boolean | OptimizationOptions;
@@ -61,9 +64,9 @@ export interface WebpackExecutorOptions {
61
64
  runtimeChunk?: boolean;
62
65
  sourceMap?: boolean | 'hidden';
63
66
  statsJson?: boolean;
64
- target?: 'node' | 'web' | 'webworker';
67
+ target?: string;
65
68
  transformers?: TransformerEntry[];
66
- tsConfig: string;
69
+ tsConfig?: string;
67
70
  vendorChunk?: boolean;
68
71
  verbose?: boolean;
69
72
  watch?: boolean;
@@ -86,8 +89,8 @@ export interface WebpackExecutorOptions {
86
89
  export interface NormalizedWebpackExecutorOptions
87
90
  extends WebpackExecutorOptions {
88
91
  outputFileName: string;
89
- assets?: AssetGlobPattern[];
90
- root?: string;
91
- projectRoot?: string;
92
- sourceRoot?: string;
92
+ assets: AssetGlobPattern[];
93
+ root: string;
94
+ projectRoot: string;
95
+ sourceRoot: string;
93
96
  }