-
Beta Was this translation helpful? Give feedback.
Answered by
ElMassimo
Apr 2, 2024
Replies: 1 comment 1 reply
-
Hi Paul! It's usually fine to have a single entrypoint, and let Rollup figure out the best way to split the bundle. Something that you can do to have a more flexible setup is to allow the bundle to split each page in a separate chunk, by using dynamic imports: if (location.pathname === '/admin/dbadmin')
import('@pages/admin/Dbadmin.vue').then(mod => createApp(mod.default).mount('#sl_vue_dbadmin')) You could generalize this by using a declarative approach such as adding const pagesByFilename = import.meta.glob('@pages/**/*.vue', { import: 'default' })
document.querySelectorAll('[data-app]').forEach(mountEl => {
const pageName = mountEl.dataset.app
const importPage = pagesByFilename[`${pageName}.vue`]
importPage().then(mod => createApp(mod.default).mount(mountEl)
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Fedrius
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Paul!
It's usually fine to have a single entrypoint, and let Rollup figure out the best way to split the bundle.
Something that you can do to have a more flexible setup is to allow the bundle to split each page in a separate chunk, by using dynamic imports:
You could generalize this by using a declarative approach such as adding
data-app="admin/Dbadmin"
to the element where each app should be mounted, usingimport.meta.glob
to import all pages, then use the attribute to mount the corresponding Vue app: