vite 只有当文件内容发生变化此 hash 才会重新生成,类似于 webpack 的 contenthash 的功能,在 vite 如何实现

2023-02-01 10:38:30 +08:00
 jaween
1666 次点击
所在节点    程序员
14 条回复
356693212
2023-02-01 10:43:35 +08:00
谷歌一下很难吗,rollup 最新的已经修改了 hash 算法了。
jaween
2023-02-01 11:11:01 +08:00
@356693212 小弟愚钝,望仙人指路
karott7
2023-02-01 13:36:36 +08:00
import { createHash } from 'node:crypto'
const hash = createHash('sha256').update(content).digest('base64')
Rrrrrr
2023-02-01 13:43:55 +08:00
服了,发个 github 的 url 都发不出。
Rrrrrr
2023-02-01 13:43:59 +08:00
jaween
2023-02-01 13:46:38 +08:00
@karott7 content 是什么
jaween
2023-02-01 13:48:09 +08:00
@Rrrrrr 我也看过这个 issues ,貌似并没有给到解决方案吧
Rrrrrr
2023-02-01 13:49:04 +08:00
@jaween 里面不是有些人贴了临时的方案
Rrrrrr
2023-02-01 13:49:54 +08:00
vite/issues/6928 这里有中文的
karott7
2023-02-01 13:50:20 +08:00
@jaween 想要 hash 的内容或者数据
Rrrrrr
2023-02-01 14:01:09 +08:00
A hash based only on the content of the final generated chunk, including transformations in renderChunk and any referenced file hashes.

它是根据生成后的 chunk 来的,所以都会变,没毛病
jaween
2023-02-01 15:05:57 +08:00
@Rrrrrr 我看到 rollup3 有关于 hash 算法的修改,但是正如这个 issue 所说,没有啥变化
https://github.com/vitejs/vite/issues/6773
aikilan
2023-02-02 09:06:34 +08:00
文件内容没改过,修改 hash 的需求场景是啥?。。。
jaween
2023-02-02 17:22:04 +08:00
@aikilan 内容有修改,现在 vite 打包后是全 hash 都变了,并不是只有改动的文件的 hash 变

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/912164

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX