@nx/webpack 16.8.0-beta.4 → 16.8.0-beta.5

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": "16.8.0-beta.4",
3
+ "version": "16.8.0-beta.5",
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": {
@@ -30,9 +30,9 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/core": "^7.22.9",
33
- "@nrwl/webpack": "16.8.0-beta.4",
34
- "@nx/devkit": "16.8.0-beta.4",
35
- "@nx/js": "16.8.0-beta.4",
33
+ "@nrwl/webpack": "16.8.0-beta.5",
34
+ "@nx/devkit": "16.8.0-beta.5",
35
+ "@nx/js": "16.8.0-beta.5",
36
36
  "autoprefixer": "^10.4.9",
37
37
  "babel-loader": "^9.1.2",
38
38
  "browserslist": "^4.21.4",
@@ -70,5 +70,5 @@
70
70
  "access": "public"
71
71
  },
72
72
  "type": "commonjs",
73
- "gitHead": "c9aad2dc8c2b34531cf61549bff872e68c481e4e"
73
+ "gitHead": "ad2d1e8a55b2d1b358bb5e7483343d9757ff2c53"
74
74
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.devServerExecutor = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const webpack = require("webpack");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
@@ -12,43 +11,39 @@ const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
12
11
  const run_webpack_1 = require("../../utils/run-webpack");
13
12
  const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
14
13
  const normalize_options_1 = require("../webpack/lib/normalize-options");
15
- function devServerExecutor(serveOptions, context) {
16
- var _a;
17
- var _b;
18
- return tslib_1.__asyncGenerator(this, arguments, function* devServerExecutor_1() {
19
- // Default to dev mode so builds are faster and HMR mode works better.
20
- (_a = (_b = process.env).NODE_ENV) !== null && _a !== void 0 ? _a : (_b.NODE_ENV = 'development');
21
- const { root: projectRoot, sourceRoot } = context.projectsConfigurations.projects[context.projectName];
22
- const buildOptions = (0, normalize_options_1.normalizeOptions)(getBuildOptions(serveOptions, context), context.root, projectRoot, sourceRoot);
23
- if (!buildOptions.index) {
24
- throw new Error(`Cannot run dev-server without "index" option. Check the build options for ${context.projectName}.`);
25
- }
26
- if (!buildOptions.buildLibsFromSource) {
27
- const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // should be generalized
28
- context.configurationName);
29
- buildOptions.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(buildOptions.tsConfig, context.root, target.data.root, dependencies);
30
- }
31
- let config = (0, get_dev_server_config_1.getDevServerConfig)(context, buildOptions, serveOptions);
32
- if (buildOptions.webpackConfig) {
33
- let customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(buildOptions.webpackConfig, buildOptions.tsConfig);
34
- if (typeof customWebpack.then === 'function') {
35
- customWebpack = yield tslib_1.__await(customWebpack);
36
- }
37
- config = yield tslib_1.__await(customWebpack(config, {
38
- options: buildOptions,
39
- context,
40
- configuration: serveOptions.buildTarget.split(':')[2],
41
- }));
14
+ async function* devServerExecutor(serveOptions, context) {
15
+ // Default to dev mode so builds are faster and HMR mode works better.
16
+ process.env.NODE_ENV ??= 'development';
17
+ const { root: projectRoot, sourceRoot } = context.projectsConfigurations.projects[context.projectName];
18
+ const buildOptions = (0, normalize_options_1.normalizeOptions)(getBuildOptions(serveOptions, context), context.root, projectRoot, sourceRoot);
19
+ if (!buildOptions.index) {
20
+ throw new Error(`Cannot run dev-server without "index" option. Check the build options for ${context.projectName}.`);
21
+ }
22
+ if (!buildOptions.buildLibsFromSource) {
23
+ const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // should be generalized
24
+ context.configurationName);
25
+ buildOptions.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(buildOptions.tsConfig, context.root, target.data.root, dependencies);
26
+ }
27
+ let config = (0, get_dev_server_config_1.getDevServerConfig)(context, buildOptions, serveOptions);
28
+ if (buildOptions.webpackConfig) {
29
+ let customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(buildOptions.webpackConfig, buildOptions.tsConfig);
30
+ if (typeof customWebpack.then === 'function') {
31
+ customWebpack = await customWebpack;
42
32
  }
43
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
44
- console.info(stats.toString(config.stats));
45
- }), (0, operators_1.map)(({ baseUrl, stats }) => {
46
- return {
47
- baseUrl,
48
- success: !stats.hasErrors(),
49
- };
50
- })))))));
51
- });
33
+ config = await customWebpack(config, {
34
+ options: buildOptions,
35
+ context,
36
+ configuration: serveOptions.buildTarget.split(':')[2],
37
+ });
38
+ }
39
+ return yield* (0, rxjs_for_await_1.eachValueFrom)((0, run_webpack_1.runWebpackDevServer)(config, webpack, WebpackDevServer).pipe((0, operators_1.tap)(({ stats }) => {
40
+ console.info(stats.toString(config.stats));
41
+ }), (0, operators_1.map)(({ baseUrl, stats }) => {
42
+ return {
43
+ baseUrl,
44
+ success: !stats.hasErrors(),
45
+ };
46
+ })));
52
47
  }
