Feature : Configuration with babel config (.babelrc, ...)
See original GitHub issueWould it be possible to configure macros directly with the babel config (.babelrc or other babel config) :
// .babelrc
{
"plugins": ["macros", {
"taggedTranslations": {
"someConfig": {}
}
}]
}
Then you get it like this in the macro :
const { createMacro } = require('babel-plugin-macros')
const configName = 'taggedTranslations'
module.exports = createMacro(taggedTranslationsMacro, { configName })
function taggedTranslationsMacro({references, state, babel, config}) {
// config is { someConfig: {} }
}
This way, it’s easier to test a specific config :
import pluginTester from 'babel-plugin-tester'
import plugin from 'babel-plugin-macros'
pluginTester({
plugin,
snapshot: true,
babelOptions: { filename: __filename },
tests: [{
code: `...`,
babelOptions: {
taggedTranslations: { someConfigIWantToTest: {} } // i add my config here 🚀
}
}],
})
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). ... Check out the...
Read more >When to use babel.config.js and .babelrc - Stack Overflow
I found two ways to configure Babel: by creating babel.config.js and .babelrc file. Under what circumstances should we prefer one config file ...
Read more >Advanced Features: Customizing Babel Config - Next.js
To start, you only need to define a .babelrc file (or babel.config.js ) at the top of your app. If such a file...
Read more >Babel.js Guide -Part 1- The Absolute Must-Know Basics
For simple configs, .babelrc is used. babelrc is a JSON5 file (like JSON where comments are allowed and sometimes recommended) that when put...
Read more >Babel - Storybook
Here are some key features of Storybook's Babel configurations. ... If your project has a .babelrc file, we'll use that instead of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kentcdodds That’s all I need, thanks !
I think you should be able to test this by mocking
cosmiconfig
like we do in our tests: https://github.com/kentcdodds/babel-plugin-macros/blob/1785a0fab2c374d1505c49cff1bd38fd541819e2/src/__tests__/index.js#L255-L306I don’t want to have two ways to do the same thing and I’m still not convinced that config is a good thing for macros anyway.
In any case, I don’t think we’ll be doing anything with this issue (unless you’d like to document an example of how to test this situation). Thanks!