Vue: Provide first class support for splitting code base into modules

Created on 4 Jul 2017  ·  4Comments  ·  Source: vuejs/vue

What problem does this feature solve?

Coming from Angular 2 , one of the feature I really miss is the use of modules to divide my code base into logical units. Technically, I can still do this in Vue by providing the below as a router component:

import Vue from 'vue';
import { routes } from './routes';

export const LazyModule: Vue.ComponentOptions<Vue> = {
  render: r => {
    console.log('rendering');
    return r('router-view');
  },
  created: function() {
    this.$router.addRoutes(routes);
  }
};

This does work but I think it would be more intuitive if there was a clear separation between what a Vue Component and Module are. Specifically, a module would not provide a render method.

What does the proposed API look like?

There has been some good work toward this end here. I have also been testing my previous example of "module" here.

Ultimately, I think we could expect some basic support in Vue and then allow Vue Router and Vuex to extend it.

Most helpful comment

@patrickhousley, you can take a look at:
Vue Async Components
Vue-router Lazy Loading
Vuex async modules (not merged yet)

All that with ssr and pwa results in a very handy mechanism of code splitting and high performance. I know that's a lot but it gets really easy to use if you get some practice.

All 4 comments

@patrickhousley, Hello, I have no experience with Angular 2, can you please try to describe what exactly is a module and what is example use-case for that?

IMO, in such framework like Vue/React, the idea is trying to think (almost) everything in Component way. So I prefer to composite components rather than with Module.

@jkzing After looking at this more, I would agree. I think what I am really looking for could be handled here. Honestly, I really just want a way to cleanly split my app into pieces. The router can do this already but only at the component level. The routes still have to be loaded statically making lazy loading large chunks of an app a little problematic.

@patrickhousley, you can take a look at:
Vue Async Components
Vue-router Lazy Loading
Vuex async modules (not merged yet)

All that with ssr and pwa results in a very handy mechanism of code splitting and high performance. I know that's a lot but it gets really easy to use if you get some practice.

Was this page helpful?
0 / 5 - 0 ratings