javascript - Webpack configures es6 and some syntactic sugars are not recognized.
ringa_lee
ringa_lee 2017-07-05 10:52:45
0
2
957

Use webpack to configure es6. Most of the syntax is supported, but... this one cannot pass compilation

{
            test: /\.js$/,
            exclude: /node_modules/, 
            loader: 'babel-loader',
            options: {
                presets:['es2015','react']
            }
        },

Has anyone encountered similar problems?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
淡淡烟草味

First add the corresponding plugin in .babelrc, for example:

{
  "presets": [
    ["es2015", { "modules": false }]
  ],
  "plugins": ["transform-object-rest-spread"]
}

Then install babel-plugin-transform-object-rest-spread via NPM.

滿天的星座

Tips, each preset of Babel has different support for new syntax. The es2015 preset only supports the es syntax officially approved in 2015. The details can be viewed here. It is recommended to use env preset.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template