這里的hash由chunkhash改成hash,原因是使用HotModuleReplacementPlugin之后不能使用chunkhash和contenthash。
看到有些地方說把“hot:true”去掉就行了,但是我自己實際測試不行,只是去掉hot還是會報錯;所以我索性給改成hash了,反正是本機調試,影響不大。
我的做法是區分環境,不同環境輸出不同的配置.
這樣本地測試就不會報錯了.
const dirVars = require('./base/dir-vars.config.js') const isOnlinepro = process.argv.indexOf('--env=onlinepro') !== -1 //判斷參數如果有這個就是生產環境 API_ROOT值就為cdn地址 const isTestpro = process.argv.indexOf('--env=testpro') !== -1 let rootPath = '' let outPath = '' if (isOnlinepro) { rootPath = '/tpl/' outPath = dirVars.buildOnline filename = 'static/js/[name].[chunkhash].js' } else if (isTestpro) { rootPath = '/build/' outPath = dirVars.buildDir filename = 'static/js/[name].[chunkhash].js' } else { rootPath = '/' outPath = dirVars.buildDir filename = 'static/js/[name].[hash].js' } module.exports = { ///entry path: outPath, publicPath: rootPath, filename: filename, // [name]表示entry每一項中的key,用以批量指定生成后文件的名稱[name].[chunkhash].js //chunkFilename: 'static/js/[id].bundle.js' //.[chunkhash] }