Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash,contenthash,chunkhash的区别 #29

Open
JCHappytime opened this issue Mar 4, 2021 · 0 comments
Open

hash,contenthash,chunkhash的区别 #29

JCHappytime opened this issue Mar 4, 2021 · 0 comments
Labels
webpack webpack工程化常见问题

Comments

@JCHappytime
Copy link
Owner

JCHappytime commented Mar 4, 2021

hash

hash是跟整个项目构建相关,只要项目里面有文件修改,整个项目构建的hash值都会更改,并且全部文件都共用相同的hash值。

contenthash

使用webpack编译代码时,我们可以在js文件里面引用css文件。所以这2个文件应该共用相同的chunkhash值,但是有个问题:如果js更改了代码,css文件就算内容没有任何改变,由于该模块发生了改变,这导致CSS会重复构建,这个时候,我们可以使用 extra-text-webpack-plugin 里面的contenthash值,保证即使CSS文件所处的模块里其他文件内容改变,只要CSS文件内容不变,那么就不会重复构建。

chunkhash

采用hash计算的话,每一次构建后生成的哈希值都不一样,即使文件内容压根没有改变。这样子时没办法实现缓存效果,我们需要换另一种hash值计算方法,也就是chunkhash。它会根据不同的入口文件(Entry)进行依赖文件解析、构建对应的chunk,生成对应的哈希值,那么只要我们不改动公共库代码,就可以保证其哈希值不会受影响。

@JCHappytime JCHappytime added the webpack webpack工程化常见问题 label Mar 4, 2021
@JCHappytime JCHappytime changed the title hash,contenthash,chunkhash的区别 hash,contenthash,chunkhash的区别以及splitChunks详解 Mar 4, 2021
@JCHappytime JCHappytime changed the title hash,contenthash,chunkhash的区别以及splitChunks详解 hash,contenthash,chunkhash的区别 Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
webpack webpack工程化常见问题
Projects
None yet
Development

No branches or pull requests

1 participant