-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Expose Babel config for Gatsby #6170
Comments
oh yeah, just noticed this when I was working with Jest tests on a Gatsby site. I wondered if my babelrc I created for Jest was basically duping something Webpack is already doing? |
Related #5824
|
Yeah, I think it makes sense expose it as a preset so it's really easy to configure with tooling. I hit issues with Storybook as well. |
Yeah, same here. Some tools require babel-config available like babel-plugin-react-intl. The same if I wanted to create my own tool that relies on babel and I don't necessarily want it in my build system (by extending webpack config). I see that most of examples and even documentation suggests copying specific presets and plugins. But this is less than optimal and more like a workaround I believe. It will make harder to migrate app to newer versions. Specifying packages in config that are not installed explicitly by user is also fragile I think. What I would ideally see is something like they do in NextJS. If you want a custom .babelrc you create a file with a nextjs preset which has all that is necessary to work by a framework: .babelrc
|
Agreed, this would be super useful! Setting up Jest in my project has been a pain and this would help streamline things while also being more explicit about what is happening behind the scenes. 👍 |
V2 is being released shortly and there are a lot of new docs that explain how to set up jest for testing! I would recommend going that route as we experimented with exposing config but it actually becomes harder to work with as you can't get the babel config until |
@kkemple I have to say I still find the docs confusing. It's unclear what approach should be taken if we just want to add a babel plugin. The old recommendation was to copy Gatsby's |
@kkemple I echo the concern brought up by @Undistraction. |
@Undistraction do you want to add the babel plugin to your testing config or to gatsby's build itself? If for testing you would add that to the jest-preprocessor config you create, if for gatsby itself you would use the babel config API. The reason exposing the actual babel config is difficult is because of the plugin architecture. Any plugin can modify that config, so in order to get a proper babel config you would have to run develop or build to first get all plugins and config bootstrapped then print out the babelrc file. The other issue this opens up that in babel 7 a babelrc file at root of project will be read in by gatsby, so if you add a plugin to your now printed babelrc file then gatsby will use it during builds. If you still want to print it out you can do something very similar to this plugin. |
Love this issue. I'll provide some context if someone wants to grab this for Hacktoberfest or honestly, just in general. SummaryExpose an NPM package Detail
As always, feel free to reach out to any of us on the Gatsby team for more assistance and detail 😄 🎉 |
This PR adds `babel-preset-gatsby`, a new package that exposes our babel config as a handy preset that we can re-use in all our internal packages as well as in public packages. I've added a new option, `targets`, to overwrite the preset-env targets. You can see the changes in the updated Babel documentation. In gatsbyjs#6170, @DSchau mentioned that we want to replace [`babel-loader-helpers`][] with this preset as well (eventually). I'm not really sure what this helper is doing right now so I decided to not touch it. It seems like the helper is used for users of Gatsby. I'm thinking now that my changes to the Babel documentation article should not be made until we also upgrade the above helper to use our preset (e.g. the helper adds `babel-plugin-macros` which is not used in our internal preset). Let me know if I should revert my changes to the article. There are a few other guides that explain a custom babel config. Should I update them as well (test-css-in-js and unit-testing)? [`babel-loader-helpers`]: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/babel-loader-helpers.js
Part of #6170 This PR adds `babel-preset-gatsby`, a new package that exposes our babel config as a handy preset that we can re-use in all our internal packages as well as in public packages. I've added a new option, `targets`, to overwrite the preset-env targets. You can see the changes in the updated Babel documentation. In #6170, @DSchau mentioned that we want to replace [`babel-loader-helpers`][] with this preset as well (eventually). I'm not really sure what this helper is doing right now so I decided to not touch it. It seems like the helper is used for users of Gatsby. I'm thinking now that my changes to the Babel documentation article should not be made until we also upgrade the above helper to use our preset (e.g. the helper adds `babel-plugin-macros` which is not used in our internal preset). Let me know if I should revert my changes to the article. There are a few other guides that explain a custom babel config. Should I update them as well (test-css-in-js and unit-testing)? [`babel-loader-helpers`]: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/babel-loader-helpers.js
Closed in #8724 |
Part of gatsbyjs#6170 This PR adds `babel-preset-gatsby`, a new package that exposes our babel config as a handy preset that we can re-use in all our internal packages as well as in public packages. I've added a new option, `targets`, to overwrite the preset-env targets. You can see the changes in the updated Babel documentation. In gatsbyjs#6170, @DSchau mentioned that we want to replace [`babel-loader-helpers`][] with this preset as well (eventually). I'm not really sure what this helper is doing right now so I decided to not touch it. It seems like the helper is used for users of Gatsby. I'm thinking now that my changes to the Babel documentation article should not be made until we also upgrade the above helper to use our preset (e.g. the helper adds `babel-plugin-macros` which is not used in our internal preset). Let me know if I should revert my changes to the article. There are a few other guides that explain a custom babel config. Should I update them as well (test-css-in-js and unit-testing)? [`babel-loader-helpers`]: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/babel-loader-helpers.js
Part of gatsbyjs#6170 This PR adds `babel-preset-gatsby`, a new package that exposes our babel config as a handy preset that we can re-use in all our internal packages as well as in public packages. I've added a new option, `targets`, to overwrite the preset-env targets. You can see the changes in the updated Babel documentation. In gatsbyjs#6170, @DSchau mentioned that we want to replace [`babel-loader-helpers`][] with this preset as well (eventually). I'm not really sure what this helper is doing right now so I decided to not touch it. It seems like the helper is used for users of Gatsby. I'm thinking now that my changes to the Babel documentation article should not be made until we also upgrade the above helper to use our preset (e.g. the helper adds `babel-plugin-macros` which is not used in our internal preset). Let me know if I should revert my changes to the article. There are a few other guides that explain a custom babel config. Should I update them as well (test-css-in-js and unit-testing)? [`babel-loader-helpers`]: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/babel-loader-helpers.js
Summary
Exposing Gatsby's Babel configuration would allow Gatsby apps to integrate with 3rd party tooling like linters and testing frameworks. There are two options for accomplishing this, making Gatsby's config a babel preset, or printing a .babelrc file in root of project (or somewhere else).
Motivation
Currently getting testing or linting configuration requires essentially copying what Gatsby does into your own
.babelrc
file, at this point it would be much cleaner and easier on the user to just install and includebabel-preset-gatsby
.The text was updated successfully, but these errors were encountered: