我要
错误:clean-webpack-plugin仅接受一个选项对象。看到: https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-
我的Webpack.config.js文件如下:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var plugins = [
new CleanWebpackPlugin(['dist'], {}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new CopyWebpackPlugin([{
from: './src/images/',
to: './images/'
}]),
new HtmlWebpackPlugin({
inject: false,
template: 'src/index.html'
})
];
var config = {
entry: [
'./src/js/main.js'
],
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: 'js/bundle.js',
},
plugins: plugins.concat([
new ExtractTextPlugin('css/bundle.css'),
//new webpack.optimize.UglifyJsPlugin(require('./uglifyjs.json'))
]),
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
include: path.join(__dirname, 'src'),
loader: 'babel',
query: {
presets: ['react', 'es2015']
}},
{
test: /.s?css$/,
include: path.join(__dirname, 'src'),
loader: ExtractTextPlugin.extract('style', [
'css?sourceMap',
'postcss',
'sass?sourceMap'
])
},
{
test: /\.css$/,
include: path.join(__dirname, 'node_modules'),
loader: 'style!css'
}
]
},
postcss: function() {
return [
require('autoprefixer')({
browsers: ['last 2 versions']
})
];
}
}
module.exports = config;
答案 0 :(得分:5)
从the page the error message links中可以看到,CleanWebpackPlugin
在传入时不接受两个参数:
new CleanWebpackPlugin(['dist'], {}),
相反,只需尝试
new CleanWebpackPlugin(),
如果您不需要传递任何选项。
例如,如果您遵循的是使用其他版本插件的旧教程或类似的教程,并且界面已更改,则可能会遇到此问题。
答案 1 :(得分:0)
就像提到的@AKX一样,clean-webpack-plugin
的最新版本不再接受数组参数。
应该清除的路径是从webpack的output.path
中读取的。在您的示例代码中,它在这里:
output: {
path: path.join(__dirname, 'dist'),
// rest of code
},
您应该非常小心,因为有人仍在使用如下模式:
output: {
path: __dirname,
filename: './dist/bundle.js'
},
以上配置将导致删除项目中的所有文件!
如果您只需要清除webpack的output.path
中的某些文件,则应在传递给cleanOnceBeforeBuildPatterns
构造函数的对象中设置CleanWebpackPlugin
字段。