react-webpack-generators / generator-react-webpack

Yeoman generator for ReactJS and Webpack
http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
MIT License
2.87k stars 356 forks source link

arrow function will throw syntax error #187

Closed tryer3000 closed 8 years ago

tryer3000 commented 8 years ago

first, I'm new to front-end, so this may not be a problem of this generator

arrow function fails to build.

Insert the following code into AppComponent

  xyz = () => { this.x = 2; };

This work in babel 5

tryer3000 commented 8 years ago

Well, I've just learnt that: It's a feature of es6 stage0.

StoneCypher commented 8 years ago

you probably just didn't install the babel presets, or something.

babel does implement arrow functions.

belal-mazlom commented 8 years ago

Check this page: http://jamesknelson.com/using-es6-in-the-browser-with-babel-6-and-webpack/ You need to add "stage-0" preset

module: {
  loaders: [
    {
      loader: "babel-loader",

      // Skip any files outside of your project's `src` directory
      include: [
        path.resolve(__dirname, "src"),
      ],

      // Only run `.js` and `.jsx` files through Babel
      test: /\.jsx?$/,

      // Options to configure babel with
      query: {
        plugins: ['transform-runtime'],
        presets: ['es2015', 'stage-0', 'react'],
      }
    },
  ]
}
weblogixx commented 8 years ago

Hi @belal-mazlom,

the article is kind of outdated. Arrow-Functions are currently supported in babel by using es2015. You can see the implementation details of the generator here (for the beta) or here for the current stable. Stage-0 is not needed to transform for arrow anymore. You can just add it to .babelrc.

StoneCypher commented 5 years ago

this issue has been closed for three years. please don't spam it with works for me.