@nx/webpack 17.2.0-beta.9 → 17.2.0-canary.20231207-b8d24e6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "17.2.0-beta.9",
3
+ "version": "17.2.0-canary.20231207-b8d24e6",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
6
6
  "repository": {
@@ -62,9 +62,9 @@
62
62
  "webpack-dev-server": "^4.9.3",
63
63
  "webpack-node-externals": "^3.0.0",
64
64
  "webpack-subresource-integrity": "^5.1.0",
65
- "@nx/devkit": "17.2.0-beta.9",
66
- "@nx/js": "17.2.0-beta.9",
67
- "@nrwl/webpack": "17.2.0-beta.9"
65
+ "@nx/devkit": "17.2.0-canary.20231207-b8d24e6",
66
+ "@nx/js": "17.2.0-canary.20231207-b8d24e6",
67
+ "@nrwl/webpack": "17.2.0-canary.20231207-b8d24e6"
68
68
  },
69
69
  "publishConfig": {
70
70
  "access": "public"
@@ -69,6 +69,10 @@ function applyNxIndependentConfig(options, config) {
69
69
  : false;
70
70
  config.output = {
71
71
  ...config.output,
72
+ libraryTarget: (config.output?.libraryTarget ??
73
+ options.target === 'node')
74
+ ? 'commonjs'
75
+ : undefined,
72
76
  path: config.output?.path ??
73
77
  (options.outputPath
74
78
  ? path.join(options.root, options.outputPath)
@@ -2,7 +2,7 @@ import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
2
  export interface WebpackPluginOptions {
3
3
  buildTargetName?: string;
4
4
  serveTargetName?: string;
5
- staticServeTargetName?: string;
5
+ serveStaticTargetName?: string;
6
6
  previewTargetName?: string;
7
7
  }
8
8
  export declare const createDependencies: CreateDependencies;
@@ -4,7 +4,6 @@ exports.createNodes = exports.createDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path_1 = require("path");
6
6
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
7
- const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
8
7
  const fs_1 = require("fs");
9
8
  const read_webpack_options_1 = require("../utils/webpack/read-webpack-options");
10
9
  const resolve_user_defined_webpack_config_1 = require("../utils/webpack/resolve-user-defined-webpack-config");
@@ -31,7 +30,7 @@ exports.createNodes = [
31
30
  options ??= {};
32
31
  options.buildTargetName ??= 'build';
33
32
  options.serveTargetName ??= 'serve';
34
- options.staticServeTargetName ??= 'static-serve';
33
+ options.serveStaticTargetName ??= 'serve-static';
35
34
  options.previewTargetName ??= 'preview';
36
35
  const projectRoot = (0, path_1.dirname)(configFilePath);
37
36
  // Do not create a project if package.json and project.json isn't there.
@@ -58,7 +57,7 @@ exports.createNodes = [
58
57
  ];
59
58
  async function createWebpackTargets(configFilePath, projectRoot, options, context) {
60
59
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
61
- const webpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)());
60
+ const webpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
62
61
  const webpackOptions = await (0, read_webpack_options_1.readWebpackOptions)(webpackConfig);
63
62
  const outputPath = normalizeOutputPath(webpackOptions.output?.path) ??
64
63
  '{workspaceRoot}/dist/{projectRoot}';
@@ -66,35 +65,26 @@ async function createWebpackTargets(configFilePath, projectRoot, options, contex
66
65
  const configBasename = (0, path_1.basename)(configFilePath);
67
66
  targets[options.buildTargetName] = {
68
67
  command: `webpack -c ${configBasename} --node-env=production`,
69
- options: {
70
- cwd: projectRoot,
71
- },
68
+ options: { cwd: projectRoot },
69
+ cache: true,
70
+ dependsOn: [`^${options.buildTargetName}`],
71
+ inputs: 'production' in namedInputs
72
+ ? [
73
+ 'default',
74
+ '^production',
75
+ {
76
+ externalDependencies: ['webpack-cli'],
77
+ },
78
+ ]
79
+ : [
80
+ 'default',
81
+ '^default',
82
+ {
83
+ externalDependencies: ['webpack-cli'],
84
+ },
85
+ ],
86
+ outputs: [outputPath],
72
87
  };
73
- const buildTargetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.buildTargetName, context.nxJsonConfiguration.targetDefaults);
74
- if (buildTargetDefaults?.cache === undefined) {
75
- targets[options.buildTargetName].cache = true;
76
- }
77
- if (buildTargetDefaults?.inputs === undefined) {
78
- targets[options.buildTargetName].inputs =
79
- 'production' in namedInputs
80
- ? [
81
- 'default',
82
- '^production',
83
- {
84
- externalDependencies: ['webpack-cli'],
85
- },
86
- ]
87
- : [
88
- 'default',
89
- '^default',
90
- {
91
- externalDependencies: ['webpack-cli'],
92
- },
93
- ];
94
- }
95
- if (buildTargetDefaults?.outputs === undefined) {
96
- targets[options.buildTargetName].outputs = [outputPath];
97
- }
98
88
  targets[options.serveTargetName] = {
99
89
  command: `webpack serve -c ${configBasename} --node-env=development`,
100
90
  options: {
@@ -107,10 +97,10 @@ async function createWebpackTargets(configFilePath, projectRoot, options, contex
107
97
  cwd: projectRoot,
108
98
  },
109
99
  };
110
- targets[options.staticServeTargetName] = {
100
+ targets[options.serveStaticTargetName] = {
111
101
  executor: '@nx/web:file-server',
112
102
  options: {
113
- buildTarget: `${projectRoot}:${options.buildTargetName}`,
103
+ buildTarget: options.buildTargetName,
114
104
  },
115
105
  };
116
106
  return targets;
@@ -1 +1,3 @@
1
- export declare function resolveUserDefinedWebpackConfig(path: string, tsConfig: string): any;
1
+ export declare function resolveUserDefinedWebpackConfig(path: string, tsConfig: string,
2
+ /** Skip require cache and return latest content */
3
+ reload?: boolean): any;
@@ -2,7 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveUserDefinedWebpackConfig = void 0;
4
4
  const internal_1 = require("@nx/js/src/internal");
5
- function resolveUserDefinedWebpackConfig(path, tsConfig) {
5
+ function resolveUserDefinedWebpackConfig(path, tsConfig,
6
+ /** Skip require cache and return latest content */
7
+ reload = false) {
8
+ if (reload) {
9
+ // Clear cache if the path is in the cache
10
+ if (require.cache[path]) {
11
+ // Clear all entries because config may import other modules
12
+ for (const k of Object.keys(require.cache)) {
13
+ delete require.cache[k];
14
+ }
15
+ }
16
+ }
6
17
  // Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
7
18
  // There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
8
19
  if (!/\.(ts|mts|cts)$/.test(path)) {