@nx/react 16.8.0-beta.3 → 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/babel.js +2 -3
- package/package.json +7 -7
- package/plugins/bundle-rollup.js +9 -3
- package/plugins/component-testing/index.js +57 -37
- package/plugins/jest.js +4 -6
- package/plugins/storybook/index.js +46 -17
- package/plugins/with-react.js +5 -9
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +101 -103
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +67 -72
- package/src/generators/application/application.js +124 -124
- package/src/generators/application/lib/add-e2e.js +41 -37
- package/src/generators/application/lib/add-jest.js +13 -8
- package/src/generators/application/lib/add-project.js +4 -3
- package/src/generators/application/lib/create-application-files.js +8 -1
- package/src/generators/application/lib/find-free-port.js +1 -2
- package/src/generators/application/lib/normalize-options.js +49 -47
- package/src/generators/application/lib/set-defaults.js +25 -5
- package/src/generators/component/component.js +68 -64
- package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -9
- package/src/generators/component-story/component-story.js +8 -9
- package/src/generators/component-test/component-test.js +15 -18
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -26
- package/src/generators/cypress-component-configuration/lib/add-files.js +38 -42
- package/src/generators/hook/hook.js +59 -58
- package/src/generators/host/host.js +54 -53
- package/src/generators/host/lib/add-module-federation-files.js +11 -3
- package/src/generators/host/lib/normalize-remote.js +8 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +21 -15
- package/src/generators/host/lib/update-module-federation-e2e-project.js +5 -2
- package/src/generators/init/init.js +30 -20
- package/src/generators/library/lib/add-linting.js +24 -27
- package/src/generators/library/lib/add-rollup-build-target.js +42 -46
- package/src/generators/library/lib/create-files.js +7 -1
- package/src/generators/library/lib/normalize-options.js +53 -50
- package/src/generators/library/lib/set-defaults.js +12 -4
- package/src/generators/library/library.js +122 -111
- package/src/generators/redux/redux.js +25 -16
- package/src/generators/remote/lib/setup-ssr-for-remote.js +25 -23
- package/src/generators/remote/remote.js +44 -39
- package/src/generators/setup-ssr/setup-ssr.js +134 -132
- package/src/generators/setup-tailwind/lib/update-project.js +3 -5
- package/src/generators/setup-tailwind/setup-tailwind.js +23 -26
- package/src/generators/stories/stories.js +79 -88
- package/src/generators/storybook-configuration/configuration.js +40 -47
- package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +2 -5
- package/src/migrations/update-12-0-0/update-emotion-setup.js +50 -55
- package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +14 -18
- package/src/migrations/update-12-8-0/update-12-8-0.js +3 -6
- package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +23 -26
- package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
- package/src/migrations/update-13-0-0/webpack5-changes-utils.js +30 -34
- package/src/migrations/update-13-10-0/update-13-10-0.js +15 -18
- package/src/migrations/update-14-0-0/add-default-development-configurations.js +26 -31
- package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +12 -16
- package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +13 -17
- package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +24 -27
- package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -2
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +3 -4
- package/src/migrations/update-15-3-0/update-rollup-executor.js +1 -2
- package/src/migrations/update-15-6-3/webpack-config-setup.js +56 -60
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +3 -6
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +3 -6
- package/src/migrations/update-16-7-0/add-babel-core.js +8 -11
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +36 -41
- package/src/module-federation/ast-utils.js +1 -1
- package/src/module-federation/load-config.js +1 -1
- package/src/module-federation/utils.js +36 -37
- package/src/module-federation/with-module-federation-ssr.js +24 -25
- package/src/module-federation/with-module-federation.js +23 -22
- package/src/rules/update-module-federation-project.js +9 -2
- package/src/utils/ast-utils.js +12 -15
- package/src/utils/create-ts-config.js +6 -4
- package/src/utils/ct-utils.js +31 -33
- package/src/utils/lint.js +5 -3
- package/src/utils/testing-generators.js +18 -22
package/babel.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = function (api, options) {
|
|
|
7
7
|
/**
|
|
8
8
|
* pagesDir is set when being transpiled by Next.js
|
|
9
9
|
*/
|
|
10
|
-
const isNextJs = api.caller((caller) => caller
|
|
10
|
+
const isNextJs = api.caller((caller) => caller?.pagesDir);
|
|
11
11
|
const presets = [[require.resolve('@nx/js/babel'), options]];
|
|
12
12
|
/**
|
|
13
13
|
* Next.js already includes the preset-react, and including it
|
|
@@ -34,9 +34,8 @@ module.exports = function (api, options) {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
function getReactPresetOptions({ presetOptions, env }) {
|
|
37
|
-
var _a;
|
|
38
37
|
const reactPresetOptions = {
|
|
39
|
-
runtime:
|
|
38
|
+
runtime: presetOptions.runtime ?? 'automatic',
|
|
40
39
|
development: env !== 'production',
|
|
41
40
|
};
|
|
42
41
|
// JSX spread is transformed into object spread in `@babel/plugin-transform-react-jsx`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.5",
|
|
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": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"migrations": "./migrations.json"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nrwl/react": "16.8.0-beta.
|
|
35
|
-
"@nx/devkit": "16.8.0-beta.
|
|
36
|
-
"@nx/js": "16.8.0-beta.
|
|
37
|
-
"@nx/linter": "16.8.0-beta.
|
|
38
|
-
"@nx/web": "16.8.0-beta.
|
|
34
|
+
"@nrwl/react": "16.8.0-beta.5",
|
|
35
|
+
"@nx/devkit": "16.8.0-beta.5",
|
|
36
|
+
"@nx/js": "16.8.0-beta.5",
|
|
37
|
+
"@nx/linter": "16.8.0-beta.5",
|
|
38
|
+
"@nx/web": "16.8.0-beta.5",
|
|
39
39
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
40
40
|
"@svgr/webpack": "^8.0.1",
|
|
41
41
|
"chalk": "^4.1.0",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"type": "commonjs",
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ad2d1e8a55b2d1b358bb5e7483343d9757ff2c53"
|
|
51
51
|
}
|
package/plugins/bundle-rollup.js
CHANGED
|
@@ -10,11 +10,17 @@ function getRollupOptions(options) {
|
|
|
10
10
|
};
|
|
11
11
|
if (Array.isArray(options.output)) {
|
|
12
12
|
options.output.forEach((o) => {
|
|
13
|
-
o.globals =
|
|
13
|
+
o.globals = { ...o.globals, ...extraGlobals };
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
options.output =
|
|
17
|
+
options.output = {
|
|
18
|
+
...options.output,
|
|
19
|
+
globals: {
|
|
20
|
+
...options.output.globals,
|
|
21
|
+
...extraGlobals,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
// React buildable libs support SVGR, but not for React Native.
|
|
20
26
|
// If imports fail, ignore it.
|
|
@@ -33,7 +39,7 @@ function getRollupOptions(options) {
|
|
|
33
39
|
...options.plugins,
|
|
34
40
|
];
|
|
35
41
|
}
|
|
36
|
-
catch
|
|
42
|
+
catch {
|
|
37
43
|
// Ignored for React Native
|
|
38
44
|
}
|
|
39
45
|
return options;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nxComponentTestingPreset = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const ct_helpers_1 = require("@nx/cypress/src/utils/ct-helpers");
|
|
@@ -32,11 +31,16 @@ function nxComponentTestingPreset(pathToConfig, options) {
|
|
|
32
31
|
const basePresetSettings = (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig, {
|
|
33
32
|
testingType: 'component',
|
|
34
33
|
});
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
34
|
+
if (options?.bundler === 'vite') {
|
|
35
|
+
return {
|
|
36
|
+
...basePresetSettings,
|
|
37
|
+
specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}',
|
|
38
|
+
devServer: {
|
|
39
|
+
...{ framework: 'react', bundler: 'vite' },
|
|
40
|
+
viteConfig: async () => {
|
|
37
41
|
const viteConfigPath = findViteConfig(normalizedProjectRootPath);
|
|
38
|
-
const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } =
|
|
39
|
-
const resolved =
|
|
42
|
+
const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } = await Function('return import("vite")')();
|
|
43
|
+
const resolved = await loadConfigFromFile({
|
|
40
44
|
mode: 'watch',
|
|
41
45
|
command: 'serve',
|
|
42
46
|
}, viteConfigPath);
|
|
@@ -51,13 +55,15 @@ function nxComponentTestingPreset(pathToConfig, options) {
|
|
|
51
55
|
},
|
|
52
56
|
},
|
|
53
57
|
});
|
|
54
|
-
}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
62
|
let webpackConfig;
|
|
57
63
|
try {
|
|
58
64
|
const graph = (0, devkit_1.readCachedProjectGraph)();
|
|
59
65
|
const { targets: ctTargets, name: ctProjectName } = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
|
|
60
|
-
const ctTargetName =
|
|
66
|
+
const ctTargetName = options?.ctTargetName || 'component-test';
|
|
61
67
|
const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
|
|
62
68
|
const ctExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
|
|
63
69
|
const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
|
|
@@ -81,40 +87,49 @@ function nxComponentTestingPreset(pathToConfig, options) {
|
|
|
81
87
|
compiler: 'babel',
|
|
82
88
|
});
|
|
83
89
|
}
|
|
84
|
-
return
|
|
90
|
+
return {
|
|
91
|
+
...basePresetSettings,
|
|
92
|
+
specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}',
|
|
93
|
+
devServer: {
|
|
94
|
+
// cypress uses string union type,
|
|
95
|
+
// need to use const to prevent typing to string
|
|
96
|
+
// but don't want to use as const on webpackConfig
|
|
97
|
+
// so it is still user modifiable
|
|
98
|
+
...{ framework: 'react', bundler: 'webpack' },
|
|
99
|
+
webpackConfig,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
85
102
|
}
|
|
86
103
|
exports.nxComponentTestingPreset = nxComponentTestingPreset;
|
|
87
104
|
/**
|
|
88
105
|
* apply the schema.json defaults from the @nx/web:webpack executor to the target options
|
|
89
106
|
*/
|
|
90
107
|
function withSchemaDefaults(target, context) {
|
|
91
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
92
108
|
const options = (0, devkit_1.readTargetOptions)(target, context);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
options.compiler ??= 'babel';
|
|
110
|
+
options.deleteOutputPath ??= true;
|
|
111
|
+
options.vendorChunk ??= true;
|
|
112
|
+
options.commonChunk ??= true;
|
|
113
|
+
options.runtimeChunk ??= true;
|
|
114
|
+
options.sourceMap ??= true;
|
|
115
|
+
options.assets ??= [];
|
|
116
|
+
options.scripts ??= [];
|
|
117
|
+
options.styles ??= [];
|
|
118
|
+
options.budgets ??= [];
|
|
119
|
+
options.namedChunks ??= true;
|
|
120
|
+
options.outputHashing ??= 'none';
|
|
121
|
+
options.extractCss ??= true;
|
|
122
|
+
options.memoryLimit ??= 2048;
|
|
123
|
+
options.maxWorkers ??= 2;
|
|
124
|
+
options.fileReplacements ??= [];
|
|
125
|
+
options.buildLibsFromSource ??= true;
|
|
126
|
+
options.generateIndexHtml ??= true;
|
|
111
127
|
return options;
|
|
112
128
|
}
|
|
113
129
|
function buildTargetWebpack(graph, buildTarget, componentTestingProjectName) {
|
|
114
|
-
var _a, _b;
|
|
115
130
|
const parsed = (0, devkit_1.parseTargetString)(buildTarget, graph);
|
|
116
|
-
const buildableProjectConfig =
|
|
117
|
-
const ctProjectConfig =
|
|
131
|
+
const buildableProjectConfig = graph.nodes[parsed.project]?.data;
|
|
132
|
+
const ctProjectConfig = graph.nodes[componentTestingProjectName]?.data;
|
|
118
133
|
if (!buildableProjectConfig || !ctProjectConfig) {
|
|
119
134
|
throw new Error((0, devkit_1.stripIndents) `Unable to load project configs from graph.
|
|
120
135
|
Using build target '${buildTarget}'
|
|
@@ -131,23 +146,28 @@ function buildTargetWebpack(graph, buildTarget, componentTestingProjectName) {
|
|
|
131
146
|
if (options.webpackConfig) {
|
|
132
147
|
customWebpack = resolveCustomWebpackConfig(options.webpackConfig, options.tsConfig);
|
|
133
148
|
}
|
|
134
|
-
return () =>
|
|
135
|
-
customWebpack =
|
|
149
|
+
return async () => {
|
|
150
|
+
customWebpack = await customWebpack;
|
|
136
151
|
// TODO(jack): Once webpackConfig is always set in @nx/webpack:webpack, we no longer need this default.
|
|
137
|
-
const defaultWebpack = getWebpackConfig(context,
|
|
152
|
+
const defaultWebpack = getWebpackConfig(context, {
|
|
153
|
+
...options,
|
|
138
154
|
// cypress will generate its own index.html from component-index.html
|
|
139
|
-
generateIndexHtml: false,
|
|
155
|
+
generateIndexHtml: false,
|
|
140
156
|
// causes issues with buildable libraries with ENOENT: no such file or directory, scandir error
|
|
141
|
-
extractLicenses: false,
|
|
157
|
+
extractLicenses: false,
|
|
158
|
+
root: devkit_1.workspaceRoot,
|
|
159
|
+
projectRoot: ctProjectConfig.root,
|
|
160
|
+
sourceRoot: ctProjectConfig.sourceRoot,
|
|
161
|
+
});
|
|
142
162
|
if (customWebpack) {
|
|
143
|
-
return
|
|
163
|
+
return await customWebpack(defaultWebpack, {
|
|
144
164
|
options,
|
|
145
165
|
context,
|
|
146
166
|
configuration: parsed.configuration,
|
|
147
167
|
});
|
|
148
168
|
}
|
|
149
169
|
return defaultWebpack;
|
|
150
|
-
}
|
|
170
|
+
};
|
|
151
171
|
}
|
|
152
172
|
function findViteConfig(projectRootFullPath) {
|
|
153
173
|
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
package/plugins/jest.js
CHANGED
|
@@ -5,7 +5,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const JS_SOURCE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
6
6
|
module.exports = {
|
|
7
7
|
process(src, filename, options) {
|
|
8
|
-
var _a, _b;
|
|
9
8
|
const assetFilename = JSON.stringify(path.basename(filename));
|
|
10
9
|
if (filename.match(/\.svg$/)) {
|
|
11
10
|
// Based on how SVGR generates a component name:
|
|
@@ -32,7 +31,7 @@ module.exports = {
|
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
33
|
if (JS_SOURCE_EXTENSIONS.includes(path.extname(filename))) {
|
|
35
|
-
const transformer = getJsTransform(
|
|
34
|
+
const transformer = getJsTransform(options.config?.transform ?? []);
|
|
36
35
|
if (transformer)
|
|
37
36
|
return transformer.process(src, filename, options);
|
|
38
37
|
}
|
|
@@ -43,19 +42,18 @@ module.exports = {
|
|
|
43
42
|
},
|
|
44
43
|
};
|
|
45
44
|
function getJsTransform(transformers) {
|
|
46
|
-
var _a;
|
|
47
45
|
try {
|
|
48
|
-
if (
|
|
46
|
+
if (transformers?.[1]?.includes('@swc/jest')) {
|
|
49
47
|
return require('@swc/jest').createTransformer();
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
catch
|
|
50
|
+
catch {
|
|
53
51
|
// ignored
|
|
54
52
|
}
|
|
55
53
|
try {
|
|
56
54
|
return require('babel-jest').default.createTransformer();
|
|
57
55
|
}
|
|
58
|
-
catch
|
|
56
|
+
catch {
|
|
59
57
|
// ignored
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.webpack = exports.core = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const config_1 = require("@nx/webpack/src/utils/config");
|
|
7
6
|
const path_1 = require("path");
|
|
@@ -43,9 +42,12 @@ function getClientEnvironment(mode) {
|
|
|
43
42
|
};
|
|
44
43
|
return { stringified };
|
|
45
44
|
}
|
|
46
|
-
const core = (prev, options) => (
|
|
45
|
+
const core = (prev, options) => ({
|
|
46
|
+
...prev,
|
|
47
|
+
disableWebpackDefaults: true,
|
|
48
|
+
});
|
|
47
49
|
exports.core = core;
|
|
48
|
-
const getProjectData = (storybookOptions) =>
|
|
50
|
+
const getProjectData = async (storybookOptions) => {
|
|
49
51
|
const fallbackData = {
|
|
50
52
|
workspaceRoot: storybookOptions.configDir,
|
|
51
53
|
projectRoot: '',
|
|
@@ -54,7 +56,7 @@ const getProjectData = (storybookOptions) => tslib_1.__awaiter(void 0, void 0, v
|
|
|
54
56
|
// Edge-case: not running from Nx
|
|
55
57
|
if (!process.env.NX_WORKSPACE_ROOT)
|
|
56
58
|
return fallbackData;
|
|
57
|
-
const projectGraph =
|
|
59
|
+
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
58
60
|
const projectNode = projectGraph.nodes[process.env.NX_TASK_TARGET_PROJECT];
|
|
59
61
|
return projectNode
|
|
60
62
|
? {
|
|
@@ -65,16 +67,15 @@ const getProjectData = (storybookOptions) => tslib_1.__awaiter(void 0, void 0, v
|
|
|
65
67
|
}
|
|
66
68
|
: // Edge-case: missing project node
|
|
67
69
|
fallbackData;
|
|
68
|
-
}
|
|
70
|
+
};
|
|
69
71
|
const fixBabelConfigurationIfNeeded = (webpackConfig, projectData) => {
|
|
70
72
|
if (!projectData.projectNode)
|
|
71
73
|
return;
|
|
72
74
|
const isUsingBabelUpwardRootMode = Object.keys(projectData.projectNode.data.targets).find((k) => {
|
|
73
|
-
var _a;
|
|
74
75
|
const targetConfig = projectData.projectNode.data.targets[k];
|
|
75
76
|
return ((targetConfig.executor === '@nx/webpack:webpack' ||
|
|
76
77
|
targetConfig.executor === '@nrwl/webpack:webpack') &&
|
|
77
|
-
|
|
78
|
+
targetConfig.options?.babelUpwardRootMode);
|
|
78
79
|
});
|
|
79
80
|
if (isUsingBabelUpwardRootMode)
|
|
80
81
|
return;
|
|
@@ -106,22 +107,33 @@ const fixBabelConfigurationIfNeeded = (webpackConfig, projectData) => {
|
|
|
106
107
|
babelRuleItem.options.configFile = babelrcPath;
|
|
107
108
|
}
|
|
108
109
|
};
|
|
109
|
-
const webpack = (storybookWebpackConfig = {}, options) =>
|
|
110
|
-
var _a, _b, _c, _d, _e, _f;
|
|
110
|
+
const webpack = async (storybookWebpackConfig = {}, options) => {
|
|
111
111
|
devkit_1.logger.info('=> Loading Nx React Storybook Addon from "@nx/react/plugins/storybook"');
|
|
112
112
|
// In case anyone is missing dep and did not run migrations.
|
|
113
113
|
// See: https://github.com/nrwl/nx/issues/14455
|
|
114
114
|
try {
|
|
115
115
|
require.resolve('@nx/webpack');
|
|
116
116
|
}
|
|
117
|
-
catch
|
|
117
|
+
catch {
|
|
118
118
|
throw new Error(`'@nx/webpack' package is not installed. Install it and try again.`);
|
|
119
119
|
}
|
|
120
120
|
const { withNx, withWeb } = require('@nx/webpack');
|
|
121
|
-
const projectData =
|
|
121
|
+
const projectData = await getProjectData(options);
|
|
122
122
|
const tsconfigPath = (0, path_1.join)(projectData.projectRoot, 'tsconfig.storybook.json');
|
|
123
123
|
fixBabelConfigurationIfNeeded(storybookWebpackConfig, projectData);
|
|
124
|
-
const builderOptions =
|
|
124
|
+
const builderOptions = {
|
|
125
|
+
...options,
|
|
126
|
+
root: projectData.workspaceRoot,
|
|
127
|
+
projectRoot: projectData.projectRoot,
|
|
128
|
+
sourceRoot: projectData.sourceRoot,
|
|
129
|
+
fileReplacements: [],
|
|
130
|
+
sourceMap: true,
|
|
131
|
+
styles: options.styles ?? [],
|
|
132
|
+
optimization: {},
|
|
133
|
+
tsConfig: tsconfigPath,
|
|
134
|
+
extractCss: storybookWebpackConfig.mode === 'production',
|
|
135
|
+
target: 'web',
|
|
136
|
+
};
|
|
125
137
|
// ESM build for modern browsers.
|
|
126
138
|
let baseWebpackConfig = {};
|
|
127
139
|
const configure = (0, config_1.composePluginsSync)(withNx({ skipTypeChecking: true }), withWeb(), (0, with_react_1.withReact)());
|
|
@@ -129,13 +141,30 @@ const webpack = (storybookWebpackConfig = {}, options) => tslib_1.__awaiter(void
|
|
|
129
141
|
options: builderOptions,
|
|
130
142
|
context: { root: devkit_1.workspaceRoot }, // The context is not used here.
|
|
131
143
|
});
|
|
132
|
-
return
|
|
144
|
+
return {
|
|
145
|
+
...storybookWebpackConfig,
|
|
146
|
+
module: {
|
|
147
|
+
...storybookWebpackConfig.module,
|
|
148
|
+
rules: [
|
|
133
149
|
...storybookWebpackConfig.module.rules,
|
|
134
150
|
...finalConfig.module.rules,
|
|
135
|
-
]
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
resolve: {
|
|
154
|
+
...storybookWebpackConfig.resolve,
|
|
155
|
+
fallback: {
|
|
156
|
+
...storybookWebpackConfig.resolve?.fallback,
|
|
136
157
|
// Next.js and other React frameworks may have server-code that uses these modules.
|
|
137
158
|
// They are not meant for client-side components so skip the fallbacks.
|
|
138
|
-
assert: false,
|
|
139
|
-
|
|
140
|
-
|
|
159
|
+
assert: false,
|
|
160
|
+
path: false,
|
|
161
|
+
util: false,
|
|
162
|
+
},
|
|
163
|
+
plugins: (0, merge_plugins_1.mergePlugins)(...(storybookWebpackConfig.resolve.plugins ??
|
|
164
|
+
[]), ...(finalConfig.resolve
|
|
165
|
+
.plugins ?? [])),
|
|
166
|
+
},
|
|
167
|
+
plugins: (0, merge_plugins_1.mergePlugins)(new webpack_1.DefinePlugin(getClientEnvironment(storybookWebpackConfig.mode).stringified), ...(storybookWebpackConfig.plugins ?? []), ...(finalConfig.plugins ?? [])),
|
|
168
|
+
};
|
|
169
|
+
};
|
|
141
170
|
exports.webpack = webpack;
|
package/plugins/with-react.js
CHANGED
|
@@ -3,15 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withReact = void 0;
|
|
4
4
|
const processed = new Set();
|
|
5
5
|
function addHotReload(config) {
|
|
6
|
-
|
|
7
|
-
if (config.mode === 'development' && ((_a = config['devServer']) === null || _a === void 0 ? void 0 : _a.hot)) {
|
|
6
|
+
if (config.mode === 'development' && config['devServer']?.hot) {
|
|
8
7
|
// add `react-refresh/babel` to babel loader plugin
|
|
9
|
-
const babelLoader = config.module.rules.find((rule) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
typeof rule !== 'string' &&
|
|
13
|
-
((_a = rule.loader) === null || _a === void 0 ? void 0 : _a.toString().includes('babel-loader'));
|
|
14
|
-
});
|
|
8
|
+
const babelLoader = config.module.rules.find((rule) => rule &&
|
|
9
|
+
typeof rule !== 'string' &&
|
|
10
|
+
rule.loader?.toString().includes('babel-loader'));
|
|
15
11
|
if (babelLoader && typeof babelLoader !== 'string') {
|
|
16
12
|
babelLoader.options['plugins'] = [
|
|
17
13
|
...(babelLoader.options['plugins'] || []),
|
|
@@ -47,7 +43,7 @@ function withReact(pluginOptions = {}) {
|
|
|
47
43
|
// Apply web config for CSS, JSX, index.html handling, etc.
|
|
48
44
|
config = withWeb(pluginOptions)(config, context);
|
|
49
45
|
addHotReload(config);
|
|
50
|
-
if (
|
|
46
|
+
if (pluginOptions?.svgr !== false) {
|
|
51
47
|
removeSvgLoaderIfPresent(config);
|
|
52
48
|
config.module.rules.push({
|
|
53
49
|
test: /\.svg$/,
|