#虽然作为一个前端已经耕耘此行业有三五个年头,但都是在业务中未曾精进,怀着初心,重识Webpack,砥砺前行💪#
- 打包html资源需要先安装html-webpack-plugin
- 指定src模版路径
webpack 命令在右webpack.config.js 文件目录下 可以直接shell 运行webpack 然后自动运行webpack.config.js的内容
const {resolve} = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output:{
filename: 'built.js',
path: resolve(__dirname,'build')
},
module:{
// loader 配置
rules: []
},
plugins:[
// plugins 配置
// 打包html 需要 html-webpack-plugin 包
new HtmlWebpackPlugin({
// 定义html 模版入口 自动打包所有的资源(js/css)
template: './src/index.html',
}),
],
mode: 'development',
}