-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Circular dependencies in hash create large browser cache invalidation between code releases #10636
Comments
Duplicate of #6773 |
@sapphi-red This is not a straight duplicate of #6773
Here's how I prevent the Vite helper functions mentioned from being added to main index chunk: import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
build: {
target: 'ES2020',
rollupOptions: {
output: {
// Workaround: Vite is bundling its plugins to the main index chunk,
// causing circular dependencies and cascading hash changes.
manualChunks(id) {
if (id.startsWith('vite/') || id.startsWith('\0vite/')) {
// Put the Vite modules and virtual modules (beginning with \0) into a vite chunk.
return 'vite';
}
},
},
},
},
plugins: [vue()]
}); |
Thanks. I now understand the difference. |
isn't it what my additional examples show? |
Describe the bug
Vite bundles both the Vue library and its own helpers into the top index chunk, and because all components import Vue and use those helpers, then all JavaScript chunks import index.
The impact is that a change to one component causes a hash change to all components which cause a large browser cache invalidation between code releases.
Reproduction
https://github.com/jf-paradis/vite-circular-dependencies
Steps to reproduce
Since the top index indirectly imports all components, any change in a single component changes that component hash, then cascades up to index, then cascades back down to all components.
The impact can be seen here as follow:
Checkout the code at
https://github.com/jf-paradis/vite-circular-dependencies
Run
npm install
Build the app, save the list of hash changes (lines omitted for clarity):
HelloWorld.vue
, and rebuild:ByeByeWorld.js
has changed, even if that component doesn't importHelloWorld.vue
. In fact, all JavaScript files have new hashes.This can be explained becuase all chunks import index:
% grep -rEo "/index\.\w+\.js" dist dist/index.html:/index.6acde798.js dist/assets/Panel.9626c151.js:/index.6acde798.js dist/assets/ByByeWorld.d27c7ad5.js:/index.6acde798.js dist/assets/HelloWorld.85a3b193.js:/index.6acde798.js
Workaround
Uncomment the
manualChunks
function invite.config.ts
.Build the app
HelloWorld.vue
, and rebuild:Notice that the hash of
ByeByeWorld.js
has NOT changed. In fact, onlyHelloWorld.js
andindex.js
have changed.% grep -rEo "/index\.\w+\.js" dist dist/index.html:/index.15a1828f.js
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: