webpack4之plugin


html-webpack-plugin

html-webpack-plugin会在打包结束后,自动生成一个html文件,并把打包生成的js文件自动引入到html文件中

配置
1
2
3
4
5
6
7
// webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
plugins: [new HtmlWebpackPlugin({
template: './index.html' // 这是模板html,不配置的话是默认的html文件,不满足需求
})]
}

clean-webpack-plugin

在打包前清理dist的文件

配置
1
2
3
4
5
6
7
var { CleanWebpackPlugin } = require('clean-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
plugins: [new HtmlWebpackPlugin({
template: './index.html' // 这是模板html,不配置的话是默认的html文件,不满足需求
}), new CleanWebpackPlugin()]
}