-
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
Make computed Babel configuration accessible in Node API #10753
Comments
This should be easy to do I think since we already have the applied config in redux. @pieh can confirm this |
@silvenon this is a bit more advanced but have you tried https://www.gatsbyjs.org/docs/add-custom-webpack-config/#modifying-the-babel-loader I'm unsure what the best practices are here and that we even want to expose babelConfig. maybe @pieh or @DSchau can help. |
@wardpeet yes, that's how I was planning to modify the webpack configuration to add another loader after babel-loader, but I need to pass the computed Babel configuration object to that loader as options. Did I understand you correctly? |
@silvenon From the documentation page that @wardpeet linked to
This is evaluate down to
Adding anything else inside the object where If I understand your use case correctly, your plugin should be able to add its overrides here |
AFAIK, exports.onCreateWebpackConfig = ({ rules, getBabelConfig }) => {
const jsRule = rules.js();
const jsRuleWithMyLoader = {
...jsRule,
use: [
...jsRule.use,
{
loader: 'my-loader',
options: {
babelConfig: getBabelConfig(),
}
},
],
};
// ...merge with the webpack config...
} If I leave this option blank, Sorry if I'm not getting it, can you show me what I can do to point my plugin to the right direction? |
Btw, exposing this config might also be a good step toward making it accessible to babel-eslint and babel-jest, without having to replicate changes made by Gatsby plugins in |
That's ok 😄 This is open source, there are no expectations, I'm happy that you're considering it at all. 😉 |
We're happy to help you giving pointers on where to get started 😄 |
If I catch some time and dive into it, I'll ask questions then. 😄 |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
You're right, gatsbot, no need to keep this open. I'll submit a PR when or if I get around to it. |
Summary
It would be very useful to be able to access Gatsby's computed Babel configuration in the Node API, especially when developing plugins.
Basic example
To make the final API consistent it would probably have to be a breaking change because
getConfig
inonCreateWebpackConfig
would need to becomegetWebpackConfig
, but a non-breaking version of the API might look like this:Motivation
I'm building a plugin which consists of a Babel preset and a webpack loader. The webpack loader is looking for the project's Babel configuration, but instead I want to pass it Gatsby's computed Babel configuration, so that people using my plugin don't have to create a custom Babel configuration on their own to make my Gatsby plugin work.
The text was updated successfully, but these errors were encountered: