9

I want to compile my code to ES6 not ES5. Here is my babelrc.

{
"presets": [
    [
        "env",
        {
            "modules": false,
            "useBuiltIns": true,
            "targets": {
                "browsers": ["Chrome >= 60"]
            }
        }
    ],
    ["react"],
    ["stage-2"]
]}

And with babel-cli, the right ES6 code can be compiled. For example

enter image description here

But when I use webpack, babel-loader in the same babel config, my ES6 code was compiled to ES5.

So how can i compile ES6+ code to ES6+ with Webpack?

Does webpack compile ES6+ code to ES5 ?

Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
Zhendong
  • 99
  • 6

1 Answers1

1

There's option target option esmodules. check it out here.

{
"presets": [
    [
        "@babel/preset-env",
        {
            "modules": false,
            "useBuiltIns": true,
            "targets": {
                "browsers": ["Chrome >= 60"],
                "esmodules": true
            }
        }
    ],
    ["@babel/preset-react"]
]}
Jasper Bernales
  • 1,601
  • 1
  • 11
  • 16