Skip to content
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(js): do not generate root babel.config.json for babel projects #17289

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented May 29, 2023

This PR ensures that babel.config.json is not generated in new projects. The default behavior is to only apply .babelrc file for individual projects and ignore its dependencies' .babelrc files. The implication of not using rootMode: upward is that any babel presets/plugins needed by a a dependency also needs to be added to the dependent project's .babelrc file.

Additionally, anywhere that we can safely swap to SWC instead of Babel we will do so by default.

Notes

  • Both @nx/node and @nx/express do not support building projects using Babel, so the babelJest option is deprecated and swcJest is added to generate Jest project with @swc/jest (to speed up test compile).
  • React still needs Babel by default if using styled-components or emotion. Will address it in a separate PR.

@vercel
Copy link

vercel bot commented May 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2023 6:08pm

@@ -71,36 +71,6 @@ export async function libraryGenerator(host: Tree, rawOptions: Schema) {
);
addTsConfigPath(host, `${options.importPath}/server`, [serverEntryPath]);

updateJson(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never worked well, and the user should already have emotion and styled-components in the app. As per this PR (#17286) the app's babel config will now be applied to the libs as well. You never want to be in a situation where different styling solutions are used between apps and libs without a build step in the lib to normalize to CSS or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a follow-up PR to enable emotion and styled-components in SWC for Next.js since they've added some early support for them.

if (host.exists(joinPathFragments(options.projectRoot, '.babelrc'))) {
host.delete(joinPathFragments(options.projectRoot, '.babelrc'));
}
if (options.compiler === 'babel') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined the .babelrc creation here rather than in the files folder.

@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch 2 times, most recently from 0879035 to dd012fc Compare May 29, 2023 17:45
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from dd012fc to e436e39 Compare May 29, 2023 17:58
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from e436e39 to bfaadf5 Compare May 29, 2023 18:01
@jaysoo jaysoo marked this pull request as ready for review May 29, 2023 18:01
@jaysoo jaysoo requested review from a team as code owners May 29, 2023 18:01
@jaysoo jaysoo requested review from AgentEnder, isaacplmann and ndcunningham and removed request for AgentEnder May 29, 2023 18:01
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from bfaadf5 to 6d2265e Compare May 29, 2023 19:36
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from 6d2265e to 5db0408 Compare May 29, 2023 20:03
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from e776a20 to ba5ad48 Compare May 31, 2023 01:22
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from ba5ad48 to 75f4ac9 Compare June 5, 2023 18:56
@jaysoo jaysoo changed the title feat(web): update Next.js, Web, and Node generators to not use Babel by default feat(js): do not generate root babel.config.json for babel projects Jun 5, 2023
@@ -138,7 +138,7 @@
"type": "string",
"description": "The compiler to use",
"enum": ["babel", "swc"],
"default": "babel"
"default": "swc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be babel as well?

@@ -143,7 +143,7 @@
"type": "string",
"description": "The compiler to use.",
"enum": ["babel", "swc"],
"default": "babel"
"default": "swc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be babel

- Project will only use its .babelrc and ignore .babelrc of other projects (e.g. other libs)
- For prevous behavior user can set `babelUpwardRootMode: true` for @nx/webpack:webpack or @nx/rollup:rollup executors
@jaysoo jaysoo force-pushed the feat/do-not-use-babel-by-default branch from a09425d to b0a7cf5 Compare June 6, 2023 18:05
@jaysoo jaysoo merged commit 08339ee into nrwl:master Jun 6, 2023
@jaysoo jaysoo deleted the feat/do-not-use-babel-by-default branch June 6, 2023 19:45
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants