Webpack默认参数es6

时间:2017-03-17 12:40:59

标签: webpack ecmascript-6

我无法使用webpack转换es6默认参数 我目前的设置是:

var path    = require('path');
var webpack = require('webpack');

module.exports = {
    entry: ["./main.js"],
    output: { path: __dirname, filename: './bundle.js'},
    resolve: {
      modules: [path.resolve('../js'), path.resolve('../js/node_modules')],
      extensions: ['*', '.ts', '.js', '.jsx', '.es6']
    },
    module: {
        loaders: [
            { test: /\.json$/, loader: 'json-loader' },
            {
                test: /(\.jsx?$|\.es6?$)/,
                loader: 'babel-loader',
                query: {
                    babelrc: false,
                    plugins: [
                      'transform-es2015-arrow-functions',
                      'transform-es2015-block-scoping'
                    ],
                    presets: ['es2016', 'react']
                },
            }
        ]
    },
    plugins: [
      new webpack.DefinePlugin({
          'process.env.NODE_ENV': JSON.stringify('development')
      }),
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': '"development"',
        'global': {}, // bizarre lodash(?) webpack workaround
        'global.GENTLY': false // superagent client fix
    })
    ],
    target: "node"
};

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要将参数transform plugins添加到babel

plugins: [
    'transform-es2015-arrow-functions',
    'transform-es2015-block-scoping',
    'transform-es2015-parameters'
],

请参阅documentation