@nx/react 17.1.0-beta.4 → 17.1.0-rc.0

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
@@ -19,3 +19,4 @@ export { componentTestGenerator } from './src/generators/component-test/componen
19
19
  export { setupTailwindGenerator } from './src/generators/setup-tailwind/setup-tailwind';
20
20
  export type { SupportedStyles } from './typings/style';
21
21
  export * from './plugins/with-react';
22
+ export { NxReactWebpackPlugin } from './plugins/nx-react-webpack-plugin/nx-react-webpack-plugin';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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 = void 0;
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;
4
4
  const tslib_1 = require("tslib");
5
5
  var lint_1 = require("./src/utils/lint");
6
6
  Object.defineProperty(exports, "extraEslintDependencies", { enumerable: true, get: function () { return lint_1.extraEslintDependencies; } });
@@ -43,3 +43,5 @@ Object.defineProperty(exports, "componentTestGenerator", { enumerable: true, get
43
43
  var setup_tailwind_1 = require("./src/generators/setup-tailwind/setup-tailwind");
44
44
  Object.defineProperty(exports, "setupTailwindGenerator", { enumerable: true, get: function () { return setup_tailwind_1.setupTailwindGenerator; } });
45
45
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "17.1.0-beta.4",
3
+ "version": "17.1.0-rc.0",
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.1.0-beta.4",
41
- "@nx/js": "17.1.0-beta.4",
42
- "@nx/eslint": "17.1.0-beta.4",
43
- "@nx/web": "17.1.0-beta.4",
44
- "@nrwl/react": "17.1.0-beta.4"
40
+ "@nx/devkit": "17.1.0-rc.0",
41
+ "@nx/js": "17.1.0-rc.0",
42
+ "@nx/eslint": "17.1.0-rc.0",
43
+ "@nx/web": "17.1.0-rc.0",
44
+ "@nrwl/react": "17.1.0-rc.0"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -0,0 +1,4 @@
1
+ import { Configuration, WebpackOptionsNormalized } from 'webpack';
2
+ export declare function applyReactConfig(options: {
3
+ svgr?: boolean;
4
+ }, config?: Partial<WebpackOptionsNormalized | Configuration>): void;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyReactConfig = void 0;
4
+ function applyReactConfig(options, config = {}) {
5
+ addHotReload(config);
6
+ if (options.svgr !== false) {
7
+ removeSvgLoaderIfPresent(config);
8
+ config.module.rules.push({
9
+ test: /\.svg$/,
10
+ issuer: /\.(js|ts|md)x?$/,
11
+ use: [
12
+ {
13
+ loader: require.resolve('@svgr/webpack'),
14
+ options: {
15
+ svgo: false,
16
+ titleProp: true,
17
+ ref: true,
18
+ },
19
+ },
20
+ {
21
+ loader: require.resolve('file-loader'),
22
+ options: {
23
+ name: '[name].[hash].[ext]',
24
+ },
25
+ },
26
+ ],
27
+ });
28
+ }
29
+ // enable webpack node api
30
+ config.node = {
31
+ __dirname: true,
32
+ __filename: true,
33
+ };
34
+ }
35
+ exports.applyReactConfig = applyReactConfig;
36
+ function addHotReload(config) {
37
+ if (config.mode === 'development' && config['devServer']?.hot) {
38
+ // add `react-refresh/babel` to babel loader plugin
39
+ const babelLoader = config.module.rules.find((rule) => rule &&
40
+ typeof rule !== 'string' &&
41
+ rule.loader?.toString().includes('babel-loader'));
42
+ if (babelLoader && typeof babelLoader !== 'string') {
43
+ babelLoader.options['plugins'] = [
44
+ ...(babelLoader.options['plugins'] || []),
45
+ [
46
+ require.resolve('react-refresh/babel'),
47
+ {
48
+ skipEnvCheck: true,
49
+ },
50
+ ],
51
+ ];
52
+ }
53
+ const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
54
+ config.plugins.push(new ReactRefreshPlugin());
55
+ }
56
+ }
57
+ // We remove potentially conflicting rules that target SVGs because we use @svgr/webpack loader
58
+ // See https://github.com/nrwl/nx/issues/14383
59
+ function removeSvgLoaderIfPresent(config) {
60
+ const svgLoaderIdx = config.module.rules.findIndex((rule) => typeof rule === 'object' && rule.test.toString().includes('svg'));
61
+ if (svgLoaderIdx === -1)
62
+ return;
63
+ config.module.rules.splice(svgLoaderIdx, 1);
64
+ }
@@ -0,0 +1,8 @@
1
+ import { Compiler } from 'webpack';
2
+ export declare class NxReactWebpackPlugin {
3
+ private options;
4
+ constructor(options?: {
5
+ svgr?: boolean;
6
+ });
7
+ apply(compiler: Compiler): void;
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxReactWebpackPlugin = void 0;
4
+ const apply_react_config_1 = require("./lib/apply-react-config");
5
+ class NxReactWebpackPlugin {
6
+ constructor(options = {}) {
7
+ this.options = options;
8
+ }
9
+ apply(compiler) {
10
+ (0, apply_react_config_1.applyReactConfig)(this.options, compiler.options);
11
+ }
12
+ }
13
+ exports.NxReactWebpackPlugin = NxReactWebpackPlugin;
@@ -1,3 +1,3 @@
1
1
  import { ResolvePluginInstance, RuleSetRule, WebpackPluginInstance } from 'webpack';
2
- export declare const mergeRules: (...args: RuleSetRule[]) => (RuleSetRule | WebpackPluginInstance)[];
2
+ export declare const mergeRules: (...args: RuleSetRule[]) => (WebpackPluginInstance | RuleSetRule)[];
3
3
  export declare const mergePlugins: (...args: (WebpackPluginInstance | ResolvePluginInstance)[]) => (WebpackPluginInstance | ResolvePluginInstance)[];
@@ -1,6 +1,5 @@
1
1
  import type { Configuration } from 'webpack';
2
- import type { WithWebOptions } from '@nx/webpack';
3
- import type { NxWebpackExecutionContext } from '@nx/webpack';
2
+ import type { NxWebpackExecutionContext, WithWebOptions } from '@nx/webpack';
4
3
  interface WithReactOptions extends WithWebOptions {
5
4
  svgr?: false;
6
5
  }
@@ -1,36 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withReact = void 0;
4
+ const apply_react_config_1 = require("./nx-react-webpack-plugin/lib/apply-react-config");
4
5
  const processed = new Set();
5
- function addHotReload(config) {
6
- if (config.mode === 'development' && config['devServer']?.hot) {
7
- // add `react-refresh/babel` to babel loader plugin
8
- const babelLoader = config.module.rules.find((rule) => rule &&
9
- typeof rule !== 'string' &&
10
- rule.loader?.toString().includes('babel-loader'));
11
- if (babelLoader && typeof babelLoader !== 'string') {
12
- babelLoader.options['plugins'] = [
13
- ...(babelLoader.options['plugins'] || []),
14
- [
15
- require.resolve('react-refresh/babel'),
16
- {
17
- skipEnvCheck: true,
18
- },
19
- ],
20
- ];
21
- }
22
- const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
23
- config.plugins.push(new ReactRefreshPlugin());
24
- }
25
- }
26
- // We remove potentially conflicting rules that target SVGs because we use @svgr/webpack loader
27
- // See https://github.com/nrwl/nx/issues/14383
28
- function removeSvgLoaderIfPresent(config) {
29
- const svgLoaderIdx = config.module.rules.findIndex((rule) => typeof rule === 'object' && rule.test.toString().includes('svg'));
30
- if (svgLoaderIdx === -1)
31
- return;
32
- config.module.rules.splice(svgLoaderIdx, 1);
33
- }
34
6
  /**
35
7
  * @param {WithReactOptions} pluginOptions
36
8
  * @returns {NxWebpackPlugin}
@@ -42,35 +14,7 @@ function withReact(pluginOptions = {}) {
42
14
  return config;
43
15
  // Apply web config for CSS, JSX, index.html handling, etc.
44
16
  config = withWeb(pluginOptions)(config, context);
45
- addHotReload(config);
46
- if (pluginOptions?.svgr !== false) {
47
- removeSvgLoaderIfPresent(config);
48
- config.module.rules.push({
49
- test: /\.svg$/,
50
- issuer: /\.(js|ts|md)x?$/,
51
- use: [
52
- {
53
- loader: require.resolve('@svgr/webpack'),
54
- options: {
55
- svgo: false,
56
- titleProp: true,
57
- ref: true,
58
- },
59
- },
60
- {
61
- loader: require.resolve('file-loader'),
62
- options: {
63
- name: '[name].[hash].[ext]',
64
- },
65
- },
66
- ],
67
- });
68
- }
69
- // enable webpack node api
70
- config.node = {
71
- __dirname: true,
72
- __filename: true,
73
- };
17
+ (0, apply_react_config_1.applyReactConfig)(pluginOptions, config);
74
18
  processed.add(config);
75
19
  return config;
76
20
  };
@@ -59,10 +59,10 @@ async function federateModuleGenerator(tree, schema) {
59
59
  Now you can use the module from your host app like this:
60
60
 
61
61
  Static import:
62
- import { MyComponent } from '${schema.name}/${remoteName}';
62
+ import { MyComponent } from '${remoteName}/${schema.name}';
63
63
 
64
64
  Dynamic import:
65
- import('${schema.name}/${remoteName}').then((m) => m.${remoteName});
65
+ import('${remoteName}/${schema.name}').then((m) => m.${schema.name});
66
66
  `);
67
67
  return (0, devkit_1.runTasksInSerial)(...tasks);
68
68
  }
@@ -18,12 +18,16 @@ async function setupSsrForRemote(tree, options, appName) {
18
18
  });
19
19
  // For hosts to use when running remotes in static mode.
20
20
  const originalOutputPath = project.targets.build?.options?.outputPath;
21
+ const serverOptions = project.targets.server?.options;
22
+ const serverOutputPath = serverOptions?.outputPath ??
23
+ (0, devkit_1.joinPathFragments)(originalOutputPath, 'server');
24
+ const serverOutputName = serverOptions?.outputName ?? 'main.js';
21
25
  project.targets['serve-static'] = {
22
26
  dependsOn: ['build', 'server'],
23
27
  executor: 'nx:run-commands',
24
28
  defaultConfiguration: 'development',
25
29
  options: {
26
- command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(originalOutputPath, 'server', 'main.js')}`,
30
+ command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(serverOutputPath, serverOutputName)}`,
27
31
  },
28
32
  };
29
33
  (0, devkit_1.updateProjectConfiguration)(tree, appName, project);