Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature : Configuration with babel config (.babelrc, ...)

See original GitHub issue

Would 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'

  snapshot: true,
  babelOptions: { filename: __filename },
  tests: [{
    code: `...`,
    babelOptions: {
      taggedTranslations: { someConfigIWantToTest: {} } // i add my config here 🚀

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

lucleraycommented, Sep 28, 2018

@kentcdodds That’s all I need, thanks !

kentcdoddscommented, Sep 28, 2018

I think you should be able to test this by mocking cosmiconfig like we do in our tests:

I 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found