Auto import fbt in babel plugin
See original GitHub issueš Feature Proposal
Add support to auto import fbt
in the babel plugin. Similar to how the new react automatic runtime feature in @babel/plugin-transform-react-jsx
Motivation
Personally I often forget to import fbt
until the compilation fails, making this automatic would improve the DX for at least me.
This would also fix use with āorganize importsā in VS Code, where it removed the fbt
import since it canāt see itās being used.
Example
// input
function App() {
return (
<fbt desc="lorem text">Lorem ipsum dolor</fbt>
)
}
// output
import fbt from 'fbt'
function App() {
return (
<fbt desc="lorem text">Lorem ipsum dolor</fbt>
)
}
Pitch
It makes sense for this feature to be in the core babel plugin, I guess itās possible to create a custom plugin but then you need to be careful about ordering etc
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
babel-plugin-fbt-import - npm
A babel plugin to automatically import `fbt`. ... Start using babel-plugin-fbt-import in your project by running `npm i babel-plugin-fbt-import`.
Read more >babel/preset-react
automatic auto imports the functions that JSX transpiles to. classic does not automatic import anything. development. boolean , defaults to false .
Read more >Enumerations | FBT - Meta Open Source
and fbt.enum` both provide the ability to add your ad-hoc or ... manifest that makes them available to the babel-plugin-fbt at "build-time".
Read more >babel-plugin-auto-import examples - CodeSandbox
Learn how to use babel-plugin-auto-import by viewing and forking example apps that make use of babel-plugin-auto-import on CodeSandbox.
Read more >How to add support Typescript for FBT an internationalization ...
import * as React from "react"; import fbt from "fbt"; ... And when you combine @babel/preset-typescript + babel-plugin-fbt you will beĀ ...
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
Created a stand-alone plugin for now, if it works out well I might create a PR sometime in the future
Iāve published the code as
babel-plugin-fbt-import
on npm now, and code can be found here https://github.com/alexandernanberg/babel-plugin-fbt-import