@nx/react 17.2.0-beta.6 → 17.2.0-beta.9

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/react",
3
- "version": "17.2.0-beta.6",
3
+ "version": "17.2.0-beta.9",
4
4
  "private": false,
5
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.",
6
6
  "repository": {
@@ -37,11 +37,11 @@
37
37
  "file-loader": "^6.2.0",
38
38
  "minimatch": "3.0.5",
39
39
  "tslib": "^2.3.0",
40
- "@nx/devkit": "17.2.0-beta.6",
41
- "@nx/js": "17.2.0-beta.6",
42
- "@nx/eslint": "17.2.0-beta.6",
43
- "@nx/web": "17.2.0-beta.6",
44
- "@nrwl/react": "17.2.0-beta.6"
40
+ "@nx/devkit": "17.2.0-beta.9",
41
+ "@nx/js": "17.2.0-beta.9",
42
+ "@nx/eslint": "17.2.0-beta.9",
43
+ "@nx/web": "17.2.0-beta.9",
44
+ "@nrwl/react": "17.2.0-beta.9"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -140,24 +140,20 @@ function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
140
140
  }
141
141
  const context = (0, ct_helpers_1.createExecutorContext)(graph, buildableProjectConfig.targets, parsed.project, parsed.target, parsed.target);
142
142
  const { normalizeOptions, } = require('@nx/webpack/src/executors/webpack/lib/normalize-options');
143
- const { resolveCustomWebpackConfig, } = require('@nx/webpack/src/utils/webpack/custom-webpack');
144
- const { getWebpackConfig, } = require('@nx/webpack/src/executors/webpack/lib/get-webpack-config');
143
+ const { resolveUserDefinedWebpackConfig, } = require('@nx/webpack/src/utils/webpack/resolve-user-defined-webpack-config');
144
+ const { withNx } = require('@nx/webpack/src/utils/with-nx');
145
145
  const options = normalizeOptions(withSchemaDefaults(parsed, context), devkit_1.workspaceRoot, buildableProjectConfig.root, buildableProjectConfig.sourceRoot);
146
146
  let customWebpack;
