Skip to content

Instantly share code, notes, and snippets.

@undoZen
Created March 27, 2019 05:49
Show Gist options
  • Save undoZen/678f3068143daaa97ad56f3b71ed53e9 to your computer and use it in GitHub Desktop.
Save undoZen/678f3068143daaa97ad56f3b71ed53e9 to your computer and use it in GitHub Desktop.
Taro webpack h5 build hash all assets
module.exports = {
h5: {
miniCssExtractPluginOption: {
filename: 'css/[name].[hash].css',
chunkFilename: 'css/[id].[chunkhash].css'
},
enableDll: false,
webpackChain(chain, webpack) {
const hashRule = (type) => {
chain.module.rules.get(type).uses.get("urlLoader").get("options").name =
chain.module.rules.get(type).uses.get("urlLoader").get("options").name.replace("[name].[ext]", "[name].[hash].[ext]")
}
hashRule('font')
hashRule('image')
hashRule('media')
chain.merge({
output: {
filename: "[name].[chunkhash].js",
chunkFilename: chain.output.get("chunkFilename").replace("[name].js", "[name].[chunkhash].js"),
},
})
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment