-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react): remove unnecessary dependencies from @nrwl/react #13525
Conversation
Nx Cloud ReportCI is running for commit 7555360. 📂 Click to track the progress, see the status, the terminal output, and the build insights. Sent with 💌 from NxCloud. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
c92f1db
to
ca12017
Compare
ca12017
to
7a2a9b7
Compare
7a2a9b7
to
8c18195
Compare
8c18195
to
b59f9c1
Compare
b59f9c1
to
caf1afa
Compare
caf1afa
to
6943ee0
Compare
6943ee0
to
40fec3e
Compare
40fec3e
to
6d9c86d
Compare
6d9c86d
to
9f51314
Compare
9f51314
to
0fc9031
Compare
0fc9031
to
80913b7
Compare
80913b7
to
258dc7b
Compare
1b186cf
to
2fb2466
Compare
2fb2466
to
7555360
Compare
7555360
to
3dc0c58
Compare
3dc0c58
to
919ff13
Compare
- If Vite is used, then Webpack and Jest are not needed - If e2e is not used, then Cypress is not needed - Trims down on the amount of packages that are downloaded
919ff13
to
53813a2
Compare
@@ -18,6 +18,12 @@ | |||
"description": "Init Webpack Plugin.", | |||
"type": "object", | |||
"properties": { | |||
"uiFramework": { | |||
"type": "string", | |||
"description": "UI Framework to use for Vite.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Please fix this in a follow up PR.
import { tsquery } from '@phenomnomnominal/tsquery'; | ||
|
||
export default async function eslint8Updates(tree: Tree) { | ||
try { | ||
const { addPropertyToJestConfig } = await import('@nrwl/jest'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have ensurePackage
?
|
||
/** | ||
* Don't run actual child_process implementation of installPackagesTask() | ||
*/ | ||
jest.mock('child_process'); | ||
// jest.mock('child_process'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm
@@ -66,22 +67,54 @@ function updateDependencies(host: Tree, schema: InitSchema) { | |||
}); | |||
} | |||
|
|||
function initRootBabelConfig(tree: Tree, schema: InitSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here? @mandarini just made a shared one in @nrwl/js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it in master, can be addresses later.
{ | ||
'@pmmmwh/react-refresh-webpack-plugin': | ||
reactRefreshWebpackPluginVersion, | ||
'@phenomnomnominal/tsquery': tsQueryVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this related to webpack?
|
||
// React apps | ||
export const reactRefreshWebpackPluginVersion = '^0.5.7'; | ||
export const tsQueryVersion = '4.1.1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this related to webpack?
I am seeing some odd behavior in after upgrading, I needed to add the following modules in order to get
I will file a bug report later; just wanted to give a quick heads up in case it helps. |
Also noticed issues and had to add |
Same issue here had to |
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
This PR removes packages such as
@nrwl/webpack
and@nrwl/cypress
as dependencies from@nrwl/react
. The goal is to avoid installing things that are not needed. For example, if vite is used then webpack should not be installed. Same thing for vitest replacing jest.Technical details
To make sure we can still use other generators inside any generator (such as
webpackInitGenerator
from@nrwl/webpack
), a new utility function is added to@nrwl/devkit
:ensurePackage
.This function takes a package and an expected version, and checks to make sure it is already installed in the workspace.
If the package is not found, then one of two things happens:
--dryRun
, thenthrowOnMissing
is set totrue
and an error is thrown with a message likeRequired package <pkg>@<version> is missing. Run npm install -D <pkg>@<version>, and then try again.
--dryRun
then the missing package is installed before continuing with the rest of the invoking generator. This will be the common case, for example when runningcreate-nx-workspace
.Results / Comparisons
A normal React+Vite workspace using
--preset=react-standalone
will result in 365MB ofnode_modules
prior to this change. After this change we end up with 259MB ofnode_modules
, or a 106MB reduction in size.A plain vite project created via
npm create vite
(select React and TypeScript), then adding the following packages:In that plain vite setup,
node_modules
is 151MB in size. There are still some improvements we can make (such as removingrxjs
), but that is out of scope for this PR.If you add the eslint plugins, then the vite project goes to 208MB in size:
If you bring in the nx-specific packages, that's another 39MB for a total 247MB (or a 12 MB difference from our
react-standalone
preset):Other notes
@nrwl/react
now relies fully on vite/webpack/jest/cypress init generators to install the necessary packages.uiFramework
option to webpack init generator, same option already supported in cypress and storybook.AsyncIterable
helpers from@nrwl/js
have been moved to@nrwl/devkit
so we can remove the JS dependency from@nrwl/react
.