2

I have started with webpack today and I'm having some problems to get it running.

Basically I need an application using react & es6. Bellow you can see the error:

Error

webpack.config.js

var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './app/app.js',
  output: {
    path: 'dist',
    filename: 'bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        query: {
          stage: 0
        },
        include: __dirname + '/app'
      },
    ]
  },
  plugins: [new HtmlWebpackPlugin({
    template: __dirname + '/app/index.html',
    hash: true,
    filename: 'index.html',
    inject: 'body'
  })]
};

so far what I have tried is install es2015 and configured as

{
    test: /\.jsx?$/,
    loader: 'babel-loader',
    exclude: /node_modules/,
    query: {
        presets: ['es2015']
    }
}

but I still getting the same error.

Any idea how can I fix it?

Dependencies

"dependencies": {
    "react": "^0.14.0",
    "react-dom": "^0.14.2",
    "react-redux": "^4.0.0",
    "webpack-dev-server": "^1.12.1"
  },
  "devDependencies": {
    "babel-loader": "^5.3.2",
    "history": "^1.13.0",
    "html-webpack-plugin": "^1.6.2",
    "webpack": "^1.12.2"
  }
gon250
  • 3,405
  • 6
  • 44
  • 75
  • What version of babel are you using? – Dominic Nov 26 '15 at 12:23
  • @DominicTobias I have updated the question adding the dependencies I have in my `package.json` – gon250 Nov 26 '15 at 12:30
  • Look throug it [**_Link_**](http://stackoverflow.com/questions/33779162/how-to-get-reactjs-to-integrate-with-webpack/33779337#33779337). In this case you nee babel-presets like es6 and react and also babel-core npm module –  Nov 26 '15 at 12:33

1 Answers1

2
  1.  npm i babel-core babel-loader babel-preset-es2015 babel-preset-react --save-dev

webpack.config.js should look like this one:

module.exports = {
  //.. some stuff before
  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loaders: ["babel"],
      query: { 
        presets: ['es2015','react'] // here you can add your stage-0 preset
      }
    }]
  }
  //.. some stuff after
}

If you would like to use babel-stage-0 you have to install it throug npm and include stage-0 into `presets' .

And also possible you will find some useful infomation oj this Link

Thanks!