@nx/webpack 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba

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 (59) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/app-plugin.d.ts +2 -0
  4. package/app-plugin.js +5 -0
  5. package/index.d.ts +6 -2
  6. package/index.js +8 -5
  7. package/migrations.json +0 -24
  8. package/package.json +9 -8
  9. package/src/executors/dev-server/dev-server.impl.js +5 -0
  10. package/src/executors/webpack/lib/normalize-options.js +2 -1
  11. package/src/executors/webpack/schema.d.ts +3 -1
  12. package/src/executors/webpack/schema.json +9 -1
  13. package/src/executors/webpack/webpack.impl.js +1 -7
  14. package/src/generators/configuration/configuration.js +4 -4
  15. package/src/generators/init/init.js +24 -25
  16. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +4 -4
  17. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +19 -0
  18. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +2 -2
  19. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +23 -16
  20. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +2 -2
  21. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +5 -5
  22. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +2 -2
  23. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +6 -2
  24. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +2 -2
  25. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +3 -3
  26. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +46 -31
  27. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +4 -4
  28. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +2 -0
  29. package/src/plugins/nx-webpack-plugin/{nx-webpack-plugin-options.d.ts → nx-app-webpack-plugin-options.d.ts} +14 -2
  30. package/src/plugins/nx-webpack-plugin/{nx-webpack-plugin.d.ts → nx-app-webpack-plugin.d.ts} +3 -3
  31. package/src/plugins/nx-webpack-plugin/{nx-webpack-plugin.js → nx-app-webpack-plugin.js} +3 -3
  32. package/src/plugins/plugin.js +18 -12
  33. package/src/plugins/webpack-nx-build-coordination-plugin.js +1 -1
  34. package/src/utils/ensure-dependencies.js +0 -1
  35. package/src/utils/get-client-environment.js +3 -3
  36. package/src/utils/module-federation/get-remotes-for-host.d.ts +2 -1
  37. package/src/utils/module-federation/get-remotes-for-host.js +11 -7
  38. package/src/utils/module-federation/secondary-entry-points.js +2 -7
  39. package/src/utils/module-federation/share.js +9 -2
  40. package/src/utils/versions.d.ts +0 -1
  41. package/src/utils/versions.js +1 -2
  42. package/src/utils/webpack/deprecated-stylus-loader.js +1 -1
  43. package/src/utils/webpack/interpolate-env-variables-to-index.js +1 -1
  44. package/src/utils/webpack/package-chunk-sort.js +4 -2
  45. package/src/utils/webpack/plugins/postcss-cli-resources.d.ts +1 -0
  46. package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
  47. package/src/utils/webpack/resolve-user-defined-webpack-config.js +2 -3
  48. package/src/utils/with-nx.d.ts +2 -2
  49. package/tsconfig-paths-plugin.d.ts +1 -0
  50. package/tsconfig-paths-plugin.js +5 -0
  51. package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +0 -2
  52. package/src/migrations/update-15-0-0/add-babel-inputs.js +0 -9
  53. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.d.ts +0 -2
  54. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +0 -20
  55. package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +0 -2
  56. package/src/migrations/update-15-6-3/webpack-config-setup.js +0 -100
  57. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.d.ts +0 -2
  58. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +0 -17
  59. /package/src/plugins/nx-webpack-plugin/{nx-webpack-plugin-options.js → nx-app-webpack-plugin-options.js} +0 -0
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
@@ -24,7 +24,7 @@
24
24
 
25
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.
26
26
 
