question-mark
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.

Support options to babel-macro

See original GitHub issue

Problem

import t from 'tagged-translations/macro';

const name = 'Vinh Le';

t`Hello ${name}`;

This is my use case that I need to have some configurations. It could be the location of the translation file.

The current version has no way to do this. We might need to configure these options globally.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Sep 8, 2017

Hey @vinhlh! 👋

I can think of a few ways to do this.

Probably the best is to use cosmiconfig and in your plugin you search for the relevant config based on the file (which you can find from the state object. I think that would be pretty straightforward.

Alternatively, you could do:

import t from 'tagged-translations/macro';

t.config({
  // some literal
})

const name = 'Vinh Le';

t`Hello ${name}`;

And you could use it in your macro as well. That’s what I had in mind for some sort of config solution.

I don’t think that I want to expose a way to configure individual macros via the babel-macros config in .babelrc because that could get unwieldy. I think my suggestion is a pretty good solution. So I’ll go ahead and close it. But feel free to continue dialog and if we decide that babel-macros could do something better to support this use case then we can reopen the issue.

Thanks a bunch!

Oh, and don’t forget to upgrade to 1.0.0!

0reactions
kentcdoddscommented, Oct 15, 2017

Ok, the PR is ready. I want at least one review before I merge it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Zero-config code transformation with babel-plugin-macros
Introducing babel-plugin-macros. Guess what! A tool like this exists! babel-plugin-macros is a new Babel plugin that allows you to do exactly ...
Read more >
Babel macros | Tan Li Hau
In this article, I am going to talk about Babel macros. ... Meaning the support that a new developer to the team can...
Read more >
How to use the babel-plugin-macros.createMacro function in ...
To help you get started, we've selected a few babel-plugin-macros.createMacro examples, based on popular ways it is used in public projects.
Read more >
How to use Babel macros with React Native - freeCodeCamp
Now, along with the polyfill, I also needed to import all the supporting locale files. There are two options here: Load all the...
Read more >
babel-macros - npm
babel -macros has been renamed to babel-plugin-macros. Please use that package instead. babel-macros. 2.0.0 • Public ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found