一.HtmlWebpackPlugin
会在打包结束后,在dist目录下自动生成html文件,并把打包生成的js自动引入到html文件中
webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpackConfig = {
entry: 'index.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
template:'src/index.html'
})]
};
template:'src/index.html’设置html模板文件
二.clean-webpack-plugin
webpack.config.js
var CleanWebpackPlugin = require('clean-webpack-plugin');
var webpackConfig = {
entry: 'index.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
template:'src/index.html'
}),new CleanWebpackPlugin(['dist'])]
};
参数代表在打包之前会删除dist目录下的所有东西