配置以下:css
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
devtool:'inline-source-map',
mode:'development',
entry:'./src/index.js',
output:{
path:path.resolve(__dirname,'dist'),
filename:'bundle-[hash].js'
},
module:{
rules:[
{
test:/\.css$/,
use:'css-loader'
}
]
},
plugins:[
new HtmlWebpackPlugin({
title:'Hello Webpack',
template: './src/index.html'
}),
new CleanWebpackPlugin(path.join(__dirname, 'dist'))
],
devServer:{
contentBase:path.join(__dirname,'dist'),
port:5678,
host:'0,0,0,0'
}
}
packjson命令以下
"scripts": {
"dev": "webpack-dev-server --open",
"test": "echo \"Error: no test specified\" && exit 1"
},
執行命令 npm run dev 報錯信息提示項目的dist目錄已經被 clean-webpack-plugin 插件刪除了。
有大神提點一下嗎?
複製代碼