@nx/webpack 19.1.0 → 19.1.2

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.
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "19.1.0",
3
+ "version": "19.1.2",
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": {
@@ -64,9 +64,9 @@
64
64
  "webpack-dev-server": "^4.9.3",
65
65
  "webpack-node-externals": "^3.0.0",
66
66
  "webpack-subresource-integrity": "^5.1.0",
67
- "@nx/devkit": "19.1.0",
68
- "@nx/js": "19.1.0",
69
- "@nrwl/webpack": "19.1.0"
67
+ "@nx/devkit": "19.1.2",
68
+ "@nx/js": "19.1.2",
69
+ "@nrwl/webpack": "19.1.2"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public"
@@ -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))),
@@ -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;
@@ -168,9 +168,7 @@ function applyNxIndependentConfig(options, config) {
168
168
  }
169
169
  function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
170
170
  const tsConfig = options.tsConfig ?? (0, js_1.getRootTsConfigPath)();
171
- const plugins = [
172
- new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ tsConfig }),
173
- ];
171
+ const plugins = [];
174
172
  const executorContext = {
175
173
  projectName: options.projectName,
176
174
  targetName: options.targetName,
@@ -178,6 +176,7 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
178
176
  configurationName: options.configurationName,
179
177
  root: options.root,
180
178
  };
179
+ plugins.push(new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ ...options, tsConfig }));
181
180
  if (!options?.skipTypeChecking) {
182
181
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
183
182
  plugins.push(new ForkTsCheckerWebpackPlugin({
@@ -56,6 +56,7 @@ function normalizeOptions(options) {
56
56
  ? normalizeAssets(combinedPluginAndMaybeExecutorOptions.assets, devkit_1.workspaceRoot, sourceRoot, projectNode.data.root)
57
57
  : [],
58
58
  baseHref: combinedPluginAndMaybeExecutorOptions.baseHref ?? '/',
59
+ buildLibsFromSource: combinedPluginAndMaybeExecutorOptions.buildLibsFromSource ?? true,
59
60
  commonChunk: combinedPluginAndMaybeExecutorOptions.commonChunk ?? true,
60
61
  compiler: combinedPluginAndMaybeExecutorOptions.compiler ?? 'babel',
61
62
  configurationName,
@@ -58,6 +58,10 @@ export interface NxAppWebpackPluginOptions {
58
58
  * Set <base href> for the resulting index.html.
59
59
  */
60
60
  baseHref?: string;
61
+ /**
62
+ * Build the libraries from source. Default is `true`.
63
+ */
64
+ buildLibsFromSource?: boolean;
61
65
  commonChunk?: boolean;
62
66
  /**
63
67
  * The compiler to use. Default is `babel` and requires a `.babelrc` file.