Closed CodePlayer7 closed 7 years ago
If you have a specific PR in mind, I'd be happy to review it, but there are a massive number of ways to configure Babel depending on how you are using it. The README does includes an example using a .babelrc
which will also work with Webpack. Babel's docs and babel-loader
are generally the best places to look for docs around those things.
After using a .babelrc
config by following the usage example, webpack.config.js
still need to be configed in my case. As the usage only has few words and talks nothing about other config,whether this would be a note in usage section for beginners like me.
@CallMeXYZ I am defining the babel settings in my package.json without any issues; here's my loader settings.
I'm not sure if I understood OP correctly but I think I have the same issue:
If I config babel-plugin-transform-decorators-legacy using the .babelrc config, as suggested in the readme I get the full error:
ERROR in ./app/src/components/Menu/Menu.jsx
Module build failed: SyntaxError: Decorators are not officially supported yet in 6.x pending a proposal update.
However, if you need to use them you can install the legacy decorators transform with:
npm install babel-plugin-transform-decorators-legacy --save-dev
and add the following line to your .babelrc file:
{
"plugins": ["transform-decorators-legacy"]
}
The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy.
which is exactly what I've already done.
However, if I instead add the plugin to my loader in webpack:
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
plugins: ['transform-decorators-legacy'],
presets: ['es2015', 'es2017', 'stage-0', 'react'],
},
},
I don't get the error.
The .babelrc
suggestion is standard because that is the usual place people put their config. If your other presets are configured as part of the loader, you'd also want to put the plugin there.
I understand/agree. My point was that for some reason, when doing it in .babelrc the error pops up whilst putting it on the webpack config file doesn't.
When you say you put it in the .babelrc
, you mean you configured the plugin there, but the presets were configured in the webpack.config.js
?
If so, the issue is that it would load the plugins in the wrong order if you do that.
That'd make a lot of sense. I'm not 100% if this is the answer to OP? Maybe you can close this issue :) thanks!
decorators only work when adding
plugins: [ 'transform-decorators-legacy' ]
in jsx loader ofwebpack.config.js
. Is it a must?if so, please add to the Usage Doc.