Search code examples
javascriptwebpackbabeljspolyfillsbabel-polyfill

Webpack / Babel not removing "const"


I'm transpiling my app and trying to get it supported for IE. However polyfill leaves a const statement in my vendor fill which breaks IE.

Is there something wrong with my config?

Webpack:

{ 

    mode: "production",

    entry: {
        app: ["whatwg-fetch", "@babel/polyfill", "./src/app/app.js"]
    },

    output: {
        path: path.resolve(
            __dirname,
            "temp/" + envData.environment + "/app/js"
        ),
        filename: "[name].bundle.js",
        publicPath: "/"
    },

    optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    test: /[\\/]node_modules[\\/]/,
                    name: "vendor",
                    chunks: "initial"
                }
            }
        }
    },

    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                loader: "happypack/loader",
                options: { babelrc: true, cacheDirectory: "./cache" }
            }
        ]
    }
}

Babelrc:

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "chrome": "55",
                    "ie": "8"
                }
            }
        ]
    ]
}

EDIT: Sorry, I forgot to include my happy loader config, which does run my code through babel-loader:

let plugins = [
    new HardSourceWebpackPlugin(),
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new HappyPack({
        loaders: ["babel-loader"]
    }),
    new LiveReloadPlugin({
        hostname: "localhost"
    })
];

Solution

  • babel-polyfil introduced this. Upgrade to > 7.4.4 for fix.

    https://github.com/babel/babel/issues/9854