EvanAgee / vuejs-wordpress-theme-starter

A WordPress theme with the guts ripped out and replaced with Vue.
https://vuewp.com/
1.6k stars 281 forks source link

Lazy-loading routes, async components #36

Open rugor opened 5 years ago

rugor commented 5 years ago

Code splitting minimizes bundle size, so I wanted it for my project. This is how I did it:

in router/index.js:

// import Page from '../components/Page/Page.vue'
const Page = () => import('../components/Page/Page.vue')

in webpack.mix.js:

mix.webpackConfig({
  output: {
    publicPath: 'vuejs-wordpress-theme-starter/dist/',
    chunkFilename: 'scripts/[name].[chunkhash].js',
  },
});

and in the <head> of index.php:

<base href="<?php bloginfo( 'stylesheet_directory' ); ?>" />

Not sure if lazy-loading is 'best practice' for everyone, so putting it here instead of a pr. Perhaps its useful for someone or can be improved.

EvanAgee commented 5 years ago

Awesome, thanks for sharing @rugor