Question: How do I code split by route using vue-router@next?
See original GitHub issueI’d like to lazy load routes / create a chunk for each route but I can’t figure out how to make it work. In Webpack I can use a dynamic import with a “magic comment” to name the chunk.
Something like this would be nice but magic comments are something I don’t really care about, I’d just like the output of my build to be split by route and to have the dynamic imports reference the .js
file.
import { RouteRecordRaw } from "vue-router"
export const routes: Array<RouteRecordRaw> = [
{
name: "About",
path: "/about",
component: () => import(/* webpackChunkName: "about" */, "../views/About.vue")
}
]
This thread seems to indicate it works now using rollup-plugin-dynamic-import-variables but using a dynamic import in the router doesn’t ouput what I’d expect – is there something else I need to configure?
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (1 by maintainers)
Top Results From Across the Web
How to Use Vue Router: A Complete Tutorial - Vue School Blog
Let's open up the router/index. js file. We are importing createRouter and createWebHistory from the vue-router library. Next, we import the ...
Read more >the best way to split view between login page and dashboard ...
One way to handle this is to have an intermediary page component that just contains the layout you want, with your other routes...
Read more >Lazy loading components and code splitting in Vue.js
This is done by splitting each route's components into chunks that are separate from the main chunk loaded on initialization.
Read more >How To Use Nested Routes in Vue.js - DigitalOcean
Then, navigate to the newly created project directory: cd vue-nested-routes-example.
Read more >Lazy Loading Routes | Vue Router
When building apps with a bundler, the JavaScript bundle can become quite large, ... It would be more efficient if we can split...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure! I simply changed it to the following:
[Section about generate routes removed to prevent misinformation]
If someone knows how to make dynamically generated routes work, please comment.
Hate that no one answered the original question 😕 How do you set a custom name on the chunk.