akameco / extract-react-intl Goto Github PK
View Code? Open in Web Editor NEWExtract react-intl messages
License: MIT License
Extract react-intl messages
License: MIT License
node
version: 8.9.3npm
(or yarn
) version: yarn 1.3.2Do you want to request a feature or report a bug?:
Suggest a feature
What is the current behavior?:
Since extract-react-intl
pushes babel-plugin-react-intl
into the plugins list, it will be executed ahead of any user configured babel presets.
So if I have a preset:
// my-preset.js
{
"presets": ["env", "stage-3"],
"plugins": ["react-intl-auto"]
}
and I use that in my projects .babelrc
:
//.babelrc
{
presets: ["my-preset"]
}
then because of this line:
plugins.push(require('babel-plugin-react-intl').default)
The following are the options passed to transformFile
inside extract-react-intl
:
{
presets: ['/some/path/to/my-preset.js'],
plugins: ['/some/path/to/babel-plugin-react-intl/index.js'],
}
Babel prioritizes plugins in the top level config BEFORE plugins in any presets.
The result in my case above is that babel-plugin-react-intl
is called BEFORE babel-plugin-react-intl-auto
which is problematic.
If I had the following .babelrc
file it will work because the plugins aren't in a preset:
//.babelrc
{
presets: ["my-preset"],
plugins: ["react-intl-auto"],
}
What is the expected desired behavior?:
I'd love to find a way for all the user's babel
config/presets/plugins to be run before babel-plugin-react-intl
so that I don't have to worry about the order of my own babel config to make this tool work.
Suggested solution:
If you were to unshift babel-plugin-react-intl
into the presets instead of plugins, it'd make it lower in the execution order for babel:
- plugins.push(require('babel-plugin-react-intl').default)
+ presets.unshift({ plugins: [require('babel-plugin-react-intl').default] })
node
version: 8.11npm
(or yarn
) version: yarnDo you want to request a feature or report a bug?:
Bug
What is the current behavior?:
$ extract-messages -l=source -o server/lang -d source --flat 'src/**/!(*.test).js'
Error: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
at assertNoDuplicates (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-descriptors.js:205:13)
at createDescriptors (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-descriptors.js:114:3)
at createPluginDescriptors (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at alias (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-descriptors.js:63:49)
at cachedFunction (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/caching.js:33:19)
at plugins.plugins (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-chain.js:319:26)
at /Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/config-chain.js:68:29)
at loadPrivatePartialConfig (/Users/stevenlangbroek/Code/ec_portal/node_modules/@babel/core/lib/config/partial.js:85:55)
error Command failed with exit code 1.
What is the expected behavior?:
We're running babel 7 in our project, so I followed the instruction re: babel-core@bridge
. Unfortunately the error still persists. I added some logging, and name
in the assertNoDuplicated
function is empty (these are added to a map to verify lack of duplication).
Suggested solution:
I'm not sure why it's still using "@babel/core" instead of babel-core
, despite babel-core@bridge
being installed. Any thoughts>
Do you want to request a feature or report a bug?:
Feature
What is the expected behavior?:
I have a case where I've wrapped react-intl with my own module with some custom functions and components to manage internationalization. I don't want the need to import some elements from it and some from react-intl. I prefer to use just one source. I've mentioned it in this issue.
babel-plugin-react-intl accepts few options to manipulate extracting process. With extract-react-intl context, most of them are not so helpful (especially if we assume using it with by extract-react-intl-messages), but one is. I mean moduleSourceName which lets plugin to know from where defineMessages
or <FormattedMessage />
is imported. Of course, default is react-intl
but in some cases one may want to use custom module.
Suggested solution:
It would be great to be able to pass custom module name to extract-react-intl which can forward it to babel-plugin-react-intl (I've tested it locally, simply by explicitly adding options to unshifted preset in the source code and it works).
Same thing would fit extract-react-intl-messages.
@akameco, I can try to manage some changes if you want (but never done that on someones github repo ๐ ).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.