如果跟着webpack走,到清理 /dist 文件夹 这个部分。按照文档教程。
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: [
+ new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
title: 'Output Management'
})
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
这样如果是webpack4会报错,TypeError: CleanWebpackPlugin is not a constructor
原因是CleanWebpackPlugin写法更改,修改成如下即可。
参考:https://www.npmjs.com/package/clean-webpack-plugin
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: [
+ new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Output Management'
})
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
}
最后,关于中文文档的这部分问题,已经提交修改。
遇到webpack一些问题可以到
https://github.com/docschina/webpack.js.org/issues
这里查看