[Solved] Webpack4 output configuration filename chunkash error

The hash here is changed from chunkhash to hash because chunkhash and content hash cannot be used after using hotmodulereplacementplugin
some places say that it is OK to remove “hot: true”, but my own actual test is not good. Just removing hot will still report an error; So I simply changed it to hash. Anyway, it’s local debugging, which has little impact
my approach is to distinguish environments and output different configurations in different environments.
in this way, the local test will not report errors

const dirVars = require('./base/dir-vars.config.js')
const isOnlinepro = process.argv.indexOf('--env=onlinepro') !== -1 //If this parameter is present it is the production environment API_ROOT value is the cdn address
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] is the key in each entry to specify the name of the generated file in bulk [name]. [chunkhash].js
    //chunkFilename: 'static/js/[id].bundle.js' //.[chunkhash]
}

 

Similar Posts: