0

I'm setting up a React environment with NPM for dependencies, Webpack for bundling and Babel to be able to code ES6. I want to be able to use ES6 everywhere on my project.

I have my webpack.config.js file setup to use 'babel-loader' as follows:

var webpack = require ('webpack')
var path = require ('path')
var DIST_DIR = path.resolve(__dirname, 'dist')
var SRC_DIR = path.resolve(__dirname, 'src')

module.exports = {
    entry:  SRC_DIR + '/app/index.js',
    output: {
        path: DIST_DIR + '/app',
        filename: 'bundle.js',
        publicPath: '/app/'
    },
    module: {
        loaders: [
            {
                test: /\.jsx?/,
                include: SRC_DIR,
                loader: 'babel-loader',
                query: {
                    presets: [ 'react', 'es2015', 'stage-2' ]
                }
            }
        ]
    }
}

Everything works as expected, But this file (webpack.config.js) is not written in ES6!

Is it possible to be able to use ES6 all along my project? If yes, where do I have to setup Babel and its presets?

Note: I'm using node v6.10.2

Agu Dondo
  • 12,638
  • 7
  • 57
  • 68
  • My question is more general, I would like to use it everywhere in the project, not specifically on webpack.config.js – Agu Dondo May 03 '17 at 19:53
  • 1
    `const` looks like ES6 to me... – Felix Kling May 03 '17 at 19:53
  • @AguDondo Then what do you mean? What else do you want to write in ES6 that you can't with this setup? Did you google first? – Andrew Li May 03 '17 at 19:54
  • *"But this file (webpack.config.js) is not written in ES6!"* You can use all the ES6 features that v6.10 supports. Or upgrade to a later version for even more compatibility. I'm also not sure what exactly you would turn to ES6 here, expect the `var` that you already had as `const`. – Felix Kling May 03 '17 at 20:59

0 Answers0