我对webpack和IE11有意见。我使用Babel进行代码转换,除了webpackbootstrap函数之外,所有的函数和东西都被转换了。如图所示,您可以看到一个箭头函数破坏了IE11。我还创建了我自己的函数和JS,并对其进行了转译,因此只有webpack自己的js不会转译。有没有人看到过同样的问题?我已经在互联网上搜索了2天,尝试了很多解决方案,但都没有解决这个问题。
正如您在图片中看到的,babel正确地转译了所有内容,除了默认的webpack javascripts。
我在这上面发疯了,请帮帮我!
提前谢谢。
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"
}
}

示例JS输入

示例JS输出

发布于 2020-10-17 14:30:01
https://stackoverflow.com/questions/64378646
复制相似问题