1️⃣ 安装
npm initnpm i webpack@4 webpack-cli@3 -Dnpm install --save-dev clean-webpack-pluginnpm i --save-dev html-webpack-plugin@4
1️⃣ package.json
{ ...... "scripts": { "build": "webpack --mode=production", "dev": "webpack --mode=development" }, ......}
1️⃣ webpack.config.js
const path = require("path"); const { CleanWebpackPlugin } = require('clean-webpack-plugin');const HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = { mode: 'development', entry: './src/index.js', output: { path: path.resolve(__dirname, 'builder'),filename: 'build.js' }, module: { rules: [] }, plugins: [ new CleanWebpackPlugin(), new HtmlWebpackPlugin({ template: "./src/index.html", filename: "index.html", title: "测试HTMl", }), ], devtool: 'cheap-module-eval-source-map', }