How to compile ES6 + ES6 code using webpack?

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

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

And with babel-cli you can compile the correct ES6 code. For instance,

enter image description here

But when I use the Web package , babel-loader in the same configuration babel, my code ES6 was compiled in ES5.

So how can I compile ES6 + code in ES6 + using Webpack?

Does webpack compile ES6 + code in ES5?

+9
source share
1 answer

There is a variant of the target option esmodules. check it out here .

{
"presets": [
    [
        "@babel/preset-env",
        {
            "modules": false,
            "useBuiltIns": true,
            "targets": {
                "browsers": ["Chrome >= 60"],
                "esmodules": true
            }
        }
    ],
    ["@babel/preset-react"]
]}
+1
source

Source: https://habr.com/ru/post/1695397/


All Articles