import HomePage from '../../pages/HomePage';
import Page404 from '../../pages/Page404';
import AppMainHeader from '../../components/layout/AppMainHeader';
import AppMainFooter from '../../components/layout/AppMainFooter';
/ eslint-disable /
import app from './app';
import router from './router';
import store from './store';
import renderVueComponentToString from 'vue-server-renderer/basic';
new Promise((resolve, reject) => {
router.push(context.url);
// Production mode
if (mix.inProduction()) {
mix.version(['public/atd/images', 'public/atd/svg']);
}
But if I try to do it with lazy-load with the same code only routes changed for code-splitting:
import HomePage from '../../pages/HomePage';
import AppMainHeader from '../../components/layout/AppMainHeader';
import AppMainFooter from '../../components/layout/AppMainFooter';
It always use fallback `ssr('atd/js/app-server.js')->context(['data' => $data])->fallback('<div id="app"></div>')->render()` with app-client.js and I don’t have SSR…
Is it real to do code-splitting with SSR?
I have an app with Vue+Vuex+Vue-router and Laravel+spatie/laravel-server-side-rendering.
It works well with SSR and it renders well to:
app.blade.php
routes
export default [ { path: '/', name: 'HomePage', components: { default: HomePage, 'main-header': AppMainHeader, 'main-footer': AppMainFooter, }, }, { path: '/404', name: 'Page404', component: Page404, }, { path: '*', redirect: { name: 'Page404' }, }, ];
/ eslint-disable / import app from './app'; import router from './router'; import store from './store'; import renderVueComponentToString from 'vue-server-renderer/basic';
new Promise((resolve, reject) => { router.push(context.url);
}) .then((app) => { renderVueComponentToString(app, (err, html) => { if (err) { throw new Error(err); }
const mix = require('laravel-mix'); const path = require('path');
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin'); const ImageminPlugin = require('imagemin-webpack-plugin').default; const CopyWebpackPlugin = require('copy-webpack-plugin'); const imageminMozjpeg = require('imagemin-mozjpeg');
mix.js('resources/atd/app-client.js', 'public/atd/js') .js('resources/atd/app-server.js', 'public/atd/js') // .sourceMaps() .options({ extractVueStyles: 'public/atd/css/main.css', }) .browserSync({ proxy: 'ssr-test.loc', open: false, files: 'public/atd', }) .webpackConfig({ resolve: { alias: { vue$: 'vue/dist/vue.common.js', }, }, module: { rules: [ { test: /.pug$/, loader: 'pug-plain-loader', }, ], }, plugins: [ new SVGSpritemapPlugin('resources/atd/assets/svg/*/.svg', { output: { filename: 'atd/svg/icon-sprite.svg', // svg4everybody: false, svgo: { plugins: [ { removeTitle: true, }, { removeAttrs: { attrs: '(stroke|fill)', }, }, ], }, }, sprite: { generate: { symbol: '-', use: true, view: true, }, }, styles: path.join(__dirname, 'resources/atd/assets/sass/sprites.scss'), }), new CopyWebpackPlugin([ { from: 'resources/atd/assets/images', to: 'atd/images', }, ]), new ImageminPlugin({ test: /.(jpe?g|png|gif)$/i, disable: process.env.NODE_ENV !== 'production', // Disable during development plugins: [ imageminMozjpeg({ quality: 65, }), ], }), ], });
// Production mode if (mix.inProduction()) { mix.version(['public/atd/images', 'public/atd/svg']); }
import HomePage from '../../pages/HomePage'; import AppMainHeader from '../../components/layout/AppMainHeader'; import AppMainFooter from '../../components/layout/AppMainFooter';
export default [ { path: '/', name: 'HomePage', components: { default: HomePage, 'main-header': AppMainHeader, 'main-footer': AppMainFooter, }, }, { path: '/404', name: 'Page404', // LAZY LOAD MODEL component: () => import('../../pages/Page404'), }, { path: '*', redirect: { name: 'Page404' }, }, ];