27
- This package is a [Webpack plugin for Nx](https://nx.dev/packages/webpack).
27
+ This package is a [Webpack plugin for Nx](https://nx.dev/nx-api/webpack).
28
28
 
29
29
  ## Getting Started
30
30
 
@@ -0,0 +1,2 @@
1
+ export { NxAppWebpackPlugin } from './src/plugins/nx-webpack-plugin/nx-app-webpack-plugin';
2
+ export type { NxAppWebpackPluginOptions } from './src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options';
package/app-plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxAppWebpackPlugin = void 0;
4
+ var nx_app_webpack_plugin_1 = require("./src/plugins/nx-webpack-plugin/nx-app-webpack-plugin");
5
+ Object.defineProperty(exports, "NxAppWebpackPlugin", { enumerable: true, get: function () { return nx_app_webpack_plugin_1.NxAppWebpackPlugin; } });
package/index.d.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import { configurationGenerator } from './src/generators/configuration/configuration';
2
+ import { NxAppWebpackPlugin } from './src/plugins/nx-webpack-plugin/nx-app-webpack-plugin';
3
+ import { NxTsconfigPathsWebpackPlugin as _NxTsconfigPathsWebpackPlugin } from './src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin';
2
4
  export { configurationGenerator };
3
5
  /** @deprecated Use `configurationGenerator` instead. */
4
6
  export declare const webpackProjectGenerator: typeof configurationGenerator;
7
+ /** @deprecated Use NxAppWebpackPlugin from `@nx/webpack/app-plugin` instead. */
8
+ export declare const NxWebpackPlugin: typeof NxAppWebpackPlugin;
9
+ /** @deprecated Use NxTsconfigPathsWebpackPlugin from `@nx/webpack/tsconfig-paths-plugin` instead. */
10
+ export declare const NxTsconfigPathsWebpackPlugin: typeof _NxTsconfigPathsWebpackPlugin;
5
11
  export * from './src/utils/create-copy-plugin';
6
12
  export * from './src/utils/config';
7
13
  export { webpackInitGenerator } from './src/generators/init/init';
@@ -14,5 +20,3 @@ export * from './src/utils/get-css-module-local-ident';
14
20
  export * from './src/utils/with-nx';
15
21
  export * from './src/utils/with-web';
16
22
  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,12 +1,19 @@
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.webpackInitGenerator = exports.NxTsconfigPathsWebpackPlugin = exports.NxWebpackPlugin = 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; } });
7
+ const nx_app_webpack_plugin_1 = require("./src/plugins/nx-webpack-plugin/nx-app-webpack-plugin");
8
+ const nx_tsconfig_paths_webpack_plugin_1 = require("./src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin");
7
9
  // Exported for backwards compatibility in case a plugin is using the old name.
8
10
  /** @deprecated Use `configurationGenerator` instead. */
9
11
  exports.webpackProjectGenerator = configuration_1.configurationGenerator;
12
+ // TODO(v20): Remove this in favor of deep imports in order to load configs faster (150-200ms faster).
13
+ /** @deprecated Use NxAppWebpackPlugin from `@nx/webpack/app-plugin` instead. */
14
+ exports.NxWebpackPlugin = nx_app_webpack_plugin_1.NxAppWebpackPlugin;
15
+ /** @deprecated Use NxTsconfigPathsWebpackPlugin from `@nx/webpack/tsconfig-paths-plugin` instead. */
16
+ exports.NxTsconfigPathsWebpackPlugin = nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin;
10
17
  tslib_1.__exportStar(require("./src/utils/create-copy-plugin"), exports);
11
18
  tslib_1.__exportStar(require("./src/utils/config"), exports);
12
19
  var init_1 = require("./src/generators/init/init");
@@ -18,7 +25,3 @@ tslib_1.__exportStar(require("./src/utils/get-css-module-local-ident"), exports)
18
25
  tslib_1.__exportStar(require("./src/utils/with-nx"), exports);
19
26
  tslib_1.__exportStar(require("./src/utils/with-web"), exports);
20
27
  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
@@ -1,29 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "add-babel-inputs": {
4
- "cli": "nx",
5
- "version": "15.0.0-beta.0",
6
- "description": "Adds babel.config.json to the hash of all tasks",
7
- "factory": "./src/migrations/update-15-0-0/add-babel-inputs"
8
- },
9
- "remove-es2015-polyfills-option": {
10
- "cli": "nx",
11
- "version": "15.4.5-beta.0",
12
- "description": "Removes es2015Polyfills option since legacy browsers are no longer supported.",
13
- "factory": "./src/migrations/update-15-4-5/remove-es2015-polyfills-option"
14
- },
15
- "webpack-config-setup": {
16
- "cli": "nx",
17
- "version": "15.6.3-beta.0",
18
- "description": "Creates or updates webpack.config.js file with the new options for webpack.",
19
- "factory": "./src/migrations/update-15-6-3/webpack-config-setup"
20
- },
21
- "add-babelUpwardRootMode-flag": {
22
- "cli": "nx",
23
- "version": "15.7.2-beta.0",
24
- "description": "Add the babelUpwardRootMode option to the build executor options.",
25
- "factory": "./src/migrations/update-15-7-2/add-babelUpwardRootMode-flag"
26
- },
27
3
  "update-16-0-0-add-nx-packages": {
28
4
  "cli": "nx",
29
5
  "version": "16.0.0-beta.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "0.0.0-pr-22179-271588f",
3
+ "version": "0.0.0-pr-26482-ebe2dba",
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": {
@@ -12,9 +12,10 @@
12
12
  "Monorepo",
13
13
  "Webpack",
14
14
  "Web",
15
- "CLI"
15
+ "CLI",
16
+ "Front-end"
16
17
  ],
