Home  >  Q&A  >  body text

javascript - Webpack configures es6 and some syntactic sugars are not recognized.

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_leeringa_lee2663 days ago914

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-07-05 10:54:45

    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.

    reply
    0
  • 滿天的星座

    滿天的星座2017-07-05 10:54:45

    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.

    reply
    0
  • Cancelreply