Performance: Bundle analysis and tree shaking
This concept affects the page load speed by reducing the JavaScript bundle size and improving initial download and parse time.
import { VBtn, VCard } from 'vuetify/components'; export default { components: { VBtn, VCard } };
import * as Vuetify from 'vuetify'; export default { components: { ...Vuetify } };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Import full library | N/A | N/A | High due to large JS execution | [X] Bad |
| Import only used components | N/A | N/A | Low due to smaller JS execution | [OK] Good |
tree shaking in a Vue project?--report flag during build.vue-cli-service build --report -> Option Cimport { ref, reactive, unusedFunc } from 'vue';
export default {
setup() {
const count = ref(0);
const state = reactive({ name: 'Vue' });
return { count, state };
}
}ref and reactive, but unusedFunc is never used.unusedFunc to reduce bundle size.unusedFunc is removed from the final bundle -> Option Dimport * as lodash from 'lodash') prevents tree shaking from removing unused parts.Pass the test and this pattern moves unknown