奔奔
老师,我的js里面使用contenthashbuild成功了
'use strict';
const path = require('path');
const webpack = require('webpack');
console.log(__dirname, 'dist');
console.log(path.join(__dirname, 'dist'));
// __dirname 当前目录 /remaineey/workspace/webpack
module.exports = {
entry: './src/index.js', // 单入口
entry: { // 多入口
index: './src/index.js',
search: './src/search.js',
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name][contenthash:8].js',
},
mode: 'development',
module: {
rules: [
{ test: /\.js$/, use: 'babel-loader' },
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
]
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
},
{
test: /\.(jpeg|png|jpg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 333330,
}
}
]
}
]
},
// 默认是false,不开启
// 参考: https://www.webpackjs.com/configuration/watch/
// watch: true,
// // 只有开启监听模式时,watch才有意义
// watchOptions: {
// // 不监听的文件或者文件目录,支持正则匹配
// ignored: /node_modules/,
// // 当第一个文件更改,会在重新构建前增加延迟。这个选项允许 webpack 将这段时间内进行的任何其他更改都聚合到一次重新构建里。以毫秒为单位
// aggregateTimeout: 300,
// // 通过传递 true 开启 polling,或者指定毫秒为单位进行轮询。
// poll: 1000 // 每秒检查一次变动
// },
// 热替换影响了chunkhash的使用,你要确保hotModuleReplacementPlugin()函数没在生产环境下执行
// plugins: [
// new webpack.HotModuleReplacementPlugin()
// ],
devServer: {
contentBase: './dist',
hot: true
}
};