Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

webpack 如何将本次构建的hash值挂到全局供js代码使用呢?

我使用webpack构建时 想要把hash值存到全局变量中 其他模块的js可以调用到。试着配了下 只有放到文件名中 比如output: 'a[hash].js'才有效果 但这样并没有存到全局变量中 项目中的js无法调用到。试着放在new webpack.DefinePlugin中 但拿不到hash值 求大神们支招


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

刚才看了一下文档和源码,提供一个思路吧

你想获取 output.filename 中设置的 [name].[hash].bundle.js

The following substitutions are available in template strings (via
webpack's internal TemplatedPathPlugin):

可以试试 TemplatedPathPlugin 或者扩展 TemplatedPathPlugin。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...