webpack - Babel 不使用 NPM / Webpack 填充?
问题描述
我真的是 Webpack + Babel 的新手,想在我的项目中尝试一下,但是当我运行“npm run build”来运行我包含的 webpack.production.config.js 文件时,它没有似乎在我的脚本中为 IE11 创建了必要的 polyfill。
我在下面包含了我试图填充的 JS 文件之一,我的 package.JSON、.babelrc 和 webpack.production.config.js:
** 包.JSON **
{
"name": "nutrifast",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.production.config.js"
},
"author": "Jonas Schmedtmann",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"babel-loader": "^8.2.2",
"babel-preset-env": "^1.7.0",
"html-webpack-plugin": "^3.0.7",
"webpack": "^5.10.1",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
** webpack.production.config.js **
const path = require('path');
module.exports = {
entry: './src/main.js',
output: {
filename: 'main.min.js',
path: path.resolve(__dirname, './dist'),
publicPath: ''
},
mode: 'production',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-env' ]
}
}
}
]
}
}
** .babelrc **
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry"
}
]
]
}
** ./src/main.js **
// Header Menu
{
const menuTrgr = document.querySelector("a[data-menu-toggle]");
const menuToggle = function() {
menuTrgr.classList.contains("active") ? menuTrgr.classList.remove("active"): menuTrgr.classList.add("active");
};
menuTrgr.addEventListener("click", menuToggle);
}
// Populates Basket from local
if(reset_basket !== 1) {
(function() {
if(localStorage) {
// Populates the meals and totals
const totals = JSON.parse(localStorage.getItem("totals"));
if(totals) {
const basketTotal = totals.mealAmount > 0 ? totals.mealAmount : 0;
document.getElementById("basket-total").innerHTML = `<b>Meals</b> <i>${basketTotal}</i>`;
}
}
})();
}
如果有人能指出我正确的方向,将不胜感激。
解决方案
推荐阅读
- node.js - 您可以使用节点 js 将图像文件作为 URL 保存到数据库中吗?
- dll - 在 Windows CE 上使用为 X86 编译的 DLL 是绝对不可能的吗?
- python - 使用“或”在熊猫数据框中选择值时如何编写条件
- node.js - Mongoose 用字段查找用户?
- c++ - 我是编程新手。编译包含 .h 文件中包含的类定义的代码后,我不断收到错误消息
- c - 移位是否取决于字节序?
- javascript - Contenteditable div 删除和创建新元素
- python - 元组超出范围问题
- javascript - 如何将firebase REST API响应转换为打字稿中的数组?
- django - 将 django 部署到谷歌云引擎服务器错误 (500)