这里的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]
}

 

相关文章:

  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案