watch的使用
改过代码立即打包一份实体文件出来:
watch: true,
watchOptions: {}
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
// 多入口
mode: 'development',
entry: {
home: './src/index.js',
},
watch: true,
watchOptions: { // 监控的选项
poll: 1000, // 每秒寻问我多少次
aggregateTimeout: 500, // 防抖, 过完500ms再进行
ignored: /node_modules/, // 不需要监控哪个文件
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
output: {
// 这里的 name代表 home, other
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html",
filename: "index.html",
chunks: [
"home",
],
})
]
};