loganfsmyth / babel-plugin-transform-decorators-legacy

A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5
MIT License
817 stars 57 forks source link

webpack.config.js need change #58

Closed CodePlayer7 closed 7 years ago

CodePlayer7 commented 7 years ago

decorators only work when adding plugins: [ 'transform-decorators-legacy' ] in jsx loader of webpack.config.js . Is it a must?if so, please add to the Usage Doc.

loganfsmyth commented 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.

CodePlayer7 commented 7 years ago

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.

borela commented 7 years ago

@CallMeXYZ I am defining the babel settings in my package.json without any issues; here's my loader settings.

mezod commented 7 years ago

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.

loganfsmyth commented 7 years ago

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.

mezod commented 7 years ago

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.

loganfsmyth commented 7 years ago

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.

mezod commented 7 years ago

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!