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

[webpack] [2021-02-13 更新] Webpack打包时Hash码是怎么生成的?随机值存在一样的情况,如何避免? #23

Open
jeddygong opened this issue Feb 13, 2021 · 1 comment

Comments

@jeddygong
Copy link
Owner

No description provided.

@jeddygong
Copy link
Owner Author

1、Hash

webpack生态中存在多种计算hash 的方式:
  • hash
  • chunkhash
  • contenthash

Hash 代表每次webpack编译中生成的hash值,所有使用这种方式的文件hash都相同。每次构建都会使webpack计算新的hash。

chunkhash 基于入口文件(entry) 及其关联的chunk生成,某个文件的改动只会影响与它有关联的chunk的hash值,不会影响其他文件。

conenthash 根据文件内容创建。当文件内容发生变化时,contenthash发生变化。

2、避免相同随机值

webpack在计算hash后分割chunk。产生相同随机值可能是因为这些文件属于同一个chunk,可以将某一个文件提 到独立的chunk (如放入entry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant