@nx/react 19.0.0-beta.0 → 19.0.0-beta.10

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/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { NxReactWebpackPlugin as _NxReactWebpackPlugin } from './plugins/nx-react-webpack-plugin/nx-react-webpack-plugin';
2
+ /** @deprecated Use '@nx/react/webpack-plugin' instead. */
3
+ export declare const NxReactWebpackPlugin: typeof _NxReactWebpackPlugin;
1
4
  export { extraEslintDependencies, extendReactEslintJson, } from './src/utils/lint';
2
5
  export { cssInJsDependenciesBabel } from './src/utils/styled';
3
6
  export { assertValidStyle } from './src/utils/assertion';
@@ -19,4 +22,3 @@ export { componentTestGenerator } from './src/generators/component-test/componen
19
22
  export { setupTailwindGenerator } from './src/generators/setup-tailwind/setup-tailwind';
20
23
  export type { SupportedStyles } from './typings/style';
21
24
  export * from './plugins/with-react';
22
- export { NxReactWebpackPlugin } from './plugins/nx-react-webpack-plugin/nx-react-webpack-plugin';
package/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NxReactWebpackPlugin = exports.setupTailwindGenerator = exports.componentTestGenerator = exports.cypressComponentConfigGenerator = exports.remoteGenerator = exports.hostGenerator = exports.storybookConfigurationGenerator = exports.storiesGenerator = exports.reduxGenerator = exports.reactInitGenerator = exports.libraryGenerator = exports.componentStoryGenerator = exports.componentCypressGenerator = exports.hookGenerator = exports.componentGenerator = exports.applicationGenerator = exports.reactVersion = exports.reactDomVersion = exports.assertValidStyle = exports.cssInJsDependenciesBabel = exports.extendReactEslintJson = exports.extraEslintDependencies = void 0;
3
+ exports.setupTailwindGenerator = exports.componentTestGenerator = exports.cypressComponentConfigGenerator = exports.remoteGenerator = exports.hostGenerator = exports.storybookConfigurationGenerator = exports.storiesGenerator = exports.reduxGenerator = exports.reactInitGenerator = exports.libraryGenerator = exports.componentStoryGenerator = exports.componentCypressGenerator = exports.hookGenerator = exports.componentGenerator = exports.applicationGenerator = exports.reactVersion = exports.reactDomVersion = exports.assertValidStyle = exports.cssInJsDependenciesBabel = exports.extendReactEslintJson = exports.extraEslintDependencies = exports.NxReactWebpackPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const nx_react_webpack_plugin_1 = require("./plugins/nx-react-webpack-plugin/nx-react-webpack-plugin");
6
+ // TODO(v20): Remove this in favor of deep imports in order to load configs faster (150-200ms faster).
7
+ /** @deprecated Use '@nx/react/webpack-plugin' instead. */
8
+ exports.NxReactWebpackPlugin = nx_react_webpack_plugin_1.NxReactWebpackPlugin;
5
9
  var lint_1 = require("./src/utils/lint");
6
10
  Object.defineProperty(exports, "extraEslintDependencies", { enumerable: true, get: function () { return lint_1.extraEslintDependencies; } });
7
11
  Object.defineProperty(exports, "extendReactEslintJson", { enumerable: true, get: function () { return lint_1.extendReactEslintJson; } });
