Webpack问题汇总
1. clean-webpack-plugin only accepts an options object.
描述:
1.项目结构
2.webpack
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
app: './src/index.js',
print: './src/print.js'
},
plugins: [
//该插件会根据output路径自动识别输出文件,并删除历史文件,只保留最新构建
new CleanWebpackPlugin(['dist']),
//自动生成index.html文件、、、、、
new HtmlWebpackPlugin({
title: 'Output Management'
})
],
output: {
//文件名必须是动态生成的,不然会文件名冲突
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
}
;
原因:传参异常
解决:
去掉参数,该插件会根据output路径自动识别输出文件,并删除历史文件,只保留最新构建
官方参数文档:https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional