@nx/react 20.3.0-canary.20241218-fb40366 → 20.3.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/migrations.json +6 -0
- package/package.json +6 -6
- package/src/generators/application/application.d.ts +3 -3
- package/src/generators/application/application.js +56 -193
- package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
- package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
- package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/application/lib/add-e2e.js +13 -1
- package/src/generators/application/lib/add-linting.d.ts +3 -0
- package/src/generators/application/lib/add-linting.js +48 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +5 -0
- package/src/generators/application/lib/bundlers/add-rspack.js +55 -0
- package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-vite.js +67 -0
- package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
- package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
- package/src/generators/application/lib/create-application-files.js +5 -0
- package/src/generators/application/schema.d.ts +1 -1
- package/src/generators/application/schema.json +1 -1
- package/src/generators/host/host.js +1 -0
- package/src/generators/library/library.js +3 -6
- package/src/generators/remote/remote.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +6 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts +2 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +18 -0
- package/src/utils/has-rsbuild-plugin.d.ts +2 -0
- package/src/utils/has-rsbuild-plugin.js +10 -0
package/migrations.json
CHANGED
@@ -41,6 +41,12 @@
|
|
41
41
|
"version": "20.2.0-beta.2",
|
42
42
|
"description": "Update the withModuleFederation import use @nx/module-federation/webpack.",
|
43
43
|
"factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
|
44
|
+
},
|
45
|
+
"ensure-nx-module-federation-package": {
|
46
|
+
"cli": "nx",
|
47
|
+
"version": "20.3.0-beta.2",
|
48
|
+
"description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.",
|
49
|
+
"factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package"
|
44
50
|
}
|
45
51
|
},
|
46
52
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/react",
|
3
|
-
"version": "20.3.0-
|
3
|
+
"version": "20.3.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, 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": {
|
@@ -38,11 +38,11 @@
|
|
38
38
|
"minimatch": "9.0.3",
|
39
39
|
"picocolors": "^1.1.0",
|
40
40
|
"tslib": "^2.3.0",
|
41
|
-
"@nx/devkit": "20.3.0-
|
42
|
-
"@nx/js": "20.3.0-
|
43
|
-
"@nx/eslint": "20.3.0-
|
44
|
-
"@nx/web": "20.3.0-
|
45
|
-
"@nx/module-federation": "20.3.0-
|
41
|
+
"@nx/devkit": "20.3.0-rc.0",
|
42
|
+
"@nx/js": "20.3.0-rc.0",
|
43
|
+
"@nx/eslint": "20.3.0-rc.0",
|
44
|
+
"@nx/web": "20.3.0-rc.0",
|
45
|
+
"@nx/module-federation": "20.3.0-rc.0",
|
46
46
|
"express": "^4.19.2",
|
47
47
|
"http-proxy-middleware": "^3.0.3"
|
48
48
|
},
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Schema } from './schema';
|
2
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
3
|
-
|
4
|
-
export declare function
|
2
|
+
import { Schema } from './schema';
|
3
|
+
export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
4
|
+
export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
5
5
|
export default applicationGenerator;
|
@@ -2,7 +2,14 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.applicationGenerator = applicationGenerator;
|
4
4
|
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
5
|
-
const
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
6
|
+
const js_1 = require("@nx/js");
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
9
|
+
const create_ts_config_1 = require("../../utils/create-ts-config");
|
10
|
+
const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
|
11
|
+
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
|
12
|
+
const init_1 = require("../init/init");
|
6
13
|
const create_application_files_1 = require("./lib/create-application-files");
|
7
14
|
const update_jest_config_1 = require("./lib/update-jest-config");
|
8
15
|
const normalize_options_1 = require("./lib/normalize-options");
|
@@ -10,71 +17,23 @@ const add_project_1 = require("./lib/add-project");
|
|
10
17
|
const add_jest_1 = require("./lib/add-jest");
|
11
18
|
const add_routing_1 = require("./lib/add-routing");
|
12
19
|
const set_defaults_1 = require("./lib/set-defaults");
|
13
|
-
const
|
14
|
-
const devkit_1 = require("@nx/devkit");
|
15
|
-
const init_1 = require("../init/init");
|
16
|
-
const eslint_1 = require("@nx/eslint");
|
17
|
-
const versions_1 = require("../../utils/versions");
|
18
|
-
const maybe_js_1 = require("../../utils/maybe-js");
|
19
|
-
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
20
|
-
const create_ts_config_1 = require("../../utils/create-ts-config");
|
21
|
-
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
22
|
-
const pc = require("picocolors");
|
23
|
-
const show_possible_warnings_1 = require("./lib/show-possible-warnings");
|
20
|
+
const add_linting_1 = require("./lib/add-linting");
|
24
21
|
const add_e2e_1 = require("./lib/add-e2e");
|
25
|
-
const
|
26
|
-
const
|
27
|
-
const
|
28
|
-
const
|
29
|
-
const
|
30
|
-
const
|
31
|
-
async function
|
32
|
-
|
33
|
-
if (options.linter === eslint_1.Linter.EsLint) {
|
34
|
-
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
35
|
-
linter: options.linter,
|
36
|
-
project: options.projectName,
|
37
|
-
tsConfigPaths: [
|
38
|
-
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
39
|
-
],
|
40
|
-
unitTestRunner: options.unitTestRunner,
|
41
|
-
skipFormat: true,
|
42
|
-
rootProject: options.rootProject,
|
43
|
-
skipPackageJson: options.skipPackageJson,
|
44
|
-
addPlugin: options.addPlugin,
|
45
|
-
});
|
46
|
-
tasks.push(lintTask);
|
47
|
-
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
48
|
-
if ((0, flat_config_1.useFlatConfig)(host)) {
|
49
|
-
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
|
50
|
-
// Add an empty rules object to users know how to add/override rules
|
51
|
-
(0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
|
52
|
-
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
53
|
-
rules: {},
|
54
|
-
});
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
|
58
|
-
tasks.push(addExtendsTask);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
if (!options.skipPackageJson) {
|
62
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
63
|
-
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
64
|
-
tasks.push(installTask, addSwcTask);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
68
|
-
}
|
69
|
-
async function applicationGenerator(host, schema) {
|
70
|
-
return await applicationGeneratorInternal(host, {
|
22
|
+
const show_possible_warnings_1 = require("./lib/show-possible-warnings");
|
23
|
+
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
24
|
+
const add_webpack_1 = require("./lib/bundlers/add-webpack");
|
25
|
+
const add_rspack_1 = require("./lib/bundlers/add-rspack");
|
26
|
+
const add_rsbuild_1 = require("./lib/bundlers/add-rsbuild");
|
27
|
+
const add_vite_1 = require("./lib/bundlers/add-vite");
|
28
|
+
async function applicationGenerator(tree, schema) {
|
29
|
+
return await applicationGeneratorInternal(tree, {
|
71
30
|
addPlugin: false,
|
72
31
|
...schema,
|
73
32
|
});
|
74
33
|
}
|
75
|
-
async function applicationGeneratorInternal(
|
34
|
+
async function applicationGeneratorInternal(tree, schema) {
|
76
35
|
const tasks = [];
|
77
|
-
const jsInitTask = await (0, js_1.initGenerator)(
|
36
|
+
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
78
37
|
...schema,
|
79
38
|
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
80
39
|
skipFormat: true,
|
@@ -82,15 +41,15 @@ async function applicationGeneratorInternal(host, schema) {
|
|
82
41
|
formatter: schema.formatter,
|
83
42
|
});
|
84
43
|
tasks.push(jsInitTask);
|
85
|
-
const options = await (0, normalize_options_1.normalizeOptions)(
|
86
|
-
(0, show_possible_warnings_1.showPossibleWarnings)(
|
87
|
-
const initTask = await (0, init_1.default)(
|
44
|
+
const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
|
45
|
+
(0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
|
46
|
+
const initTask = await (0, init_1.default)(tree, {
|
88
47
|
...options,
|
89
48
|
skipFormat: true,
|
90
49
|
});
|
91
50
|
tasks.push(initTask);
|
92
51
|
if (!options.addPlugin) {
|
93
|
-
const nxJson = (0, devkit_1.readNxJson)(
|
52
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
94
53
|
nxJson.targetDefaults ??= {};
|
95
54
|
if (!Object.keys(nxJson.targetDefaults).includes('build')) {
|
96
55
|
nxJson.targetDefaults.build = {
|
@@ -101,174 +60,78 @@ async function applicationGeneratorInternal(host, schema) {
|
|
101
60
|
else if (!nxJson.targetDefaults.build.dependsOn) {
|
102
61
|
nxJson.targetDefaults.build.dependsOn = ['^build'];
|
103
62
|
}
|
104
|
-
(0, devkit_1.updateNxJson)(
|
63
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
105
64
|
}
|
106
65
|
if (options.bundler === 'webpack') {
|
107
|
-
|
108
|
-
const webpackInitTask = await webpackInitGenerator(host, {
|
109
|
-
skipPackageJson: options.skipPackageJson,
|
110
|
-
skipFormat: true,
|
111
|
-
addPlugin: options.addPlugin,
|
112
|
-
});
|
113
|
-
tasks.push(webpackInitTask);
|
114
|
-
if (!options.skipPackageJson) {
|
115
|
-
const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
|
116
|
-
tasks.push(ensureDependencies(host, { uiFramework: 'react' }));
|
117
|
-
}
|
66
|
+
await (0, add_webpack_1.initWebpack)(tree, options, tasks);
|
118
67
|
}
|
119
68
|
else if (options.bundler === 'rspack') {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
skipFormat: true,
|
125
|
-
});
|
126
|
-
tasks.push(rspackInitTask);
|
69
|
+
await (0, add_rspack_1.initRspack)(tree, options, tasks);
|
70
|
+
}
|
71
|
+
else if (options.bundler === 'rsbuild') {
|
72
|
+
await (0, add_rsbuild_1.initRsbuild)(tree, options, tasks);
|
127
73
|
}
|
128
74
|
if (!options.rootProject) {
|
129
|
-
(0, create_ts_config_1.extractTsConfigBase)(
|
75
|
+
(0, create_ts_config_1.extractTsConfigBase)(tree);
|
130
76
|
}
|
131
|
-
await (0, create_application_files_1.createApplicationFiles)(
|
132
|
-
(0, add_project_1.addProject)(
|
77
|
+
await (0, create_application_files_1.createApplicationFiles)(tree, options);
|
78
|
+
(0, add_project_1.addProject)(tree, options);
|
133
79
|
if (options.style === 'tailwind') {
|
134
|
-
const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(
|
80
|
+
const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(tree, {
|
135
81
|
project: options.projectName,
|
136
82
|
});
|
137
83
|
tasks.push(twTask);
|
138
84
|
}
|
139
85
|
if (options.bundler === 'vite') {
|
140
|
-
|
141
|
-
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
142
|
-
// See: https://vitejs.dev/guide/env-and-mode.html
|
143
|
-
if (host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
|
144
|
-
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
|
145
|
-
}
|
146
|
-
const viteTask = await viteConfigurationGenerator(host, {
|
147
|
-
uiFramework: 'react',
|
148
|
-
project: options.projectName,
|
149
|
-
newProject: true,
|
150
|
-
includeVitest: options.unitTestRunner === 'vitest',
|
151
|
-
inSourceTests: options.inSourceTests,
|
152
|
-
compiler: options.compiler,
|
153
|
-
skipFormat: true,
|
154
|
-
addPlugin: options.addPlugin,
|
155
|
-
projectType: 'application',
|
156
|
-
});
|
157
|
-
tasks.push(viteTask);
|
158
|
-
createOrEditViteConfig(host, {
|
159
|
-
project: options.projectName,
|
160
|
-
includeLib: false,
|
161
|
-
includeVitest: options.unitTestRunner === 'vitest',
|
162
|
-
inSourceTests: options.inSourceTests,
|
163
|
-
rollupOptionsExternal: [
|
164
|
-
"'react'",
|
165
|
-
"'react-dom'",
|
166
|
-
"'react/jsx-runtime'",
|
167
|
-
],
|
168
|
-
imports: [
|
169
|
-
options.compiler === 'swc'
|
170
|
-
? `import react from '@vitejs/plugin-react-swc'`
|
171
|
-
: `import react from '@vitejs/plugin-react'`,
|
172
|
-
],
|
173
|
-
plugins: ['react()'],
|
174
|
-
}, false);
|
86
|
+
await (0, add_vite_1.setupViteConfiguration)(tree, options, tasks);
|
175
87
|
}
|
176
88
|
else if (options.bundler === 'rspack') {
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
js: options.js,
|
182
|
-
useJsx: true,
|
183
|
-
}, `src/main.tsx`)),
|
184
|
-
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
185
|
-
target: 'web',
|
186
|
-
newProject: true,
|
187
|
-
framework: 'react',
|
188
|
-
});
|
189
|
-
tasks.push(rspackTask);
|
89
|
+
await (0, add_rspack_1.setupRspackConfiguration)(tree, options, tasks);
|
90
|
+
}
|
91
|
+
else if (options.bundler === 'rsbuild') {
|
92
|
+
await (0, add_rsbuild_1.setupRsbuildConfiguration)(tree, options, tasks);
|
190
93
|
}
|
191
94
|
if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
|
192
|
-
|
193
|
-
const vitestTask = await vitestGenerator(host, {
|
194
|
-
uiFramework: 'react',
|
195
|
-
coverageProvider: 'v8',
|
196
|
-
project: options.projectName,
|
197
|
-
inSourceTests: options.inSourceTests,
|
198
|
-
skipFormat: true,
|
199
|
-
addPlugin: options.addPlugin,
|
200
|
-
});
|
201
|
-
tasks.push(vitestTask);
|
202
|
-
createOrEditViteConfig(host, {
|
203
|
-
project: options.projectName,
|
204
|
-
includeLib: false,
|
205
|
-
includeVitest: true,
|
206
|
-
inSourceTests: options.inSourceTests,
|
207
|
-
rollupOptionsExternal: [
|
208
|
-
"'react'",
|
209
|
-
"'react-dom'",
|
210
|
-
"'react/jsx-runtime'",
|
211
|
-
],
|
212
|
-
imports: [
|
213
|
-
options.compiler === 'swc'
|
214
|
-
? `import react from '@vitejs/plugin-react-swc'`
|
215
|
-
: `import react from '@vitejs/plugin-react'`,
|
216
|
-
],
|
217
|
-
plugins: ['react()'],
|
218
|
-
}, true);
|
95
|
+
await (0, add_vite_1.setupVitestConfiguration)(tree, options, tasks);
|
219
96
|
}
|
220
97
|
if ((options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
|
221
98
|
options.inSourceTests) {
|
222
|
-
|
99
|
+
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/${options.fileName}.spec.tsx`));
|
223
100
|
}
|
224
|
-
const lintTask = await addLinting(
|
101
|
+
const lintTask = await (0, add_linting_1.addLinting)(tree, options);
|
225
102
|
tasks.push(lintTask);
|
226
|
-
const e2eTask = await (0, add_e2e_1.addE2e)(
|
103
|
+
const e2eTask = await (0, add_e2e_1.addE2e)(tree, options);
|
227
104
|
tasks.push(e2eTask);
|
228
105
|
if (options.unitTestRunner === 'jest') {
|
229
|
-
const jestTask = await (0, add_jest_1.addJest)(
|
106
|
+
const jestTask = await (0, add_jest_1.addJest)(tree, options);
|
230
107
|
tasks.push(jestTask);
|
231
108
|
}
|
232
109
|
// Handle tsconfig.spec.json for jest or vitest
|
233
|
-
(0, update_jest_config_1.updateSpecConfig)(
|
234
|
-
const stylePreprocessorTask = (0, install_common_dependencies_1.installCommonDependencies)(
|
110
|
+
(0, update_jest_config_1.updateSpecConfig)(tree, options);
|
111
|
+
const stylePreprocessorTask = (0, install_common_dependencies_1.installCommonDependencies)(tree, options);
|
235
112
|
tasks.push(stylePreprocessorTask);
|
236
|
-
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(
|
113
|
+
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(tree, options);
|
237
114
|
tasks.push(styledTask);
|
238
|
-
const routingTask = (0, add_routing_1.addRouting)(
|
115
|
+
const routingTask = (0, add_routing_1.addRouting)(tree, options);
|
239
116
|
tasks.push(routingTask);
|
240
|
-
(0, set_defaults_1.setDefaults)(
|
117
|
+
(0, set_defaults_1.setDefaults)(tree, options);
|
241
118
|
if (options.bundler === 'rspack' && options.style === 'styled-jsx') {
|
242
|
-
|
243
|
-
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
|
244
|
-
host.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
|
245
|
-
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
246
|
-
module.exports = composePlugins(withNx(), withReact(), (config) => {
|
247
|
-
config.module.rules.push({
|
248
|
-
test: /\\.[jt]sx$/i,
|
249
|
-
use: [
|
250
|
-
{
|
251
|
-
loader: 'babel-loader',
|
252
|
-
options: {
|
253
|
-
presets: ['@babel/preset-typescript'],
|
254
|
-
plugins: ['styled-jsx/babel'],
|
255
|
-
},
|
256
|
-
},
|
257
|
-
],
|
258
|
-
});
|
259
|
-
return config;
|
260
|
-
});
|
261
|
-
`);
|
119
|
+
(0, add_rspack_1.handleStyledJsxForRspack)(tasks, tree, options);
|
262
120
|
}
|
263
|
-
(0, ts_solution_setup_1.updateTsconfigFiles)(
|
121
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
|
264
122
|
jsx: 'react-jsx',
|
265
123
|
module: 'esnext',
|
266
124
|
moduleResolution: 'bundler',
|
267
125
|
}, options.linter === 'eslint'
|
268
126
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
269
127
|
: undefined);
|
128
|
+
// If we are using the new TS solution
|
129
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
130
|
+
if (options.isUsingTsSolutionConfig) {
|
131
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
|
132
|
+
}
|
270
133
|
if (!options.skipFormat) {
|
271
|
-
await (0, devkit_1.formatFiles)(
|
134
|
+
await (0, devkit_1.formatFiles)(tree);
|
272
135
|
}
|
273
136
|
tasks.push(() => {
|
274
137
|
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
File without changes
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title><%= className %></title>
|
6
|
+
<base href="/" />
|
7
|
+
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
9
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<div id="root"></div>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%_ if (strict) { _%>import { StrictMode } from 'react';<%_ } _%>
|
2
|
+
import * as ReactDOM from 'react-dom/client';
|
3
|
+
<%_ if (routing) { _%>import { BrowserRouter } from 'react-router-dom';<%_ } _%>
|
4
|
+
import App from './app/<%= fileName %>';
|
5
|
+
<%_ if(hasStyleFile) { _%>
|
6
|
+
import './styles.<%= style %>'
|
7
|
+
<%_ } _%>
|
8
|
+
|
9
|
+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
10
|
+
<%_ if(strict && !routing) { _%>
|
11
|
+
root.render(
|
12
|
+
<StrictMode>
|
13
|
+
<App/>
|
14
|
+
</StrictMode>
|
15
|
+
)
|
16
|
+
<%_ } _%>
|
17
|
+
<%_ if(!strict && routing) { _%>
|
18
|
+
root.render(
|
19
|
+
<BrowserRouter>
|
20
|
+
<App/>
|
21
|
+
</BrowserRouter>
|
22
|
+
)
|
23
|
+
<%_ } _%>
|
24
|
+
<%_ if(strict && routing) { _%>
|
25
|
+
root.render(
|
26
|
+
<StrictMode>
|
27
|
+
<BrowserRouter>
|
28
|
+
<App/>
|
29
|
+
</BrowserRouter>
|
30
|
+
</StrictMode>
|
31
|
+
)
|
32
|
+
<%_ } _%>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%_ if (isUsingTsSolutionSetup) { _%>{
|
2
|
+
"extends": "<%= offsetFromRoot%>tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "dist",
|
5
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
6
|
+
"jsx": "react-jsx",
|
7
|
+
"lib": ["dom"],
|
8
|
+
"types": [
|
9
|
+
"node",
|
10
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
11
|
+
"@nx/react/typings/cssmodule.d.ts",
|
12
|
+
"@nx/react/typings/image.d.ts"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
16
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
17
|
+
}<% } else { %>{
|
18
|
+
"extends": "./tsconfig.json",
|
19
|
+
"compilerOptions": {
|
20
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
21
|
+
"types": [
|
22
|
+
"node",
|
23
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
24
|
+
"@nx/react/typings/cssmodule.d.ts",
|
25
|
+
"@nx/react/typings/image.d.ts"
|
26
|
+
]
|
27
|
+
},
|
28
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
29
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
30
|
+
}
|
31
|
+
<% } %>
|
@@ -7,11 +7,14 @@ const versions_1 = require("../../../utils/versions");
|
|
7
7
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
8
8
|
const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
|
9
9
|
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
10
|
+
const has_rsbuild_plugin_1 = require("../../../utils/has-rsbuild-plugin");
|
10
11
|
const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
|
11
12
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
12
13
|
async function addE2e(tree, options) {
|
13
14
|
const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
|
14
15
|
(options.bundler === 'rspack' && (0, has_rspack_plugin_1.hasRspackPlugin)(tree)) ||
|
16
|
+
(options.bundler === 'rsbuild' &&
|
17
|
+
(await (0, has_rsbuild_plugin_1.hasRsbuildPlugin)(tree, options.appProjectRoot))) ||
|
15
18
|
(options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
|
16
19
|
let e2eWebServerInfo = {
|
17
20
|
e2eWebServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
|
@@ -28,6 +31,11 @@ async function addE2e(tree, options) {
|
|
28
31
|
const { getViteE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
29
32
|
e2eWebServerInfo = await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
30
33
|
}
|
34
|
+
else if (options.bundler === 'rsbuild') {
|
35
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
36
|
+
const { getRsbuildE2EWebServerInfo } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
37
|
+
e2eWebServerInfo = await getRsbuildE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `rsbuild.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
38
|
+
}
|
31
39
|
if (!hasNxBuildPlugin) {
|
32
40
|
await (0, web_1.webStaticServeGenerator)(tree, {
|
33
41
|
buildTarget: `${options.projectName}:build`,
|
@@ -65,7 +73,11 @@ async function addE2e(tree, options) {
|
|
65
73
|
project: options.e2eProjectName,
|
66
74
|
directory: 'src',
|
67
75
|
// the name and root are already normalized, instruct the generator to use them as is
|
68
|
-
bundler: options.bundler === 'rspack'
|
76
|
+
bundler: options.bundler === 'rspack'
|
77
|
+
? 'webpack'
|
78
|
+
: options.bundler === 'rsbuild'
|
79
|
+
? 'none'
|
80
|
+
: options.bundler,
|
69
81
|
skipFormat: true,
|
70
82
|
devServerTarget: e2eWebServerInfo.e2eDevServerTarget,
|
71
83
|
baseUrl: e2eWebServerInfo.e2eWebServerAddress,
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.addLinting = addLinting;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const eslint_1 = require("@nx/eslint");
|
6
|
+
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
7
|
+
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
8
|
+
const devkit_2 = require("@nx/devkit");
|
9
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
10
|
+
const lint_1 = require("../../../utils/lint");
|
11
|
+
async function addLinting(host, options) {
|
12
|
+
const tasks = [];
|
13
|
+
if (options.linter === eslint_1.Linter.EsLint) {
|
14
|
+
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
15
|
+
linter: options.linter,
|
16
|
+
project: options.projectName,
|
17
|
+
tsConfigPaths: [
|
18
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
19
|
+
],
|
20
|
+
unitTestRunner: options.unitTestRunner,
|
21
|
+
skipFormat: true,
|
22
|
+
rootProject: options.rootProject,
|
23
|
+
skipPackageJson: options.skipPackageJson,
|
24
|
+
addPlugin: options.addPlugin,
|
25
|
+
});
|
26
|
+
tasks.push(lintTask);
|
27
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
28
|
+
if ((0, flat_config_1.useFlatConfig)(host)) {
|
29
|
+
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
|
30
|
+
// Add an empty rules object to users know how to add/override rules
|
31
|
+
(0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
|
32
|
+
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
33
|
+
rules: {},
|
34
|
+
});
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
|
38
|
+
tasks.push(addExtendsTask);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
if (!options.skipPackageJson) {
|
42
|
+
const installTask = (0, devkit_2.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
43
|
+
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
44
|
+
tasks.push(installTask, addSwcTask);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
return (0, devkit_2.runTasksInSerial)(...tasks);
|
48
|
+
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
3
|
+
export declare function initRsbuild(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
4
|
+
export declare function setupRsbuildConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.initRsbuild = initRsbuild;
|
4
|
+
exports.setupRsbuildConfiguration = setupRsbuildConfiguration;
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
6
|
+
const versions_1 = require("../../../../utils/versions");
|
7
|
+
const maybe_js_1 = require("../../../../utils/maybe-js");
|
8
|
+
async function initRsbuild(tree, options, tasks) {
|
9
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
10
|
+
const { initGenerator } = await Promise.resolve().then(() => require('@nx/rsbuild/generators'));
|
11
|
+
const initTask = await initGenerator(tree, {
|
12
|
+
skipPackageJson: options.skipPackageJson,
|
13
|
+
addPlugin: true,
|
14
|
+
skipFormat: true,
|
15
|
+
});
|
16
|
+
tasks.push(initTask);
|
17
|
+
}
|
18
|
+
async function setupRsbuildConfiguration(tree, options, tasks) {
|
19
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
20
|
+
const { configurationGenerator } = await Promise.resolve().then(() => require('@nx/rsbuild/generators'));
|
21
|
+
const { addBuildPlugin, addCopyAssets, addHtmlTemplatePath, addExperimentalSwcPlugin, versions, } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
22
|
+
const rsbuildTask = await configurationGenerator(tree, {
|
23
|
+
project: options.projectName,
|
24
|
+
entry: (0, maybe_js_1.maybeJs)({
|
25
|
+
js: options.js,
|
26
|
+
useJsx: true,
|
27
|
+
}, `./src/main.tsx`),
|
28
|
+
tsConfig: './tsconfig.app.json',
|
29
|
+
target: 'web',
|
30
|
+
devServerPort: options.devServerPort ?? 4200,
|
31
|
+
});
|
32
|
+
tasks.push(rsbuildTask);
|
33
|
+
const pathToConfigFile = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rsbuild.config.ts');
|
34
|
+
const deps = { '@rsbuild/plugin-react': versions.rsbuildPluginReactVersion };
|
35
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-react', 'pluginReact', options.style === '@emotion/styled'
|
36
|
+
? `swcReactOptions: {\n\timportSource: '@emotion/react',\n}`
|
37
|
+
: undefined);
|
38
|
+
if (options.style === 'scss') {
|
39
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-sass', 'pluginSass');
|
40
|
+
deps['@rsbuild/plugin-sass'] = versions.rsbuildPluginSassVersion;
|
41
|
+
}
|
42
|
+
else if (options.style === 'less') {
|
43
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-less', 'pluginLess');
|
44
|
+
deps['@rsbuild/plugin-less'] = versions.rsbuildPluginLessVersion;
|
45
|
+
}
|
46
|
+
else if (options.style === '@emotion/styled') {
|
47
|
+
deps['@swc/plugin-emotion'] = versions.rsbuildSwcPluginEmotionVersion;
|
48
|
+
addExperimentalSwcPlugin(tree, pathToConfigFile, '@swc/plugin-emotion');
|
49
|
+
}
|
50
|
+
else if (options.style === 'styled-jsx') {
|
51
|
+
deps['@swc/plugin-styled-jsx'] = versions.rsbuildSwcPluginStyledJsxVersion;
|
52
|
+
addExperimentalSwcPlugin(tree, pathToConfigFile, '@swc/plugin-styled-jsx');
|
53
|
+
}
|
54
|
+
else if (options.style === 'styled-components') {
|
55
|
+
deps['@rsbuild/plugin-styled-components'] =
|
56
|
+
versions.rsbuildPluginStyledComponentsVersion;
|
57
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-styled-components', 'pluginStyledComponents');
|
58
|
+
}
|
59
|
+
addHtmlTemplatePath(tree, pathToConfigFile, './src/index.html');
|
60
|
+
addCopyAssets(tree, pathToConfigFile, './src/assets');
|
61
|
+
addCopyAssets(tree, pathToConfigFile, './src/favicon.ico');
|
62
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, deps));
|
63
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
3
|
+
export declare function initRspack(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
4
|
+
export declare function setupRspackConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
5
|
+
export declare function handleStyledJsxForRspack(tasks: any[], tree: Tree, options: NormalizedSchema<Schema>): void;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.initRspack = initRspack;
|
4
|
+
exports.setupRspackConfiguration = setupRspackConfiguration;
|
5
|
+
exports.handleStyledJsxForRspack = handleStyledJsxForRspack;
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
7
|
+
const pc = require("picocolors");
|
8
|
+
const versions_1 = require("../../../../utils/versions");
|
9
|
+
const maybe_js_1 = require("../../../../utils/maybe-js");
|
10
|
+
async function initRspack(tree, options, tasks) {
|
11
|
+
const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
12
|
+
const rspackInitTask = await rspackInitGenerator(tree, {
|
13
|
+
...options,
|
14
|
+
addPlugin: false,
|
15
|
+
skipFormat: true,
|
16
|
+
});
|
17
|
+
tasks.push(rspackInitTask);
|
18
|
+
}
|
19
|
+
async function setupRspackConfiguration(tree, options, tasks) {
|
20
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
21
|
+
const rspackTask = await configurationGenerator(tree, {
|
22
|
+
project: options.projectName,
|
23
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
|
24
|
+
js: options.js,
|
25
|
+
useJsx: true,
|
26
|
+
}, `src/main.tsx`)),
|
27
|
+
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
28
|
+
target: 'web',
|
29
|
+
newProject: true,
|
30
|
+
framework: 'react',
|
31
|
+
});
|
32
|
+
tasks.push(rspackTask);
|
33
|
+
}
|
34
|
+
function handleStyledJsxForRspack(tasks, tree, options) {
|
35
|
+
devkit_1.logger.warn(`${pc.bold('styled-jsx')} is not supported by ${pc.bold('Rspack')}. We've added ${pc.bold('babel-loader')} to your project, but using babel will slow down your build.`);
|
36
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
|
37
|
+
tree.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
|
38
|
+
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
39
|
+
module.exports = composePlugins(withNx(), withReact(), (config) => {
|
40
|
+
config.module.rules.push({
|
41
|
+
test: /\\.[jt]sx$/i,
|
42
|
+
use: [
|
43
|
+
{
|
44
|
+
loader: 'babel-loader',
|
45
|
+
options: {
|
46
|
+
presets: ['@babel/preset-typescript'],
|
47
|
+
plugins: ['styled-jsx/babel'],
|
48
|
+
},
|
49
|
+
},
|
50
|
+
],
|
51
|
+
});
|
52
|
+
return config;
|
53
|
+
});
|
54
|
+
`);
|
55
|
+
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
3
|
+
export declare function setupViteConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
4
|
+
export declare function setupVitestConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.setupViteConfiguration = setupViteConfiguration;
|
4
|
+
exports.setupVitestConfiguration = setupVitestConfiguration;
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
6
|
+
const versions_1 = require("../../../../utils/versions");
|
7
|
+
async function setupViteConfiguration(tree, options, tasks) {
|
8
|
+
const { createOrEditViteConfig, viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
9
|
+
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
10
|
+
// See: https://vitejs.dev/guide/env-and-mode.html
|
11
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
|
12
|
+
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
|
13
|
+
}
|
14
|
+
const viteTask = await viteConfigurationGenerator(tree, {
|
15
|
+
uiFramework: 'react',
|
16
|
+
project: options.projectName,
|
17
|
+
newProject: true,
|
18
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
19
|
+
inSourceTests: options.inSourceTests,
|
20
|
+
compiler: options.compiler,
|
21
|
+
skipFormat: true,
|
22
|
+
addPlugin: options.addPlugin,
|
23
|
+
projectType: 'application',
|
24
|
+
});
|
25
|
+
tasks.push(viteTask);
|
26
|
+
createOrEditViteConfig(tree, {
|
27
|
+
project: options.projectName,
|
28
|
+
includeLib: false,
|
29
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
30
|
+
inSourceTests: options.inSourceTests,
|
31
|
+
rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
|
32
|
+
imports: [
|
33
|
+
options.compiler === 'swc'
|
34
|
+
? `import react from '@vitejs/plugin-react-swc'`
|
35
|
+
: `import react from '@vitejs/plugin-react'`,
|
36
|
+
],
|
37
|
+
plugins: ['react()'],
|
38
|
+
}, false);
|
39
|
+
}
|
40
|
+
async function setupVitestConfiguration(tree, options, tasks) {
|
41
|
+
const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
42
|
+
const vitestTask = await vitestGenerator(tree, {
|
43
|
+
uiFramework: 'react',
|
44
|
+
coverageProvider: 'v8',
|
45
|
+
project: options.projectName,
|
46
|
+
inSourceTests: options.inSourceTests,
|
47
|
+
skipFormat: true,
|
48
|
+
addPlugin: options.addPlugin,
|
49
|
+
});
|
50
|
+
tasks.push(vitestTask);
|
51
|
+
createOrEditViteConfig(tree, {
|
52
|
+
project: options.projectName,
|
53
|
+
includeLib: false,
|
54
|
+
includeVitest: true,
|
55
|
+
inSourceTests: options.inSourceTests,
|
56
|
+
rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
|
57
|
+
imports: [
|
58
|
+
options.compiler === 'swc'
|
59
|
+
? `import react from '@vitejs/plugin-react-swc'`
|
60
|
+
: `import react from '@vitejs/plugin-react'`,
|
61
|
+
],
|
62
|
+
plugins: ['react()'],
|
63
|
+
}, true);
|
64
|
+
if (options.bundler === 'rsbuild') {
|
65
|
+
tree.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'vite.config.ts'), (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'vitest.config.ts'));
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.initWebpack = initWebpack;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const versions_1 = require("../../../../utils/versions");
|
6
|
+
async function initWebpack(tree, options, tasks) {
|
7
|
+
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
8
|
+
const webpackInitTask = await webpackInitGenerator(tree, {
|
9
|
+
skipPackageJson: options.skipPackageJson,
|
10
|
+
skipFormat: true,
|
11
|
+
addPlugin: options.addPlugin,
|
12
|
+
});
|
13
|
+
tasks.push(webpackInitTask);
|
14
|
+
if (!options.skipPackageJson) {
|
15
|
+
const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
|
16
|
+
tasks.push(ensureDependencies(tree, { uiFramework: 'react' }));
|
17
|
+
}
|
18
|
+
}
|
@@ -124,6 +124,11 @@ async function createApplicationFiles(host, options) {
|
|
124
124
|
: null,
|
125
125
|
});
|
126
126
|
}
|
127
|
+
else if (options.bundler === 'rsbuild') {
|
128
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rsbuild'), options.appProjectRoot, {
|
129
|
+
...templateVariables,
|
130
|
+
});
|
131
|
+
}
|
127
132
|
if (options.unitTestRunner === 'none' ||
|
128
133
|
(options.unitTestRunner === 'vitest' && options.inSourceTests == true)) {
|
129
134
|
host.delete(`${options.appProjectRoot}/src/app/${options.fileName}.spec.tsx`);
|
@@ -23,7 +23,7 @@ export interface Schema {
|
|
23
23
|
devServerPort?: number;
|
24
24
|
skipPackageJson?: boolean;
|
25
25
|
rootProject?: boolean;
|
26
|
-
bundler?: 'webpack' | 'vite' | 'rspack';
|
26
|
+
bundler?: 'webpack' | 'vite' | 'rspack' | 'rsbuild';
|
27
27
|
minimal?: boolean;
|
28
28
|
// Internal options
|
29
29
|
addPlugin?: boolean;
|
@@ -101,7 +101,7 @@
|
|
101
101
|
"bundler": {
|
102
102
|
"description": "The bundler to use.",
|
103
103
|
"type": "string",
|
104
|
-
"enum": ["vite", "webpack", "rspack"],
|
104
|
+
"enum": ["vite", "webpack", "rspack", "rsbuild"],
|
105
105
|
"x-prompt": "Which bundler do you want to use to build the application?",
|
106
106
|
"default": "vite",
|
107
107
|
"x-priority": "important"
|
@@ -107,6 +107,7 @@ async function hostGenerator(host, schema) {
|
|
107
107
|
(0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host);
|
108
108
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { '@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion }, {
|
109
109
|
'@nx/web': versions_1.nxVersion,
|
110
|
+
'@nx/module-federation': versions_1.nxVersion,
|
110
111
|
});
|
111
112
|
tasks.push(installTask);
|
112
113
|
if (!options.skipFormat) {
|
@@ -21,7 +21,6 @@ const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
21
21
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
22
22
|
const set_defaults_1 = require("./lib/set-defaults");
|
23
23
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
24
|
-
const plugin_1 = require("@nx/js/src/utils/typescript/plugin");
|
25
24
|
async function libraryGenerator(host, schema) {
|
26
25
|
return await libraryGeneratorInternal(host, {
|
27
26
|
addPlugin: false,
|
@@ -117,11 +116,6 @@ async function libraryGeneratorInternal(host, schema) {
|
|
117
116
|
const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, options);
|
118
117
|
tasks.push(rollupTask);
|
119
118
|
}
|
120
|
-
else if (options.bundler === 'none' && options.addPlugin) {
|
121
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
122
|
-
(0, plugin_1.ensureProjectIsExcludedFromPluginRegistrations)(nxJson, options.projectRoot);
|
123
|
-
(0, devkit_1.updateNxJson)(host, nxJson);
|
124
|
-
}
|
125
119
|
// Set up test target
|
126
120
|
if (options.unitTestRunner === 'jest') {
|
127
121
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
@@ -217,6 +211,9 @@ async function libraryGeneratorInternal(host, schema) {
|
|
217
211
|
}, options.linter === 'eslint'
|
218
212
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
219
213
|
: undefined);
|
214
|
+
if (options.isUsingTsSolutionConfig) {
|
215
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
216
|
+
}
|
220
217
|
if (!options.skipFormat) {
|
221
218
|
await (0, devkit_1.formatFiles)(host);
|
222
219
|
}
|
@@ -126,6 +126,7 @@ async function remoteGenerator(host, schema) {
|
|
126
126
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
|
127
127
|
'@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion,
|
128
128
|
'@nx/web': versions_1.nxVersion,
|
129
|
+
'@nx/module-federation': versions_1.nxVersion,
|
129
130
|
});
|
130
131
|
tasks.push(installTask);
|
131
132
|
if (!options.skipFormat) {
|
@@ -4,6 +4,7 @@ exports.default = migrateWithMfImport;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
6
6
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
7
|
+
const versions_1 = require("../../utils/versions");
|
7
8
|
const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/react/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/react/module-federation]';
|
8
9
|
const NEW_IMPORT_PATH = `'@nx/module-federation/webpack'`;
|
9
10
|
async function migrateWithMfImport(tree) {
|
@@ -31,5 +32,10 @@ async function migrateWithMfImport(tree) {
|
|
31
32
|
tree.write(filePath, contents);
|
32
33
|
});
|
33
34
|
}
|
35
|
+
if (projects.size !== 0) {
|
36
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
37
|
+
'@nx/module-federation': versions_1.nxVersion,
|
38
|
+
});
|
39
|
+
}
|
34
40
|
await (0, devkit_1.formatFiles)(tree);
|
35
41
|
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = ensureMfPackage;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
6
|
+
const versions_1 = require("../../utils/versions");
|
7
|
+
async function ensureMfPackage(tree) {
|
8
|
+
const projects = new Set();
|
9
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/react:module-federation-dev-server', (options, project, target) => {
|
10
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
11
|
+
projects.add(projectConfig.root);
|
12
|
+
});
|
13
|
+
if (projects.size !== 0) {
|
14
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
15
|
+
'@nx/module-federation': versions_1.nxVersion,
|
16
|
+
});
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.hasRsbuildPlugin = hasRsbuildPlugin;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const versions_1 = require("./versions");
|
6
|
+
async function hasRsbuildPlugin(tree, projectPath) {
|
7
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
8
|
+
const { hasRsbuildPlugin } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
9
|
+
return hasRsbuildPlugin(tree, projectPath);
|
10
|
+
}
|