默认的webpack箭头功能IE11问题

问题描述

我对webpack和IE11有问题。我使用Babel进行编译,所有功能内容都经过了webpackbootstrap函数的编译。如图所示,您可以看到打破IE11的箭头功能。我还创建了我自己的函数和JS,并对其进行了转译,因此仅webpack自己的js不进行转译。有没有人见过同样的问题?我已经在互联网上搜索了2天,并尝试了许多解决方案,但没有一个解决此问题。

您可以在图像中看到babel正确地编译了除认webpack javascript之外的所有内容

我对此感到迷茫,请帮助我!

谢谢。

webpack.config.js

const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const path = require("path");

module.exports = {
    module: {
        rules: [
            {
                test: /\.scss$/,use: [
                    MiniCssExtractPlugin.loader,{
                        loader: 'css-loader'
                    },{
                        loader: 'sass-loader',options: {
                            sourceMap: true,// options...
                        }
                    }
                ]
            },{
                test: /\.js$/,exclude: /node_modules/,use: {
                    loader: 'babel-loader',options: {
                        presets: ['@babel/preset-env'],plugins: ["@babel/plugin-transform-arrow-functions"]
                    }
                }
            }
        ]
    },plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname,"src","index.html")
        }),new MiniCssExtractPlugin({
            filename: 'css/main.css'
        })
    ]
};

package.json

{
  "name": "webpack-tutorial","version": "1.0.0","description": "","main": "index.js","scripts": {
    "dev": "webpack --mode development","start": "webpack serve --mode development","build": "webpack --mode production","start-prod": "webpack serve --mode production","test": "echo \"Error: no test specified\" && exit 1"
  },"keywords": [],"author": "","license": "ISC","devDependencies": {
    "@babel/core": "^7.12.0","@babel/plugin-proposal-class-properties": "^7.10.4","@babel/plugin-transform-arrow-functions": "^7.10.4","@babel/preset-env": "^7.12.0","babel-loader": "^8.1.0","babel-preset-es2015": "^6.24.1","css-loader": "^5.0.0","html-webpack-plugin": "^4.5.0","mini-css-extract-plugin": "^1.0.0","sass": "^1.27.0","sass-loader": "^10.0.3","style-loader": "^2.0.0","webpack": "^5.1.0","webpack-cli": "^4.0.0","webpack-dev-server": "^3.11.0"
  }
}

enter image description here

示例JS输入

enter image description here

示例JS输出

enter image description here

解决方法

他在webpack v5中也遇到类似的问题。

您可以在这里找到我的解决方案:

webpack + babel - transpile object arrow functions doesn't work