53
48
  exports.devServerExecutor = devServerExecutor;
54
49
  function getBuildOptions(options, context) {
@@ -63,6 +58,9 @@ function getBuildOptions(options, context) {
63
58
  overrides.baseHref = options.baseHref;
64
59
  }
65
60
  const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
66
- return Object.assign(Object.assign({}, buildOptions), overrides);
61
+ return {
62
+ ...buildOptions,
63
+ ...overrides,
64
+ };
67
65
  }
68
66
  exports.default = devServerExecutor;
@@ -39,8 +39,7 @@ function getDevServerPartial(root, options, buildOptions) {
39
39
  htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
40
40
  },
41
41
  onListening(server) {
42
- var _a;
43
- const isHttps = server.options.https || ((_a = server.options.server) === null || _a === void 0 ? void 0 : _a.type) === 'https';
42
+ const isHttps = server.options.https || server.options.server?.type === 'https';
44
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)}`);
45
44
  },
46
45
  open: options.open,
@@ -1,53 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ssrDevServerExecutor = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const chalk = require("chalk");
7
6
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
8
7
  const wait_until_server_is_listening_1 = require("./lib/wait-until-server-is-listening");
9
- function ssrDevServerExecutor(options, context) {
10
- var _a, _b;
11
- return tslib_1.__asyncGenerator(this, arguments, function* ssrDevServerExecutor_1() {
12
- var _c, e_1, _d, _e;
13
- const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
14
- const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context.projectGraph);
15
- const browserOptions = (0, devkit_1.readTargetOptions)(browserTarget, context);
16
- const serverOptions = (0, devkit_1.readTargetOptions)(serverTarget, context);
17
- const runBrowser = yield tslib_1.__await((0, devkit_1.runExecutor)(browserTarget, Object.assign(Object.assign({}, browserOptions), options.browserTargetOptions), context));
18
- const runServer = yield tslib_1.__await((0, devkit_1.runExecutor)(serverTarget, Object.assign(Object.assign({}, serverOptions), options.serverTargetOptions), context));
19
- let browserBuilt = false;
20
- let nodeStarted = false;
21
- const combined = (0, async_iterable_1.combineAsyncIterables)(runBrowser, runServer);
22
- process.env['port'] = `${options.port}`;
23
- try {
24
- for (var _f = true, combined_1 = tslib_1.__asyncValues(combined), combined_1_1; combined_1_1 = yield tslib_1.__await(combined_1.next()), _c = combined_1_1.done, !_c; _f = true) {
25
- _e = combined_1_1.value;
26
- _f = false;
27
- const output = _e;
28
- if (!output.success)
29
- throw new Error('Could not build application');
30
- if (((_a = output.options) === null || _a === void 0 ? void 0 : _a.target) === 'node') {
31
- nodeStarted = true;
32
- }
33
- else if (((_b = output.options) === null || _b === void 0 ? void 0 : _b.target) === 'web') {
34
- browserBuilt = true;
35
- }
36
- if (nodeStarted && browserBuilt) {
37
- yield tslib_1.__await((0, wait_until_server_is_listening_1.waitUntilServerIsListening)(options.port));
38
- console.log(`[ ${chalk.green('ready')} ] on http://localhost:${options.port}`);
39
- yield yield tslib_1.__await(Object.assign(Object.assign({}, output), { baseUrl: `http://localhost:${options.port}` }));
40
- }
41
- }
8
+ async function* ssrDevServerExecutor(options, context) {
9
+ const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
10
+ const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context.projectGraph);
11
+ const browserOptions = (0, devkit_1.readTargetOptions)(browserTarget, context);
12
+ const serverOptions = (0, devkit_1.readTargetOptions)(serverTarget, context);
13
+ const runBrowser = await (0, devkit_1.runExecutor)(browserTarget, { ...browserOptions, ...options.browserTargetOptions }, context);
14
+ const runServer = await (0, devkit_1.runExecutor)(serverTarget, { ...serverOptions, ...options.serverTargetOptions }, context);
15
+ let browserBuilt = false;
16
+ let nodeStarted = false;
17
+ const combined = (0, async_iterable_1.combineAsyncIterables)(runBrowser, runServer);
18
+ process.env['port'] = `${options.port}`;
19
+ for await (const output of combined) {
20
+ if (!output.success)
21
+ throw new Error('Could not build application');
22
+ if (output.options?.target === 'node') {
23
+ nodeStarted = true;
42
24
  }
43
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
44
- finally {
45
- try {
46
- if (!_f && !_c && (_d = combined_1.return)) yield tslib_1.__await(_d.call(combined_1));
47
- }
48
- finally { if (e_1) throw e_1.error; }
25
+ else if (output.options?.target === 'web') {
26
+ browserBuilt = true;
49
27
  }
50
- });
28
+ if (nodeStarted && browserBuilt) {
29
+ await (0, wait_until_server_is_listening_1.waitUntilServerIsListening)(options.port);
30
+ console.log(`[ ${chalk.green('ready')} ] on http://localhost:${options.port}`);
31
+ yield {
32
+ ...output,
33
+ baseUrl: `http://localhost:${options.port}`,
34
+ };
35
+ }
36
+ }
51
37
  }