17
- "main": "./index.js",
18
+ "main": "./index",
18
19
  "typings": "./index.d.ts",
19
20
  "author": "Victor Savkin",
20
21
  "license": "MIT",
@@ -45,13 +46,13 @@
45
46
  "loader-utils": "^2.0.3",
46
47
  "mini-css-extract-plugin": "~2.4.7",
47
48
  "parse5": "4.0.0",
48
- "postcss": "^8.4.14",
49
+ "postcss": "^8.4.38",
49
50
  "postcss-import": "~14.1.0",
50
51
  "postcss-loader": "^6.1.1",
51
52
  "rxjs": "^7.8.0",
52
53
  "sass": "^1.42.1",
53
54
  "sass-loader": "^12.2.0",
54
- "source-map-loader": "^3.0.0",
55
+ "source-map-loader": "^5.0.0",
55
56
  "style-loader": "^3.3.0",
56
57
  "stylus": "^0.59.0",
57
58
  "stylus-loader": "^7.1.0",
@@ -63,9 +64,9 @@
63
64
  "webpack-dev-server": "^4.9.3",
64
65
  "webpack-node-externals": "^3.0.0",
65
66
  "webpack-subresource-integrity": "^5.1.0",
66
- "@nx/devkit": "0.0.0-pr-22179-271588f",
67
- "@nx/js": "0.0.0-pr-22179-271588f",
68
- "@nrwl/webpack": "0.0.0-pr-22179-271588f"
67
+ "@nx/devkit": "0.0.0-pr-26482-ebe2dba",
68
+ "@nx/js": "0.0.0-pr-26482-ebe2dba",
69
+ "@nrwl/webpack": "0.0.0-pr-26482-ebe2dba"
69
70
  },
70
71
  "publishConfig": {
71
72
  "access": "public"
@@ -48,6 +48,11 @@ async function* devServerExecutor(serveOptions, context) {
48
48
  configuration: serveOptions.buildTarget.split(':')[2],
49
49
  });
50
50
  }
51
+ else if (userDefinedWebpackConfig) {
52
+ // New behavior, we want the webpack config to export object
53
+ config = userDefinedWebpackConfig;
54
+ config.devServer ??= devServer;
55
+ }
51
56
  }
52
57
  return yield* (0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
53
58
  console.info(stats.toString(config.stats));
@@ -21,7 +21,8 @@ function normalizeOptions(options, root, projectRoot, sourceRoot) {
21
21
  : options.optimization,
22
22
  };
23
23
  if (options.assets) {
24
- normalizedOptions.assets = (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot, projectRoot);
24
+ normalizedOptions.assets = (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot, projectRoot, false // executor assets are relative to workspace root for consistency
25
+ );
25
26
  }
26
27
  return normalizedOptions;
27
28
  }