@@ -43,5 +47,3 @@ Object.defineProperty(exports, "componentTestGenerator", { enumerable: true, get
43
47
  var setup_tailwind_1 = require("./src/generators/setup-tailwind/setup-tailwind");
44
48
  Object.defineProperty(exports, "setupTailwindGenerator", { enumerable: true, get: function () { return setup_tailwind_1.setupTailwindGenerator; } });
45
49
  tslib_1.__exportStar(require("./plugins/with-react"), exports);
46
- var nx_react_webpack_plugin_1 = require("./plugins/nx-react-webpack-plugin/nx-react-webpack-plugin");
47
- Object.defineProperty(exports, "NxReactWebpackPlugin", { enumerable: true, get: function () { return nx_react_webpack_plugin_1.NxReactWebpackPlugin; } });
package/migrations.json CHANGED
@@ -1,23 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "update-rollup-executor": {
4
- "cli": "nx",
5
- "version": "15.3.0-beta.0",
6
- "description": "Update projects using @nrwl/web:rollup to @nrwl/rollup:rollup for build.",
7
- "factory": "./src/migrations/update-15-3-0/update-rollup-executor"
8
- },
9
- "install-webpack-rollup-dependencies": {
10
- "cli": "nx",
11
- "version": "15.3.0-beta.0",
12
- "description": "Install new dependencies for React projects using Webpack or Rollup.",
13
- "factory": "./src/migrations/update-15-3-0/install-webpack-rollup-dependencies"
14
- },
15
- "react-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
3
  "update-16-0-0-add-nx-packages": {
22
4
  "cli": "nx",
23
5
  "version": "16.0.0-beta.1",
@@ -62,148 +44,6 @@
62
44
  }
63
45
  },
64
46
  "packageJsonUpdates": {
65
- "15.2.2-beta.0": {
66
- "version": "15.2.2-beta.0",
67
- "packages": {
68
- "@types/react": {
69
- "version": "18.0.25",
70
- "alwaysAddToPackageJson": false
71
- },
72
- "@types/react-dom": {
73
- "version": "18.0.9",
74
- "alwaysAddToPackageJson": false
75
- },
76
- "@types/node": {
77
- "version": "18.11.9",
78
- "alwaysAddToPackageJson": false
79
- },
80
- "styled-components": {
81
- "version": "5.3.6",
82
- "alwaysAddToPackageJson": false
83
- },
84
- "@emotion/styled": {
85
- "version": "11.10.5",
86
- "alwaysAddToPackageJson": false
87
- },
88
- "@emotion/react": {
89
- "version": "11.10.5",
90
- "alwaysAddToPackageJson": false
91
- },
92
- "@emotion/babel-plugin": {
93
- "version": "11.10.5",
94
- "alwaysAddToPackageJson": false
95
- },
96
- "styled-jsx": {
97
- "version": "5.1.0",
98
- "alwaysAddToPackageJson": false
99
- },
100
- "react-router-dom": {
101
- "version": "6.4.3",
102
- "alwaysAddToPackageJson": false
103
- },
104
- "@reduxjs/toolkit": {
105
- "version": "1.9.0",
106
- "alwaysAddToPackageJson": false
107
- },
108
- "react-redux": {
109
- "version": "8.0.5",
110
- "alwaysAddToPackageJson": false
111
- },
112
- "eslint-plugin-react": {
113
- "version": "7.31.11",
114
- "alwaysAddToPackageJson": false
115
- },
116
- "postcss": {
117
- "version": "8.4.19",
118
- "alwaysAddToPackageJson": false
119
- },
120
- "tailwindcss": {
121
- "version": "3.2.4",
122
- "alwaysAddToPackageJson": false
123
- },
124
- "autoprefixer": {
125
- "version": "10.4.13",
126
- "alwaysAddToPackageJson": false
127
- },
128
- "@types/express": {
129
- "version": "4.17.14",
130
- "alwaysAddToPackageJson": false
131
- }
132
- }
133
- },
134
- "15.8.0": {
135
- "version": "15.8.0-beta.0",
136
- "packages": {
137
- "@types/react": {
138
- "version": "18.0.28",
139
- "alwaysAddToPackageJson": false
140
- },
141
- "@types/react-dom": {
142
- "version": "18.0.11",
143
- "alwaysAddToPackageJson": false
144
- },
145
- "@types/node": {
146
- "version": "18.14.2",
147
- "alwaysAddToPackageJson": false
148
- },
149
- "@emotion/styled": {
150
- "version": "11.10.6",
151
- "alwaysAddToPackageJson": false
152
- },
153
- "@emotion/react": {
154
- "version": "11.10.6",
155
- "alwaysAddToPackageJson": false
156
- },
157
- "@emotion/babel-plugin": {
158
- "version": "11.10.6",
159
- "alwaysAddToPackageJson": false
160
- },
161
- "styled-jsx": {
162
- "version": "5.1.2",
163
- "alwaysAddToPackageJson": false
164
- },
165
- "react-router-dom": {
166
- "version": "6.8.1",
167
- "alwaysAddToPackageJson": false
168
- },
169
- "@testing-library/react": {
170
- "version": "14.0.0",
171
- "alwaysAddToPackageJson": false
172
- },
173
- "@reduxjs/toolkit": {
174
- "version": "1.9.3",
175
- "alwaysAddToPackageJson": false
176
- },
177
- "eslint-plugin-import": {
178
- "version": "2.27.5",
179
- "alwaysAddToPackageJson": false
180
- },
181
- "eslint-plugin-jsx-a11y": {
182
- "version": "6.7.1",
183
- "alwaysAddToPackageJson": false
184
- },
185
- "eslint-plugin-react": {
186
- "version": "7.32.2",
187
- "alwaysAddToPackageJson": false
188
- },
189
- "postcss": {
190
- "version": "8.4.21",
191
- "alwaysAddToPackageJson": false
192
- },
193
- "tailwindcss": {
194
- "version": "3.2.7",
195
- "alwaysAddToPackageJson": false
196
- },
197
- "@types/express": {
198
- "version": "4.17.17",
199
- "alwaysAddToPackageJson": false
200
- },
201
- "less": {
202
- "version": "4.1.3",
203
- "alwaysAddToPackageJson": false
204
- }
205
- }
206
- },
207
47
  "16.3.0": {
208
48
  "version": "16.3.0-beta.2",
209
49
  "packages": {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "19.0.0-beta.0",
3
+ "version": "19.0.0-beta.10",
4
4
  "private": false,
5
- "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
5
+ "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/nrwl/nx.git",
@@ -37,11 +37,11 @@
37
37
  "file-loader": "^6.2.0",
38
38
  "minimatch": "9.0.3",
39
39
  "tslib": "^2.3.0",
40
- "@nx/devkit": "19.0.0-beta.0",
41
- "@nx/js": "19.0.0-beta.0",
42
- "@nx/eslint": "19.0.0-beta.0",
43
- "@nx/web": "19.0.0-beta.0",
44
- "@nrwl/react": "19.0.0-beta.0"
40
+ "@nx/devkit": "19.0.0-beta.10",
41
+ "@nx/js": "19.0.0-beta.10",
42
+ "@nx/eslint": "19.0.0-beta.10",
43
+ "@nx/web": "19.0.0-beta.10",
44
+ "@nrwl/react": "19.0.0-beta.10"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -36,7 +36,7 @@ function getRollupOptions(options) {
36
36
  url({
37
37
  limit: 10000, // 10kB
38
38
  }),
39
- ...options.plugins,
39
+ ...(Array.isArray(options.plugins) ? options.plugins : []),
40
40
  ];
41
41
  }
42
42
  catch {
@@ -168,7 +168,10 @@ function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
168
168
  }
169
169
  return async () => {
170
170
  customWebpack = await customWebpack;
171
- // TODO(v19): Once webpackConfig is always set in @nx/webpack:webpack and isolatedConfig is removed, we no longer need this default.
171
+ // TODO(v20): Component testing need to be agnostic of the underlying executor. With Crystal, we're not using `@nx/webpack:webpack` by default.
172
+ // We need to decouple CT from the build target of the app, we just care about bundler config (e.g. webpack.config.js).
173
+ // The generated setup should support both Webpack and Vite as documented here: https://docs.cypress.io/guides/component-testing/react/overview
174
+ // Related issue: https://github.com/nrwl/nx/issues/21546
172
175
  const configure = composePluginsSync(withNx(), withWeb());
173
176
  const defaultWebpack = configure({}, {
174
177
  options: {
@@ -8,19 +8,15 @@ const webpack_1 = require("webpack");
8
8
  const merge_plugins_1 = require("./merge-plugins");
9
9
  const with_react_1 = require("../with-react");
10
10
  const fs_1 = require("fs");
11
- // Prevent sensitive keys from being bundled when source code uses entire `process.env` object rather than individual keys (e.g. `process.env.NX_FOO`).
12
- // TODO(v19): BREAKING: Only env vars prefixed with NX_PUBLIC should be bundled. This is a breaking change so we won't do it in v18.
13
- const excludedKeys = ['NX_CLOUD_ACCESS_TOKEN', 'NX_CLOUD_ENCRYPTION_KEY'];
14
11
  // This is shamelessly taken from CRA and modified for NX use
15
12
  // https://github.com/facebook/create-react-app/blob/4784997f0682e75eb32a897b4ffe34d735912e6c/packages/react-scripts/config/env.js#L71
16
13
  function getClientEnvironment(mode) {
17
14
  // Grab NODE_ENV and NX_* and STORYBOOK_* environment variables and prepare them to be
18
15
  // injected into the application via DefinePlugin in webpack configuration.
19
- const NX_PREFIX = /^NX_/i;
16
+ const NX_PREFIX = /^NX_PUBLIC_/i;
20
17
  const STORYBOOK_PREFIX = /^STORYBOOK_/i;
21
18
  const raw = Object.keys(process.env)
22
- .filter((key) => !excludedKeys.includes(key) &&
23
- (NX_PREFIX.test(key) || STORYBOOK_PREFIX.test(key)))
19
+ .filter((key) => NX_PREFIX.test(key) || STORYBOOK_PREFIX.test(key))
24
20
  .reduce((env, key) => {
25
21
  env[key] = process.env[key];
26
22
  return env;
@@ -1,6 +1,6 @@
1
1
  <% if (webpackPluginOptions) { %>
2
- const { NxWebpackPlugin } = require('@nx/webpack');
3
- const { NxReactWebpackPlugin } = require('@nx/react');
2
+ const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
3
+ const { NxReactWebpackPlugin } = require('@nx/react/webpack-plugin');
4
4
  const { join } = require('path');
5
5
 
6
6
  module.exports = {
@@ -11,7 +11,7 @@ module.exports = {
11
11
  port: 4200
12
12
  },
13
13
  plugins: [
14
- new NxWebpackPlugin({
14
+ new NxAppWebpackPlugin({
15
15
  tsConfig: '<%= webpackPluginOptions.tsConfig %>',
16
16
  compiler: '<%= webpackPluginOptions.compiler %>',
17
17
  main: '<%= webpackPluginOptions.main %>',
@@ -93,7 +93,7 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
93
93
  normalized.compiler = normalized.compiler ?? 'babel';
94
94
  normalized.bundler = normalized.bundler ?? 'webpack';
95
95
  normalized.unitTestRunner = normalized.unitTestRunner ?? 'jest';
96
- normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'cypress';
96
+ normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'playwright';
97
97
  normalized.inSourceTests = normalized.minimal || normalized.inSourceTests;
98
98
  normalized.devServerPort ??= (0, find_free_port_1.findFreePort)(host);
99
99
  normalized.minimal = normalized.minimal ?? false;
@@ -122,10 +122,10 @@
122
122
  },
123
123
  "e2eTestRunner": {
124
124
  "type": "string",
125
- "enum": ["cypress", "playwright", "none"],
125
+ "enum": ["playwright", "cypress", "none"],
126
126
  "description": "Test runner to use for end to end (E2E) tests.",
127
127
  "x-prompt": "Which E2E test runner would you like to use?",
128
- "default": "cypress"
128
+ "default": "playwright"
129
129
  },
130
130
  "tags": {
131
131
  "type": "string",
@@ -103,10 +103,10 @@
103
103
  },
104
104
  "e2eTestRunner": {
105
105
  "type": "string",
106
- "enum": ["cypress", "playwright", "none"],
106
+ "enum": ["playwright", "cypress", "none"],
107
107
  "description": "Test runner to use for end to end (E2E) tests.",
108
108
  "x-prompt": "Which E2E test runner would you like to use?",
109
- "default": "cypress"
109
+ "default": "playwright"
110
110
  },
111
111
  "tags": {
112
112
  "type": "string",
@@ -109,10 +109,10 @@
109
109
  },
110
110
  "e2eTestRunner": {
111
111
  "type": "string",
112
- "enum": ["cypress", "playwright", "none"],
112
+ "enum": ["playwright", "cypress", "none"],
113
113
  "description": "Test runner to use for end to end (E2E) tests.",
114
114
  "x-prompt": "Which E2E test runner would you like to use?",
115
- "default": "cypress"
115
+ "default": "playwright"
116
116
  },
117
117
  "tags": {
118
118
  "type": "string",
@@ -39,8 +39,8 @@ export declare const typesCorsVersion = "~2.8.12";
39
39
  export declare const moduleFederationNodeVersion = "~0.9.9";
40
40
  export declare const lessVersion = "3.12.2";
41
41
  export declare const sassVersion = "^1.55.0";
42
- export declare const rollupPluginUrlVersion = "^7.0.0";
43
- export declare const svgrRollupVersion = "^8.0.1";
42
+ export declare const rollupPluginUrlVersion = "^8.0.2";
43
+ export declare const svgrRollupVersion = "^8.1.0";
44
44
  export declare const swcPluginStyledJsxVersion = "^1.5.67";
45
45
  export declare const swcPluginEmotionVersion = "^2.5.67";
46
46
  export declare const swcPluginStyledComponentsVersion = "^1.5.67";
@@ -47,8 +47,8 @@ exports.moduleFederationNodeVersion = '~0.9.9';
47
47
  exports.lessVersion = '3.12.2';
48
48
  exports.sassVersion = '^1.55.0';
49
49
  // rollup plugins (if needed)
50
- exports.rollupPluginUrlVersion = '^7.0.0';
51
- exports.svgrRollupVersion = '^8.0.1';
50
+ exports.rollupPluginUrlVersion = '^8.0.2';
51
+ exports.svgrRollupVersion = '^8.1.0';
52
52
  exports.swcPluginStyledJsxVersion = '^1.5.67';
53
53
  exports.swcPluginEmotionVersion = '^2.5.67';
54
54
  exports.swcPluginStyledComponentsVersion = '^1.5.67';
@@ -0,0 +1 @@
1
+ export { NxReactWebpackPlugin } from './plugins/nx-react-webpack-plugin/nx-react-webpack-plugin';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxReactWebpackPlugin = void 0;
4
+ var nx_react_webpack_plugin_1 = require("./plugins/nx-react-webpack-plugin/nx-react-webpack-plugin");
5
+ Object.defineProperty(exports, "NxReactWebpackPlugin", { enumerable: true, get: function () { return nx_react_webpack_plugin_1.NxReactWebpackPlugin; } });
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function installWebpackRollupDependencies(tree: Tree): import("@nx/devkit").GeneratorCallback;
3
- export default installWebpackRollupDependencies;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installWebpackRollupDependencies = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const versions_1 = require("../../utils/versions");
6
- function installWebpackRollupDependencies(tree) {
7
- const projects = (0, devkit_1.getProjects)(tree);
8
- let shouldInstall = false;
9
- for (const [, project] of projects) {
10
- if (project.targets?.build?.executor === '@nrwl/webpack:webpack' ||
11
- project.targets?.build?.executor === '@nrwl/rollup:rollup' ||
12
- project.targets?.build?.executor === '@nrwl/web:rollup') {
13
- shouldInstall = true;
14
- break;
15
- }
16
- }
17
- if (shouldInstall) {
18
- // These were previously dependencies of `@nrwl/react` but we've removed them
19
- // to accommodate different bundlers and test runners.
20
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
21
- '@babel/preset-react': '^7.14.5',
22
- '@pmmmwh/react-refresh-webpack-plugin': '^0.5.7',
23
- '@svgr/webpack': '^6.1.2',
24
- 'css-loader': '^6.4.0',
25
- 'react-refresh': '^0.10.0',
26
- 'style-loader': '^3.3.0',
27
- stylus: '^0.55.0',
28
- 'stylus-loader': '^7.1.0',
29
- 'url-loader': '^4.1.1',
30
- webpack: '^5.75.0',
31
- 'webpack-merge': '^5.8.0',
32
- '@nrwl/webpack': versions_1.nxVersion,
33
- });
34
- }
35
- }
36
- exports.installWebpackRollupDependencies = installWebpackRollupDependencies;
37
- exports.default = installWebpackRollupDependencies;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function updateRollupExecutor(tree: Tree): void;
3
- export default updateRollupExecutor;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateRollupExecutor = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function updateRollupExecutor(tree) {
6
- const projects = (0, devkit_1.getProjects)(tree);
7
- for (const [name, project] of projects) {
8
- if (project.targets?.build?.executor === '@nrwl/web:rollup') {
9
- project.targets.build.executor = '@nrwl/rollup:rollup';
10
- (0, devkit_1.updateProjectConfiguration)(tree, name, project);
11
- }
12
- }
13
- }
14
- exports.updateRollupExecutor = updateRollupExecutor;
15
- exports.default = updateRollupExecutor;
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
- const path_1 = require("path");
6
- async function default_1(tree) {
7
- // Since projects can have multiple configurations, we need to know if the default options
8
- // need to be migrated or not. If so then the subsequent configurations with `webpackConfig` also need to be.
9
- const defaultOptionsUpdated = new Set();
10
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', (options, projectName, targetName, configurationName) => {
11
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
12
- const defaultOptions = projectConfiguration.targets[targetName].options;
13
- const defaultWasUpdated = defaultOptionsUpdated.has(projectName);
14
- // If default was not updated (for different configurations), we don't do anything
15
- // If isolatedConfig is set, we don't need to do anything
16
- // If it is NOT React, we don't need to do anything
17
- if (!defaultWasUpdated &&
18
- (defaultOptions?.['isolatedConfig'] ||
19
- !(defaultOptions?.['main']?.match(/main\.(t|j)sx$/) ||
20
- defaultOptions?.['webpackConfig'] === '@nrwl/react/plugins/webpack'))) {
21
- return;
22
- }
23
- defaultOptionsUpdated.add(projectName);
24
- // If this is not the default options (e.g. for development, production, or something custom),
25
- // then skip it unless it specifically configures a webpackConfig file
26
- if (configurationName && !options?.webpackConfig) {
27
- return;
28
- }
29
- // If webpackConfig is set, update it with the new options
30
- // If webpackConfig is not set, we need to create a new
31
- // webpack.config.js file and set the path to it in the
32
- // executor options
33
- if (options?.['webpackConfig'] &&
34
- options['webpackConfig'] !== '@nrwl/react/plugins/webpack') {
35
- let oldName = options['webpackConfig'];
36
- if (options['webpackConfig'].endsWith('.js')) {
37
- oldName = options['webpackConfig'].replace('.js', '.old.js');
38
- }
39
- if (options['webpackConfig'].endsWith('.ts')) {
40
- oldName = options['webpackConfig'].replace('.ts', '.old.ts');
41
- }
42
- renameFile(tree, options['webpackConfig'], oldName);
43
- const justTheFileName = (0, path_1.basename)(oldName);
44
- tree.write(options['webpackConfig'], `
45
- const { composePlugins, withNx } = require('@nrwl/webpack');
46
- const { withReact } = require('@nrwl/react');
47
-
48
- // Nx plugins for webpack.
49
- module.exports = composePlugins(withNx(), withReact(), (config, { options, context }) => {
50
- // Note: This was added by an Nx migration.
51
- // You should consider inlining the logic into this file.
52
- // For more information on webpack config and Nx see:
53
- // https://nx.dev/recipes/webpack/webpack-config-setup
54
- return require('./${justTheFileName}')(config, context);
55
- });
56
- `);
57
- options['isolatedConfig'] = true;
58
- projectConfiguration.targets[targetName][configurationName ?? 'options'] = options;
59
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
60
- devkit_1.logger.info(`
61
- ${options['webpackConfig']} has been renamed to ${oldName} and a new ${options['webpackConfig']}
62
- has been created for your project ${projectName}.
63
- You should consider inlining the logic from ${oldName} into ${options['webpackConfig']}.
64
- You can read our guide on how to do this here:
65
-
66
- https://nx.dev/recipes/webpack/webpack-config-setup
67
- `);
68
- }
69
- else {
70
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
71
- if (!options) {
72
- options = {};
73
- }
74
- options['webpackConfig'] = `${projectConfiguration.root}/webpack.config.js`;
75
- options['isolatedConfig'] = true;
76
- tree.write(options['webpackConfig'], `
77
- const { composePlugins, withNx } = require('@nrwl/webpack');
78
- const { withReact } = require('@nrwl/react');
79
-
80
- // Nx plugins for webpack.
81
- module.exports = composePlugins(withNx(), withReact(), (config, { options, context }) => {
82
- // Update the webpack config as needed here.
83
- // e.g. config.plugins.push(new MyPlugin())
84
- // For more information on webpack config and Nx see:
85
- // https://nx.dev/recipes/webpack/webpack-config-setup
86
- return config;
87
- });
88
- `);
89
- projectConfiguration.targets[targetName].options = options;
90
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
91
- }
92
- });
93
- await (0, devkit_1.formatFiles)(tree);
94
- }
95
- exports.default = default_1;
96
- function renameFile(tree, from, to) {
97
- const buffer = tree.read(from);
98
- if (!buffer) {
99
- return;
100
- }
101
- tree.write(to, buffer);
102
- tree.delete(from);
103
- }