52
38
  exports.ssrDevServerExecutor = ssrDevServerExecutor;
53
39
  exports.default = ssrDevServerExecutor;
@@ -5,15 +5,27 @@ const path_1 = require("path");
5
5
  const fs_1 = require("fs");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  function normalizeOptions(options, root, projectRoot, sourceRoot) {
8
- var _a, _b;
9
- return Object.assign(Object.assign({}, options), { root,
8
+ return {
9
+ ...options,
10
+ root,
10
11
  projectRoot,
11
- sourceRoot, target: (_a = options.target) !== null && _a !== void 0 ? _a : 'web', main: (0, path_1.resolve)(root, options.main), outputPath: (0, path_1.resolve)(root, options.outputPath), outputFileName: (_b = options.outputFileName) !== null && _b !== void 0 ? _b : 'main.js', tsConfig: (0, path_1.resolve)(root, options.tsConfig), fileReplacements: normalizeFileReplacements(root, options.fileReplacements), assets: normalizeAssets(options.assets, root, sourceRoot), webpackConfig: normalizePluginPath(options.webpackConfig, root), optimization: typeof options.optimization !== 'object'
12
+ sourceRoot,
13
+ target: options.target ?? 'web',
14
+ main: (0, path_1.resolve)(root, options.main),
15
+ outputPath: (0, path_1.resolve)(root, options.outputPath),
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),
20
+ webpackConfig: normalizePluginPath(options.webpackConfig, root),
21
+ optimization: typeof options.optimization !== 'object'
12
22
  ? {
13
23
  scripts: options.optimization,
14
24
  styles: options.optimization,
15
25
  }
16
- : options.optimization, polyfills: options.polyfills ? (0, path_1.resolve)(root, options.polyfills) : undefined });
26
+ : options.optimization,
27
+ polyfills: options.polyfills ? (0, path_1.resolve)(root, options.polyfills) : undefined,
28
+ };
17
29
  }
18
30
  exports.normalizeOptions = normalizeOptions;