147
147
  if (options.webpackConfig) {
148
- customWebpack = resolveCustomWebpackConfig(options.webpackConfig, options.tsConfig.startsWith(context.root)
148
+ customWebpack = resolveUserDefinedWebpackConfig(options.webpackConfig, options.tsConfig.startsWith(context.root)
149
149
  ? options.tsConfig
150
150
  : (0, path_1.join)(context.root, options.tsConfig));
151
151
  }
152
152
  return async () => {
153
153
  customWebpack = await customWebpack;
154
154
  // TODO(jack): Once webpackConfig is always set in @nx/webpack:webpack, we no longer need this default.
155
- const defaultWebpack = getWebpackConfig(context, {
155
+ const defaultWebpack = withNx({
156
156
  ...options,
157
- // cypress will generate its own index.html from component-index.html
158
- generateIndexHtml: false,
159
- // causes issues with buildable libraries with ENOENT: no such file or directory, scandir error
160
- extractLicenses: false,
161
157
  root: devkit_1.workspaceRoot,
162
158
  projectRoot: ctProjectConfig.root,
163
159
  sourceRoot: ctProjectConfig.sourceRoot,
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyReactConfig = void 0;
4
4
  function applyReactConfig(options, config = {}) {
5
+ if (!process.env['NX_TASK_TARGET_PROJECT'])
6
+ return;
5
7
  addHotReload(config);
6
8
  if (options.svgr !== false) {
7
9
  removeSvgLoaderIfPresent(config);
@@ -140,7 +140,7 @@ const webpack = async (storybookWebpackConfig = {}, options) => {
140
140
  };
141
141
  // ESM build for modern browsers.
142
142
  let baseWebpackConfig = {};
143
- const configure = (0, config_1.composePluginsSync)(withNx({ skipTypeChecking: true }), withWeb(), (0, with_react_1.withReact)());
143
+ const configure = (0, config_1.composePluginsSync)(withNx({ target: 'web', skipTypeChecking: true }), (0, with_react_1.withReact)());
144
144
  const finalConfig = configure(baseWebpackConfig, {
145
145
  options: builderOptions,
146
146
  context: { root: devkit_1.workspaceRoot }, // The context is not used here.
@@ -1,6 +1,6 @@
1
1
  import type { Configuration } from 'webpack';
2
2
  import type { NxWebpackExecutionContext, WithWebOptions } from '@nx/webpack';
3
- interface WithReactOptions extends WithWebOptions {
3
+ export interface WithReactOptions extends WithWebOptions {
4
4
  svgr?: false;
5
5
  }
6
6
  /**
@@ -8,4 +8,3 @@ interface WithReactOptions extends WithWebOptions {
8
8
  * @returns {NxWebpackPlugin}
9
9
  */
10
10
  export declare function withReact(pluginOptions?: WithReactOptions): (config: Configuration, context: NxWebpackExecutionContext) => Configuration;
11
- export {};
@@ -13,7 +13,6 @@ const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies")
13
13
  const devkit_1 = require("@nx/devkit");
14
14
  const init_1 = require("../init/init");
15
15
  const eslint_1 = require("@nx/eslint");
16
- const lint_project_1 = require("@nx/eslint/src/generators/lint-project/lint-project");
17
16
  const versions_1 = require("../../utils/versions");
18
17
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
19
18
  const create_ts_config_1 = require("../../utils/create-ts-config");
@@ -32,9 +31,6 @@ async function addLinting(host, options) {
32
31
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
33
32
  ],
34
33
  unitTestRunner: options.unitTestRunner,
35
- eslintFilePatterns: [
36
- (0, lint_project_1.mapLintPattern)(options.appProjectRoot, '{ts,tsx,js,jsx}', options.rootProject),
37
- ],
38
34
  skipFormat: true,
39
35
  rootProject: options.rootProject,
40
36
  skipPackageJson: options.skipPackageJson,
@@ -68,6 +64,14 @@ async function applicationGeneratorInternal(host, schema) {
68
64
  skipHelperLibs: options.bundler === 'vite',
69
65
  });
70
66
  tasks.push(initTask);
67
+ if (options.bundler === 'webpack') {
68
+ const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
69
+ const webpackInitTask = await webpackInitGenerator(host, {
70
+ uiFramework: 'react',
71
+ skipFormat: true,
72
+ });
73
+ tasks.push(webpackInitTask);
74
+ }
71
75
  if (!options.rootProject) {
72
76
  (0, create_ts_config_1.extractTsConfigBase)(host);
73
77
  }
@@ -108,14 +112,6 @@ async function applicationGeneratorInternal(host, schema) {
108
112
  plugins: ['react()'],
109
113
  }, false);
110
114
  }
111
- else if (options.bundler === 'webpack') {
112
- const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
113
- const webpackInitTask = await webpackInitGenerator(host, {
114
- uiFramework: 'react',
115
- skipFormat: true,
116
- });
117
- tasks.push(webpackInitTask);
118
- }
119
115
  else if (options.bundler === 'rspack') {
120
116
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
121
117
  const rspackTask = await configurationGenerator(host, {
@@ -1,9 +1,50 @@
1
+ <% if (webpackPluginOptions) { %>
2
+ const { NxWebpackPlugin } = require('@nx/webpack');
3
+ const { NxReactWebpackPlugin } = require('@nx/react');
4
+ const { join } = require('path');
5
+
6
+ module.exports = {
7
+ output: {
8
+ path: join(__dirname, '<%= offsetFromRoot %><%= webpackPluginOptions.outputPath %>'),
9
+ },
10
+ devServer: {
11
+ port: 4200
12
+ },
13
+ plugins: [
14
+ new NxWebpackPlugin({
15
+ tsConfig: '<%= webpackPluginOptions.tsConfig %>',
16
+ compiler: '<%= webpackPluginOptions.compiler %>',
17
+ main: '<%= webpackPluginOptions.main %>',
18
+ index: '<%= webpackPluginOptions.index %>',
19
+ baseHref: '<%= webpackPluginOptions.baseHref %>',
20
+ assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
21
+ styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
22
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
23
+ optimization: process.env['NODE_ENV'] === 'production',
24
+ }),
25
+ new NxReactWebpackPlugin({
26
+ // Uncomment this line if you don't want to use SVGR
27
+ // See: https://react-svgr.com/
28
+ // svgr: false
29
+ }),
30
+ ],
31
+ };
32
+ <% } else { %>
1
33
  const { composePlugins, withNx } = require('@nx/webpack');
2
34
  const { withReact } = require('@nx/react');
3
35
 
4
36
  // Nx plugins for webpack.
5
- module.exports = composePlugins(withNx(), withReact(), (config) => {
6
- // Update the webpack config as needed here.
7
- // e.g. `config.plugins.push(new MyPlugin())`
8
- return config;
9
- });
37
+ module.exports = composePlugins(
38
+ withNx(),
39
+ withReact({
40
+ // Uncomment this line if you don't want to use SVGR
41
+ // See: https://react-svgr.com/
42
+ // svgr: false
43
+ }),
44
+ (config) => {
45
+ // Update the webpack config as needed here.
46
+ // e.g. `config.plugins.push(new MyPlugin())`
47
+ return config;
48
+ }
49
+ );
50
+ <% } %>
@@ -4,13 +4,16 @@ exports.addE2e = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const web_1 = require("@nx/web");
6
6
  const versions_1 = require("../../../utils/versions");
7
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
7
8
  async function addE2e(tree, options) {
8
9
  switch (options.e2eTestRunner) {
9
10
  case 'cypress': {
10
- (0, web_1.webStaticServeGenerator)(tree, {
11
- buildTarget: `${options.projectName}:build`,
12
- targetName: 'serve-static',
13
- });
11
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) {
12
+ (0, web_1.webStaticServeGenerator)(tree, {
13
+ buildTarget: `${options.projectName}:build`,
14
+ targetName: 'serve-static',
15
+ });
16
+ }
14
17
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
15
18
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
16
19
  projectType: 'application',
@@ -1,3 +1,4 @@
1
1
  import { NormalizedSchema } from '../schema';
2
- export declare function addProject(host: any, options: NormalizedSchema): void;
2
+ import { Tree } from '@nx/devkit';
3
+ export declare function addProject(host: Tree, options: NormalizedSchema): void;
3
4
  export declare function maybeJs(options: NormalizedSchema, path: string): string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.maybeJs = exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
5
6
  function addProject(host, options) {
6
7
  const project = {
7
8
  root: options.appProjectRoot,
@@ -11,10 +12,12 @@ function addProject(host, options) {
11
12
  tags: options.parsedTags,
12
13
  };
13
14
  if (options.bundler === 'webpack') {
14
- project.targets = {
15
- build: createBuildTarget(options),
16
- serve: createServeTarget(options),
17
- };
15
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(host)) {
16
+ project.targets = {
17
+ build: createBuildTarget(options),
18
+ serve: createServeTarget(options),
19
+ };
20
+ }
18
21
  }
19
22
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
20
23
  ...project,
@@ -7,6 +7,8 @@ const path_1 = require("path");
7
7
  const create_ts_config_1 = require("../../../utils/create-ts-config");
8
8
  const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
9
9
  const get_app_tests_1 = require("./get-app-tests");
10
+ const add_project_1 = require("./add-project");
11
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
10
12
  function createApplicationFiles(host, options) {
11
13
  let styleSolutionSpecificAppFiles;
12
14
  if (options.styledModule && options.style !== 'styled-jsx') {
@@ -38,7 +40,12 @@ function createApplicationFiles(host, options) {
38
40
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
39
41
  }
40
42
  else if (options.bundler === 'webpack') {
41
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, templateVariables);
43
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
44
+ ...templateVariables,
45
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(host)
46
+ ? createNxWebpackPluginOptions(options)
47
+ : null,
48
+ });
42
49
  if (options.compiler === 'babel') {
43
50
  (0, devkit_1.writeJson)(host, `${options.appProjectRoot}/.babelrc`, {
44
51
  presets: [
@@ -112,3 +119,20 @@ function createApplicationFiles(host, options) {
112
119
  (0, create_ts_config_1.createTsConfig)(host, options.appProjectRoot, 'app', options, relativePathToRootTsConfig);
113
120
  }
114
121
  exports.createApplicationFiles = createApplicationFiles;
122
+ function createNxWebpackPluginOptions(options) {
123
+ return {
124
+ target: 'web',
125
+ compiler: options.compiler ?? 'babel',
126
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
127
+ ? options.appProjectRoot
128
+ : options.projectName),
129
+ index: './src/index.html',
130
+ baseHref: '/',
131
+ main: (0, add_project_1.maybeJs)(options, `./src/main.tsx`),
132
+ tsConfig: './tsconfig.app.json',
133
+ assets: ['./src/favicon.ico', './src/assets'],
134
+ styles: options.styledModule || !options.hasStyles
135
+ ? []
136
+ : [`./src/styles.${options.style}`],
137
+ };
138
+ }
@@ -15,7 +15,6 @@ async function addLinting(host, options) {
15
15
  (0, path_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
16
16
  ],
17
17
  unitTestRunner: options.unitTestRunner,
18
- eslintFilePatterns: [`${options.projectRoot}/**/*.{ts,tsx,js,jsx}`],
19
18
  skipFormat: true,
20
19
  skipPackageJson: options.skipPackageJson,
21
20
  setParserOptionsProject: options.setParserOptionsProject,
@@ -49,11 +49,12 @@ async function normalizeOptions(host, options) {
49
49
  if (appProjectConfig.projectType !== 'application') {
50
50
  throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
51
51
  }
52
- try {
53
- normalized.appMain = appProjectConfig.targets.build.options.main;
54
- normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
55
- }
56
- catch (e) {
52
+ normalized.appMain =
53
+ appProjectConfig.targets.build.options.main ??
54
+ findMainEntry(host, appProjectConfig.root);
55
+ normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
56
+ // TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
57
+ if (!normalized.appMain) {
57
58
  throw new Error(`Could not locate project main for ${options.appProject}`);
58
59
  }
59
60
  }
@@ -61,3 +62,27 @@ async function normalizeOptions(host, options) {
61
62
  return normalized;
62
63
  }
63
64
  exports.normalizeOptions = normalizeOptions;
65
+ function findMainEntry(tree, projectRoot) {
66
+ const mainFiles = [
67
+ // These are the main files we generate with.
68
+ 'src/main.ts',
69
+ 'src/main.tsx',
70
+ 'src/main.js',
71
+ 'src/main.jsx',
72
+ // Other options just in case
73
+ 'src/index.ts',
74
+ 'src/index.tsx',
75
+ 'src/index.js',
76
+ 'src/index.jsx',
77
+ 'main.ts',
78
+ 'main.tsx',
79
+ 'main.js',
80
+ 'main.jsx',
81
+ 'index.ts',
82
+ 'index.tsx',
83
+ 'index.js',
84
+ 'index.jsx',
85
+ ];
86
+ const mainEntry = mainFiles.find((file) => tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file)));
87
+ return mainEntry ? (0, devkit_1.joinPathFragments)(projectRoot, mainEntry) : undefined;
88
+ }
@@ -21,7 +21,7 @@ async function setupSsrForRemote(tree, options, appName) {
21
21
  const serverOptions = project.targets.server?.options;
22
22
  const serverOutputPath = serverOptions?.outputPath ??
23
23
  (0, devkit_1.joinPathFragments)(originalOutputPath, 'server');
24
- const serverOutputName = serverOptions?.outputName ?? 'main.js';
24
+ const serverOutputName = serverOptions?.outputFileName ?? 'main.js';
25
25
  project.targets['serve-static'] = {
26
26
  dependsOn: ['build', 'server'],
27
27
  executor: 'nx:run-commands',
@@ -65,7 +65,6 @@ async function setupSsrGenerator(tree, options) {
65
65
  compiler: 'babel',
66
66
  externalDependencies: 'all',
67
67
  outputHashing: 'none',
68
- isolatedConfig: true,
69
68
  webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
70
69
  },
71
70
  configurations: {
@@ -5,7 +5,7 @@ const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const project_graph_1 = require("nx/src/project-graph/project-graph");
7
7
  function getFunctionDeterminateRemoteUrl(isServer = false) {
8
- const target = isServer ? 'serve-server' : 'serve';
8
+ const target = 'serve';
9
9
  const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
10
10
  return function (remote) {
11
11
  const mappedStaticRemotesFromEnv = process.env
@@ -1,7 +1,7 @@
1
1
  import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
2
- import type { AsyncNxWebpackPlugin } from '@nx/webpack';
2
+ import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
3
3
  /**
4
4
  * @param {ModuleFederationConfig} options
5
- * @return {Promise<AsyncNxWebpackPlugin>}
5
+ * @return {Promise<AsyncNxComposableWebpackPlugin>}
6
6
  */
7
- export declare function withModuleFederation(options: ModuleFederationConfig): Promise<AsyncNxWebpackPlugin>;
7
+ export declare function withModuleFederation(options: ModuleFederationConfig): Promise<AsyncNxComposableWebpackPlugin>;
@@ -5,7 +5,7 @@ const utils_1 = require("./utils");
5
5
  const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
6
6
  /**
7
7
  * @param {ModuleFederationConfig} options
8
- * @return {Promise<AsyncNxWebpackPlugin>}
8
+ * @return {Promise<AsyncNxComposableWebpackPlugin>}
9
9
  */
10
10
  async function withModuleFederation(options) {
11
11
  const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasWebpackPlugin(tree: Tree): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasWebpackPlugin = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasWebpackPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return !!nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/webpack/plugin'
9
+ : p.plugin === '@nx/webpack/plugin');
10
+ }
11
+ exports.hasWebpackPlugin = hasWebpackPlugin;
@@ -1,3 +0,0 @@
1
- export const environment = {
2
- production: true
3
- };
@@ -1,6 +0,0 @@
1
- // This file can be replaced during build by using the `fileReplacements` array.
2
- // When building for production, this file is replaced with `environment.prod.ts`.
3
-
4
- export const environment = {
5
- production: false
6
- };