安装

npm init -y

安装依赖

 yarn add webpack webpack-cli webpack-dev-server

yarn add html-webpack-plugin 

配置webpack.config.js

const path=require("path"),
// 解析html
HtmlWebpackPlugin=require('html-webpack-plugin')

module.exports={
//模式
mode:"production",
entry:"./src/index.js",
// 打包路径
output:{
filename:"bundle.js",
path:path.resolve(__dirname,"dist")
},
devtool:"source-map",
// 默认寻找位置
resolve:{
modules:[path.resolve(__dirname,""),path.resolve(__dirname,"node_modules")]
},
// 解析html
plugins:[new HtmlWebpackPlugin({
template:path.resolve(__dirname,"public/index.html")
})]
}