Webpack / Babel不删除“ const”

问题描述 投票:0回答:2

我正在编译我的应用程序,并尝试使其支持IE。 但是,polyfill在我的供应商填充中留下了const语句,这会破坏IE。

我的配置有问题吗?

的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"
                }
            }
        ]
    ]
}

编辑:对不起,我忘了包括我快乐的装载机配置,它确实通过babel-loader运行我的代码:

let plugins = [
    new HardSourceWebpackPlugin(),
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new HappyPack({
        loaders: ["babel-loader"]
    }),
    new LiveReloadPlugin({
        hostname: "localhost"
    })
];
javascript webpack babel polyfills babel-polyfill
2个回答
1
投票

安装babel-loader并尝试以下配置:

module: {
  rules: [
    {
      test: /\.m?js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['@babel/preset-env']
        }
      }
    }
  ]
}

0
投票

babel-polyfil对此进行了介绍。 升级到> 7.4.4进行修复。

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

© www.soinside.com 2019 - 2024. All rights reserved.