在提取文本插件之后将带有哈希的 css 文件名链接到 index.html [英] Link css filename with hash to index.html after the Extract Text Plugin
问题描述
我想问一下,在为我的产品运行 npm 后,如何将生成的带有哈希名称的 css 文件链接到我的 index.html:
I would like to ask how can I link the generated css files with a hash name to my index.html after I run the npm for my production:
"build-production": "webpack -p --progress --colors --config webpack.config.production.js"
这是我的 webpack 配置中的插件,它将生成带有哈希的文件名,因为每次我为生产构建时,它都会生成一个新的哈希文件名.有没有不用手动编辑index.html就可以自动完成的方法?
This is the plugin in my webpack config that will generate the filename with hash since every time I build for production it generates a new hash filename. Is there a way that can automatically do it without manually editting the index.html?
plugins: [
new ExtractTextPlugin("css/[name][contenthash].css")
]
推荐答案
html-webpack-plugin 就是答案.
它可以为生成的css和js文件自动添加link
和script
标签到index.html
.
It can automatically add link
and script
tag to index.html
for generated css and js file.
这篇关于在提取文本插件之后将带有哈希的 css 文件名链接到 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!