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

vite 打包后所有 js 文件(无论是否修改) hash 都改变了,怎么实现只有改动文件的 hash 值变化。其他文件才能缓存 #6928

Closed
7 tasks done
Krryxa opened this issue Feb 15, 2022 · 13 comments
Labels
duplicate This issue or pull request already exists pending triage

Comments

@Krryxa
Copy link

Krryxa commented Feb 15, 2022

Describe the bug

vite 打包后所有 js 文件(无论是否修改) hash 都改变了,怎么实现只有改动文件的 hash 值变化。其他文件才能缓存

Reproduction

https://github.com/Krryxa/krry-vue-vite

System Info

"vite": "^2.7.1"

Used Package Manager

yarn

Logs

No response

Validations

@chenyurou
Copy link

遇到了同样问题,导致文件缓存也失效,请问应该怎么解决

@Krryxa
Copy link
Author

Krryxa commented Feb 15, 2022

image

是这个依赖全部内容的问题吗

@chenyurou
Copy link

chenyurou commented Feb 15, 2022

是的,像我只改了403文件,预期是只想要403.1891d439.js的hash发生变化,但是现在却是全部js文件的hash发生了改变。查看打包出来的文件内容,发现 引用了403文件的index.056b260d.js内容也发生变化,然后其他文件又引用了这个index.056b260d.js,然后就这样引起了一连串变化

@poyoho
Copy link
Member

poyoho commented Feb 16, 2022

image
🤔 but I had same hash.

@Krryxa
Copy link
Author

Krryxa commented Feb 16, 2022

@poyoho Did you modify the files in the second build

@poyoho
Copy link
Member

poyoho commented Feb 20, 2022

是的,像我只改了403文件,预期是只想要403.1891d439.js的hash发生变化,但是现在却是全部js文件的hash发生了改变。查看打包出来的文件内容,发现 引用了403文件的index.056b260d.js内容也发生变化,然后其他文件又引用了这个index.056b260d.js,然后就这样引起了一连串变化

maybe this is right? @Krryxa

@Krryxa
Copy link
Author

Krryxa commented Feb 20, 2022

是的,像我只改了403文件,预期是只想要403.1891d439.js的hash发生变化,但是现在却是全部js文件的hash发生了改变。查看打包出来的文件内容,发现 引用了403文件的index.056b260d.js内容也发生变化,然后其他文件又引用了这个index.056b260d.js,然后就这样引起了一连串变化

maybe this is right? @Krryxa

@poyoho She's my colleague, and we're discussing this issue, looking for ways to solve it

@poyoho
Copy link
Member

poyoho commented Feb 20, 2022

@Krryxa I mean the reason for answering this issue 😂

I tested and modified the file to meet expectations

@chenyurou
Copy link

chenyurou commented Feb 20, 2022

@Krryxa I mean the reason for answering this issue 😂

I tested and modified the file to meet expectations

@poyoho 请问有办法实现类似于webpack contenthash 这样的效果吗,避免出现其他不相关的文件缓存失效

@poyoho
Copy link
Member

poyoho commented Feb 20, 2022

now had two file index.789123.js and a.123456.js

index.789123.js

import { a } from "./a.123456.js";
console.log("baz" + a);

a.123456.js

const a=1;
export{a};

If I change a.123456.js calc the hash. The a.123456.js will be a.abcdef.js.
And index.789123.js had the a.123456.js dep, so index.789123.js content will be change(a.123456.js -> a.abcdef.js.). index.789123.js will be change.

I can't reproduce the problem from your repo. Can you provide a more detailed reproduction path?

@Krryxa
Copy link
Author

Krryxa commented Feb 20, 2022

now had two file index.789123.js and a.123456.js

index.789123.js

import { a } from "./a.123456.js";
console.log("baz" + a);

a.123456.js

const a=1;
export{a};

If I change a.123456.js calc the hash. The a.123456.js will be a.abcdef.js. And index.789123.js had the a.123456.js dep, so index.789123.js content will be change(a.123456.js -> a.abcdef.js.). index.789123.js will be change.

I can't reproduce the problem from your repo. Can you provide a more detailed reproduction path?

@poyoho We already know that this is the reason why the hash values change. We're just looking for a way to avoid this problem. Unmodified files do not change the hash in order to cache them

@869288142
Copy link

869288142 commented Feb 24, 2022

@Krryxa vite production mode use rollup bundle. you can open a issue in rollup repo.
Compared with webpack, rollup's long-term cache is not perfect

@sapphi-red
Copy link
Member

Closing as this is a duplicate of #6773.

@sapphi-red sapphi-red added the duplicate This issue or pull request already exists label Apr 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists pending triage
Projects
None yet
Development

No branches or pull requests

5 participants