【发布时间】:2020-10-15 19:42:41
【问题描述】:
我在使用 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 输出
【问题讨论】:
标签: webpack babel-loader