19
31
  function normalizeFileReplacements(root, fileReplacements) {
@@ -29,7 +41,7 @@ function normalizePluginPath(pluginPath, root) {
29
41
  try {
30
42
  return require.resolve(pluginPath);
31
43
  }
32
- catch (_a) {
44
+ catch {
33
45
  return (0, path_1.resolve)(root, pluginPath);
34
46
  }
35
47
  }
@@ -61,9 +73,12 @@ function normalizeAssets(assets, root, sourceRoot) {
61
73
  }
62
74
  const assetPath = (0, devkit_1.normalizePath)(asset.input);
63
75
  const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
64
- return Object.assign(Object.assign({}, asset), { input: resolvedAssetPath,
76
+ return {
77
+ ...asset,
78
+ input: resolvedAssetPath,
65
79
  // Now we remove starting slash to make Webpack place it from the output root.
66
- output: asset.output.replace(/^\//, '') });
80
+ output: asset.output.replace(/^\//, ''),
81
+ };
67
82
  }
68
83
  });
69
84
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runWebpack = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const webpack = require("webpack");
6
5
  const rxjs_1 = require("rxjs");
7
6
  // TODO(jack): move to dev-server executor
@@ -9,7 +8,7 @@ function runWebpack(config) {
9
8
  return new rxjs_1.Observable((subscriber) => {
10
9
  // Passing `watch` option here will result in a warning due to missing callback.
11
10
  // We manually call `.watch` or `.run` later so this option isn't needed here.
12
- const { watch } = config, normalizedConfig = tslib_1.__rest(config, ["watch"]);
11
+ const { watch, ...normalizedConfig } = config;
13
12
  const webpackCompiler = webpack(normalizedConfig);
14
13
  const callback = (err, stats) => {
15
14
  if (err) {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webpackExecutor = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
7
6
  const rxjs_1 = require("rxjs");
@@ -13,97 +12,92 @@ const run_webpack_1 = require("./lib/run-webpack");
13
12
  const fs_1 = require("../../utils/fs");
14
13
  const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
15
14
  const normalize_options_1 = require("./lib/normalize-options");
16
- function getWebpackConfigs(options, context) {
17
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
- if (options.isolatedConfig && !options.webpackConfig) {
19
- throw new Error(`Using "isolatedConfig" without a "webpackConfig" is not supported.`);
15
+ async function getWebpackConfigs(options, context) {
16
+ if (options.isolatedConfig && !options.webpackConfig) {
17
+ throw new Error(`Using "isolatedConfig" without a "webpackConfig" is not supported.`);
18
+ }
19
+ let customWebpack = null;
20
+ if (options.webpackConfig) {
21
+ customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(options.webpackConfig, options.tsConfig);
22
+ if (typeof customWebpack.then === 'function') {
23
+ customWebpack = await customWebpack;
20
24
  }
21
- let customWebpack = null;
22
- if (options.webpackConfig) {
23
- customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(options.webpackConfig, options.tsConfig);
24
- if (typeof customWebpack.then === 'function') {
25
- customWebpack = yield customWebpack;
26
- }
27
- }
28
- const config = options.isolatedConfig
29
- ? {}
30
- : (0, get_webpack_config_1.getWebpackConfig)(context, options);
31
- if (customWebpack) {
32
- return yield customWebpack(config, {
33
- options,
34
- context,
35
- configuration: context.configurationName, // backwards compat
36
- });
37
- }
38
- else {
39
- // If the user has no webpackConfig specified then we always have to apply
40
- return config;
41
- }
42
- });
25
+ }
26
+ const config = options.isolatedConfig
27
+ ? {}
28
+ : (0, get_webpack_config_1.getWebpackConfig)(context, options);
29
+ if (customWebpack) {
30
+ return await customWebpack(config, {
31
+ options,
32
+ context,
33
+ configuration: context.configurationName, // backwards compat
34
+ });
35
+ }
36
+ else {
37
+ // If the user has no webpackConfig specified then we always have to apply
38
+ return config;
39
+ }
43
40
  }
44
- function webpackExecutor(_options, context) {
45
- var _a;
46
- return tslib_1.__asyncGenerator(this, arguments, function* webpackExecutor_1() {
47
- const metadata = context.projectsConfigurations.projects[context.projectName];
48
- const sourceRoot = metadata.sourceRoot;
49
- const options = (0, normalize_options_1.normalizeOptions)(_options, context.root, metadata.root, sourceRoot);
50
- const isScriptOptimizeOn = typeof options.optimization === 'boolean'
51
- ? options.optimization
52
- : options.optimization && options.optimization.scripts
53
- ? options.optimization.scripts
54
- : false;
55
- (_a = process.env).NODE_ENV || (_a.NODE_ENV = isScriptOptimizeOn
56
- ? 'production'
57
- : 'development');
58
- if (options.compiler === 'swc') {
59
- try {
60
- require.resolve('swc-loader');
61
- require.resolve('@swc/core');
62
- }
63
- catch (_b) {
64
- devkit_1.logger.error(`Missing SWC dependencies: @swc/core, swc-loader. Make sure you install them first.`);
65
- return yield tslib_1.__await({
66
- success: false,
67
- outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
68
- options,
69
- });
70
- }
71
- }
72
- if (!options.buildLibsFromSource && context.targetName) {
73
- const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
74
- options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, context.root, metadata.root, dependencies);
75
- }
76
- // Delete output path before bundling
77
- if (options.deleteOutputPath) {
78
- (0, fs_1.deleteOutputDir)(context.root, options.outputPath);
41
+ async function* webpackExecutor(_options, context) {
42
+ const metadata = context.projectsConfigurations.projects[context.projectName];
43
+ const sourceRoot = metadata.sourceRoot;
44
+ const options = (0, normalize_options_1.normalizeOptions)(_options, context.root, metadata.root, sourceRoot);
45
+ const isScriptOptimizeOn = typeof options.optimization === 'boolean'
46
+ ? options.optimization
47
+ : options.optimization && options.optimization.scripts
48
+ ? options.optimization.scripts
49
+ : false;
50
+ process.env.NODE_ENV ||= isScriptOptimizeOn
51
+ ? 'production'
52
+ : 'development';
53
+ if (options.compiler === 'swc') {
54
+ try {
55
+ require.resolve('swc-loader');
56
+ require.resolve('@swc/core');
79
57
  }
80
- if (options.generatePackageJson && metadata.projectType !== 'application') {
81
- 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.
82
- For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`);
83
- }
84
- const configs = yield tslib_1.__await(getWebpackConfigs(options, context));
85
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((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))),
86
- // Run build sequentially and bail when first one fails.
87
- (0, operators_1.mergeScan)((acc, config) => {
88
- if (!acc.hasErrors()) {
89
- return (0, run_webpack_1.runWebpack)(config).pipe((0, operators_1.tap)((stats) => {
90
- console.info(stats.toString(config.stats));
91
- }));
92
- }
93
- else {
94
- return (0, rxjs_1.of)();
95
- }
96
- }, { hasErrors: () => false }, 1),
97
- // Collect build results as an array.
98
- (0, operators_1.bufferCount)(Array.isArray(configs) ? configs.length : 1), (0, operators_1.switchMap)((results) => tslib_1.__awaiter(this, void 0, void 0, function* () {
99
- const success = results.every((result) => Boolean(result) && !result.hasErrors());
58
+ catch {
59
+ devkit_1.logger.error(`Missing SWC dependencies: @swc/core, swc-loader. Make sure you install them first.`);
100
60
  return {
101
- success,
61
+ success: false,
102
62
  outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
103
63
  options,
104
64
  };
105
- }))))))));
106
- });
65
+ }
66
+ }
67
+ if (!options.buildLibsFromSource && context.targetName) {
68
+ const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
69
+ options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, context.root, metadata.root, dependencies);
70
+ }
71
+ // Delete output path before bundling
72
+ if (options.deleteOutputPath) {
73
+ (0, fs_1.deleteOutputDir)(context.root, options.outputPath);
74
+ }
75
+ if (options.generatePackageJson && metadata.projectType !== 'application') {
76
+ 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.
77
+ For libraries, configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).`);
78
+ }
79
+ const configs = await getWebpackConfigs(options, context);
80
+ 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))),
81
+ // Run build sequentially and bail when first one fails.
82
+ (0, operators_1.mergeScan)((acc, config) => {
83
+ if (!acc.hasErrors()) {
84
+ return (0, run_webpack_1.runWebpack)(config).pipe((0, operators_1.tap)((stats) => {
85
+ console.info(stats.toString(config.stats));
86
+ }));
87
+ }
88
+ else {
89
+ return (0, rxjs_1.of)();
90
+ }
91
+ }, { hasErrors: () => false }, 1),
92
+ // Collect build results as an array.
93
+ (0, operators_1.bufferCount)(Array.isArray(configs) ? configs.length : 1), (0, operators_1.switchMap)(async (results) => {
94
+ const success = results.every((result) => Boolean(result) && !result.hasErrors());
95
+ return {
96
+ success,
97
+ outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
98
+ options,
99
+ };
100
+ })));
107
101
  }
108
102
  exports.webpackExecutor = webpackExecutor;
109
103
  exports.default = webpackExecutor;
@@ -1,45 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compat = exports.configurationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const init_1 = require("../init/init");
7
- function configurationGenerator(tree, options) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const task = yield (0, init_1.webpackInitGenerator)(tree, Object.assign(Object.assign({}, options), { skipFormat: true }));
10
- checkForTargetConflicts(tree, options);
11
- addBuildTarget(tree, options);
12
- if (options.devServer) {
13
- addServeTarget(tree, options);
14
- }
15
- if (!options.skipFormat) {
16
- yield (0, devkit_1.formatFiles)(tree);
17
- }
18
- return task;
6
+ async function configurationGenerator(tree, options) {
7
+ const task = await (0, init_1.webpackInitGenerator)(tree, {
8
+ ...options,
9
+ skipFormat: true,
19
10
  });
11
+ checkForTargetConflicts(tree, options);
12
+ addBuildTarget(tree, options);
13
+ if (options.devServer) {
14
+ addServeTarget(tree, options);
15
+ }
16
+ if (!options.skipFormat) {
17
+ await (0, devkit_1.formatFiles)(tree);
18
+ }
19
+ return task;
20
20
  }
21
21
  exports.configurationGenerator = configurationGenerator;
22
22
  function checkForTargetConflicts(tree, options) {
23
- var _a, _b;
24
23
  if (options.skipValidation)
25
24
  return;
26
25
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
27
- if ((_a = project.targets) === null || _a === void 0 ? void 0 : _a.build) {
26
+ if (project.targets?.build) {
28
27
  throw new Error(`Project "${project.name}" already has a build target. Pass --skipValidation to ignore this error.`);
29
28
  }
30
- if (options.devServer && ((_b = project.targets) === null || _b === void 0 ? void 0 : _b.serve)) {
29
+ if (options.devServer && project.targets?.serve) {
31
30
  throw new Error(`Project "${project.name}" already has a serve target. Pass --skipValidation to ignore this error.`);
32
31
  }
33
32
  }
34
33
  function addBuildTarget(tree, options) {
35
- var _a, _b, _c;
36
34
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
37
35
  const buildOptions = {
38
36
  target: options.target,
39
37
  outputPath: (0, devkit_1.joinPathFragments)('dist', project.root),
40
- compiler: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'swc',
41
- main: (_b = options.main) !== null && _b !== void 0 ? _b : (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts'),
42
- tsConfig: (_c = options.tsConfig) !== null && _c !== void 0 ? _c : (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.app.json'),
38
+ compiler: options.compiler ?? 'swc',
39
+ main: options.main ?? (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts'),
40
+ tsConfig: options.tsConfig ?? (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.app.json'),
43
41
  webpackConfig: (0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'),
44
42
  };
45
43
  if (options.webpackConfig) {
@@ -78,7 +76,11 @@ module.exports = composePlugins(withNx(), (config) => {
78
76
  });
79
77
  `);
80
78
  }
81
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, Object.assign(Object.assign({}, project), { targets: Object.assign(Object.assign({}, project.targets), { build: {
79
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, {
80
+ ...project,
81
+ targets: {
82
+ ...project.targets,
83
+ build: {
82
84
  executor: '@nx/webpack:webpack',
83
85
  outputs: ['{options.outputPath}'],
84
86
  defaultConfiguration: 'production',
@@ -93,11 +95,17 @@ module.exports = composePlugins(withNx(), (config) => {
93
95
  vendorChunk: false,
94
96
  },
95
97
  },
96
- } }) }));
98
+ },
99
+ },
100
+ });
97
101
  }
98
102
  function addServeTarget(tree, options) {
99
103
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
100
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, Object.assign(Object.assign({}, project), { targets: Object.assign(Object.assign({}, project.targets), { serve: {
104
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, {
105
+ ...project,
106
+ targets: {
107
+ ...project.targets,
108
+ serve: {
101
109
  executor: '@nx/webpack:dev-server',
102
110
  options: {
103
111
  buildTarget: `${options.project}:build`,
@@ -107,7 +115,9 @@ function addServeTarget(tree, options) {
107
115
  buildTarget: `${options.project}:build:production`,
108
116
  },
109
117
  },
110
- } }) }));
118
+ },
119
+ },
120
+ });
111
121
  }
112
122
  exports.default = configurationGenerator;
113
123
  exports.compat = (0, devkit_1.convertNxGenerator)(configurationGenerator);