@@ -47,7 +47,7 @@ export interface WebpackExecutorOptions {
47
47
  extractLicenses?: boolean;
48
48
  fileReplacements?: FileReplacement[];
49
49
  generatePackageJson?: boolean;
50
- // TODO(v19): Remove this option
50
+ // TODO(v20): Remove this option
51
51
  /** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
52
52
  isolatedConfig?: boolean;
53
53
  standardWebpackConfigFunction?: boolean;
@@ -84,6 +84,8 @@ export interface WebpackExecutorOptions {
84
84
  stylePreprocessorOptions?: any;
85
85
  styles?: Array<ExtraEntryPointClass | string>;
86
86
  subresourceIntegrity?: boolean;
87
+ publicPath?: string;
88
+ rebaseRootRelative?: boolean;
87
89
  }
88
90
 
89
91
  export interface NormalizedWebpackExecutorOptions
@@ -235,7 +235,7 @@
235
235
  "type": "boolean",
236
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.).",
237
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 19. See https://nx.dev/recipes/webpack/webpack-config-setup."
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 20. See https://nx.dev/recipes/webpack/webpack-config-setup."
239
239
  },
240
240
  "standardWebpackConfigFunction": {
241
241
  "type": "boolean",
@@ -299,6 +299,14 @@
299
299
  "type": "string",
300
300
  "description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
301
301
  "x-completion-type": "file"
302
+ },
303
+ "publicPath": {
304
+ "type": "string",
305
+ "description": "Set a public path for assets resources with absolute paths."
306
+ },
307
+ "rebaseRootRelative": {
308
+ "type": "boolean",
309
+ "description": "Whether to rebase absolute path for assets in postcss cli resources."
302
310
  }
303
311
  },
304
312
  "required": [],
@@ -6,7 +6,6 @@ const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
6
6
  const rxjs_1 = require("rxjs");
7
7
  const operators_1 = require("rxjs/operators");
8
8
  const path_1 = require("path");
9
- const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
10
9
  const run_webpack_1 = require("./lib/run-webpack");
11
10
  const fs_1 = require("../../utils/fs");
12
11
  const resolve_user_defined_webpack_config_1 = require("../../utils/webpack/resolve-user-defined-webpack-config");
@@ -83,18 +82,13 @@ async function* webpackExecutor(_options, context) {
83
82
  };
84
83
  }
85
84
  }
86
- if (!options.buildLibsFromSource && context.targetName) {
87
- const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
88
- options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, context.root, metadata.root, dependencies);
89
- process.env.NX_TSCONFIG_PATH = options.tsConfig;
90
- }
91
85
  // Delete output path before bundling
92
86
  if (options.deleteOutputPath && options.outputPath) {
93
87
  (0, fs_1.deleteOutputDir)(context.root, options.outputPath);
94
88
  }
95
89
  if (options.generatePackageJson && metadata.projectType !== 'application') {
96
90
  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.
97
- For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`);
91
+ For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/nx-api/eslint-plugin/documents/dependency-checks).`);
98
92
  }
99
93
  const configs = await getWebpackConfigs(options, context);
100
94
  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))),
@@ -63,7 +63,7 @@ function createWebpackConfig(tree, options) {
63
63
  if (options.target === 'web') {
64
64
  tree.write((0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'), (0, has_plugin_1.hasPlugin)(tree)
65
65
  ? `
66
- const { NxWebpackPlugin } = require('@nx/webpack');
66
+ const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
67
67
  const { join } = require('path');
68
68
 
69
69
  module.exports = {
@@ -71,7 +71,7 @@ module.exports = {
71
71
  path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
72
72
  },
73
73
  plugins: [
74
- new NxWebpackPlugin({
74
+ new NxAppWebpackPlugin({
75
75
  target: '${buildOptions.target}',
76
76
  tsConfig: '${buildOptions.tsConfig}',
77
77
  compiler: '${buildOptions.compiler}',
@@ -95,7 +95,7 @@ module.exports = composePlugins(withNx(), withWeb(), (config) => {
95
95
  else {
96
96
  tree.write((0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'), (0, has_plugin_1.hasPlugin)(tree)
97
97
  ? `
98
- const { NxWebpackPlugin } = require('@nx/webpack');
98
+ const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
99
99
  const { join } = require('path');
100
100
 
101
101
  module.exports = {
@@ -103,7 +103,7 @@ module.exports = {
103
103
  path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
104
104
  },
105
105
  plugins: [
106
- new NxWebpackPlugin({
106
+ new NxAppWebpackPlugin({
107
107
  target: '${buildOptions.target}',
108
108
  tsConfig: '${buildOptions.tsConfig}',
109
109
  compiler: '${buildOptions.compiler}',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webpackInitGeneratorInternal = exports.webpackInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
5
+ const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
6
6
  const plugin_1 = require("../../plugins/plugin");
7
7
  const versions_1 = require("../../utils/versions");
8
8
  function webpackInitGenerator(tree, schema) {
@@ -15,7 +15,29 @@ async function webpackInitGeneratorInternal(tree, schema) {
15
15
  nxJson.useInferencePlugins !== false;
16
16
  schema.addPlugin ??= addPluginDefault;
17
17
  if (schema.addPlugin) {
18
- addPlugin(tree);
18
+ await (0, add_plugin_1.addPluginV1)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/webpack/plugin', plugin_1.createNodes, {
19
+ buildTargetName: [
20
+ 'build',
21
+ 'webpack:build',
22
+ 'build:webpack',
23
+ 'webpack-build',
24
+ 'build-webpack',
25
+ ],
26
+ serveTargetName: [
27
+ 'serve',
28
+ 'webpack:serve',
29
+ 'serve:webpack',
30
+ 'webpack-serve',
31
+ 'serve-webpack',
32
+ ],
33
+ previewTargetName: [
34
+ 'preview',
35
+ 'webpack:preview',
36
+ 'preview:webpack',
37
+ 'webpack-preview',
38
+ 'preview-webpack',
39
+ ],
40
+ }, schema.updatePackageScripts);
19
41
  }
20
42
  let installTask = () => { };
21
43
  if (!schema.skipPackageJson) {
@@ -28,33 +50,10 @@ async function webpackInitGeneratorInternal(tree, schema) {
28
50
  }
29
51
  installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions);
30
52
  }
31
- if (schema.updatePackageScripts) {
32
- await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
33
- }
34
53
  if (!schema.skipFormat) {
35
54
  await (0, devkit_1.formatFiles)(tree);
36
55
  }
37
56
  return installTask;
38
57
  }
39
58
  exports.webpackInitGeneratorInternal = webpackInitGeneratorInternal;
40
- function addPlugin(tree) {
41
- const nxJson = (0, devkit_1.readNxJson)(tree);
42
- nxJson.plugins ??= [];
43
- for (const plugin of nxJson.plugins) {
44
- if (typeof plugin === 'string'
45
- ? plugin === '@nx/webpack/plugin'
46
- : plugin.plugin === '@nx/webpack/plugin') {
47
- return;
48
- }
49
- }
50
- nxJson.plugins.push({
51
- plugin: '@nx/webpack/plugin',
52
- options: {
53
- buildTargetName: 'build',
54
- serveTargetName: 'serve',
55
- previewTargetName: 'preview',
56
- },
57
- });
58
- (0, devkit_1.updateNxJson)(tree, nxJson);
59
- }
60
59
  exports.default = webpackInitGenerator;
@@ -1,8 +1,8 @@
1
- import { Compiler } from 'webpack';
1
+ import { Compiler, type Configuration, type WebpackOptionsNormalized } from 'webpack';
2
+ import { NormalizedNxAppWebpackPluginOptions } from '../nx-webpack-plugin/nx-app-webpack-plugin-options';
2
3
  export declare class NxTsconfigPathsWebpackPlugin {
3
4
  private options;
4
- constructor(options: {
5
- tsConfig: string;
6
- });
5
+ constructor(options: NormalizedNxAppWebpackPluginOptions);
7
6
  apply(compiler: Compiler): void;
7
+ handleBuildLibsFromSource(config: Partial<WebpackOptionsNormalized | Configuration>, options: any): void;
8
8
  }
@@ -4,6 +4,8 @@ exports.NxTsconfigPathsWebpackPlugin = void 0;
4
4
  const path = require("path");
5
5
  const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
6
6
  const devkit_1 = require("@nx/devkit");
7
+ const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
8
+ const webpack_nx_build_coordination_plugin_1 = require("../webpack-nx-build-coordination-plugin");
7
9
  class NxTsconfigPathsWebpackPlugin {
8
10
  constructor(options) {
9
11
  this.options = options;
@@ -11,6 +13,8 @@ class NxTsconfigPathsWebpackPlugin {
11
13
  throw new Error(`Missing "tsConfig" option. Set this option in your Nx webpack plugin.`);
12
14
  }
13
15
  apply(compiler) {
16
+ // If we are not building libs from source, we need to remap paths so tsconfig may be updated.
17
+ this.handleBuildLibsFromSource(compiler.options, this.options);
14
18
  const extensions = new Set([
15
19
  ...['.ts', '.tsx', '.mjs', '.js', '.jsx'],
16
20
  ...(compiler.options?.resolve?.extensions ?? []),
@@ -27,5 +31,20 @@ class NxTsconfigPathsWebpackPlugin {
27
31
  mainFields: ['module', 'main'],
28
32
  }));
29
33
  }
34
+ handleBuildLibsFromSource(config, options) {
35
+ if (!options.buildLibsFromSource && options.targetName) {
36
+ const remappedTarget = options.targetName === 'serve' ? 'build' : options.targetName;
37
+ const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(undefined, options.projectGraph, options.root, options.projectName, remappedTarget, options.configurationName);
38
+ options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, options.root, target.data.root, dependencies);
39
+ if (options.targetName === 'serve') {
40
+ const buildableDependencies = dependencies
41
+ .filter((dependency) => dependency.node.type === 'lib')
42
+ .map((dependency) => dependency.node.name)
43
+ .join(',');
44
+ const buildCommand = `nx run-many --target=build --projects=${buildableDependencies}`;
45
+ config.plugins.push(new webpack_nx_build_coordination_plugin_1.WebpackNxBuildCoordinationPlugin(buildCommand));
46
+ }
47
+ }
48
+ }
30
49
  }
31
50
  exports.NxTsconfigPathsWebpackPlugin = NxTsconfigPathsWebpackPlugin;
@@ -1,5 +1,5 @@
1
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, }?: {
2
+ import { NormalizedNxAppWebpackPluginOptions } from '../nx-app-webpack-plugin-options';
3
+ export declare function applyBaseConfig(options: NormalizedNxAppWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
4
4
  useNormalizedEntry?: boolean;
5
5
  }): void;
@@ -68,27 +68,22 @@ function applyNxIndependentConfig(options, config) {
68
68
  : false;
69
69
  config.output = {
70
70
  ...config.output,
71
- libraryTarget: (config.output?.libraryTarget ??
72
- options.target === 'node')
73
- ? 'commonjs'
74
- : undefined,
71
+ libraryTarget: config.output?.libraryTarget ??
72
+ (options.target === 'node' ? 'commonjs' : undefined),
75
73
  path: config.output?.path ??
76
74
  (options.outputPath
77
75
  ? path.join(options.root, options.outputPath)
78
76
  : 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',
77
+ filename: config.output?.filename ??
78
+ (options.outputHashing ? `[name]${hashFormat.script}.js` : '[name].js'),
79
+ chunkFilename: config.output?.chunkFilename ??
80
+ (options.outputHashing ? `[name]${hashFormat.chunk}.js` : '[name].js'),
85
81
  hashFunction: config.output?.hashFunction ?? 'xxhash64',
86
82
  // Disabled for performance
87
83
  pathinfo: config.output?.pathinfo ?? false,
88
84
  // Use CJS for Node since it has the widest support.
89
- scriptType: config.output?.scriptType ?? options.target === 'node'
90
- ? undefined
91
- : 'module',
85
+ scriptType: config.output?.scriptType ??
86
+ (options.target === 'node' ? undefined : 'module'),
92
87
  };
93
88
  config.watch = options.watch;
94
89
  config.watchOptions = {
@@ -157,12 +152,23 @@ function applyNxIndependentConfig(options, config) {
157
152
  moduleTrace: !!options.verbose,
158
153
  usedExports: !!options.verbose,
159
154
  };
155
+ /**
156
+ * Initialize properties that get set when webpack is used during task execution.
157
+ * These properties may be used by consumers who expect them to not be undefined.
158
+ *
159
+ * When @nx/webpack/plugin resolves the config, it is not during a task, and therefore
160
+ * these values are not set, which can lead to errors being thrown when reading
161
+ * the webpack options from the resolved file.
162
+ */
163
+ config.entry ??= {};
164
+ config.resolve ??= {};
165
+ config.module ??= {};
166
+ config.plugins ??= [];
167
+ config.externals ??= [];
160
168
  }
161
169
  function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
162
170
  const tsConfig = options.tsConfig ?? (0, js_1.getRootTsConfigPath)();
163
- const plugins = [
164
- new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ tsConfig }),
165
- ];
171
+ const plugins = [];
166
172
  const executorContext = {
167
173
  projectName: options.projectName,
168
174
  targetName: options.targetName,
@@ -170,6 +176,7 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
170
176
  configurationName: options.configurationName,
171
177
  root: options.root,
172
178
  };
179
+ plugins.push(new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ ...options, tsConfig }));
173
180
  if (!options?.skipTypeChecking) {
174
181
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
175
182
  plugins.push(new ForkTsCheckerWebpackPlugin({
@@ -1,5 +1,5 @@
1
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, }?: {
2
+ import { NormalizedNxAppWebpackPluginOptions } from '../nx-app-webpack-plugin-options';
3
+ export declare function applyWebConfig(options: NormalizedNxAppWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
4
4
  useNormalizedEntry?: boolean;
5
5
  }): void;
@@ -126,7 +126,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
126
126
  use: [
127
127
  ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
128
128
  {
129
- loader: path.join(__dirname, 'webpack/deprecated-stylus-loader.js'),
129
+ loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
130
130
  options: {
131
131
  stylusOptions: {
132
132
  include: includePaths,
@@ -185,7 +185,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
185
185
  use: [
186
186
  ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
187
187
  {
188
- loader: path.join(__dirname, 'webpack/deprecated-stylus-loader.js'),
188
+ loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
189
189
  options: {
190
190
  sourceMap: !!options.sourceMap,
191
191
  stylusOptions: {
@@ -245,7 +245,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
245
245
  use: [
246
246
  ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
247
247
  {
248
- loader: require.resolve('stylus-loader'),
248
+ loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
249
249
  options: {
250
250
  sourceMap: !!options.sourceMap,
251
251
  stylusOptions: {
@@ -335,7 +335,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
335
335
  type: 'asset',
336
336
  parser: {
337
337
  dataUrlCondition: {
338
- maxSize: 10000, // 10 kB
338
+ maxSize: 10_000, // 10 kB
339
339
  },
340
340
  },
341
341
  generator: {
@@ -348,7 +348,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
348
348
  type: 'asset',
349
349
  parser: {
350
350
  dataUrlCondition: {
351
- maxSize: 10000, // 10 kB
351
+ maxSize: 10_000, // 10 kB
352
352
  },
353
353
  },
354
354
  generator: {
@@ -1,5 +1,5 @@
1
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
2
- export declare function createLoaderFromCompiler(options: NormalizedNxWebpackPluginOptions): {
1
+ import { NormalizedNxAppWebpackPluginOptions } from '../nx-app-webpack-plugin-options';
2
+ export declare function createLoaderFromCompiler(options: NormalizedNxAppWebpackPluginOptions): {
3
3
  test: RegExp;
4
4
  loader: string;
5
5
  exclude: RegExp;
@@ -46,14 +46,18 @@ function createLoaderFromCompiler(options) {
46
46
  },
47
47
  };
48
48
  case 'babel':
49
- const tsConfig = (0, js_1.readTsConfig)(path.join(options.root, options.tsConfig));
49
+ const tsConfig = options.tsConfig
50
+ ? (0, js_1.readTsConfig)(path.join(options.root, options.tsConfig))
51
+ : undefined;
50
52
  const babelConfig = {
51
53
  test: /\.([jt])sx?$/,
52
54
  loader: path.join(__dirname, '../../../utils/web-babel-loader'),
53
55
  exclude: /node_modules/,
54
56
  options: {
55
57
  cwd: path.join(options.root, options.sourceRoot),
56
- emitDecoratorMetadata: tsConfig.options.emitDecoratorMetadata,
58
+ emitDecoratorMetadata: tsConfig
59
+ ? tsConfig.options.emitDecoratorMetadata
60
+ : false,
57
61
  isModern: true,
58
62
  isTest: process.env.NX_CYPRESS_COMPONENT_TEST === 'true',
59
63
  envName: process.env.BABEL_ENV ?? process.env.NODE_ENV,
@@ -1,3 +1,3 @@
1
1
  import { WebpackPluginInstance } from 'webpack';
2
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
3
- export declare function instantiateScriptPlugins(options: NormalizedNxWebpackPluginOptions): WebpackPluginInstance[];
2
+ import { NormalizedNxAppWebpackPluginOptions } from '../nx-app-webpack-plugin-options';
3
+ export declare function instantiateScriptPlugins(options: NormalizedNxAppWebpackPluginOptions): WebpackPluginInstance[];
@@ -1,4 +1,4 @@
1
- import { AssetGlobPattern, FileReplacement, NormalizedNxWebpackPluginOptions, NxWebpackPluginOptions } from '../nx-webpack-plugin-options';
2
- export declare function normalizeOptions(options: NxWebpackPluginOptions): NormalizedNxWebpackPluginOptions;
3
- export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string, projectRoot: string): AssetGlobPattern[];
1
+ import { AssetGlobPattern, FileReplacement, NormalizedNxAppWebpackPluginOptions, NxAppWebpackPluginOptions } from '../nx-app-webpack-plugin-options';
2
+ export declare function normalizeOptions(options: NxAppWebpackPluginOptions): NormalizedNxAppWebpackPluginOptions;
3
+ export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string, projectRoot: string, resolveRelativePathsToProjectRoot?: boolean): AssetGlobPattern[];
4
4
  export declare function normalizeFileReplacements(root: string, fileReplacements: FileReplacement[]): FileReplacement[];