How do I get the prerender-spa-plugin to work with Laravel?

  • 0
    At the moment there is a code like this in webpack.mix.js:

    const mix = require('laravel-mix');
    const path = require('path')
    const PrerenderSPAPlugin = require('prerender-spa-plugin')
     | Mix Asset Management
     | Mix provides a clean, fluent API for defining some Webpack build steps
     | for your Laravel application. By default, we are compiling the Sass
     | file for the application as well as bundling up all the JS files.
    mix.js('resources/js/app.js', 'public/js')
        .sass('resources/sass/app.scss', 'public/css')
    if (mix.inProduction()) {
    mix.webpackConfig = {
        plugins: [
            new PrerenderSPAPlugin({
                // Required - The path to the webpack-outputted app to prerender.
                staticDir: path.join(__dirname, 'dist'),
                // Required - Routes to render.
                routes: ['/', '/portfolio'],

    Laravel Anonymous, Mar 2, 2020

  • 1 Answers
  • 0
    If laravel is used only as an API, and the application itself is a SPA, then it is more logical to divide it into two applications - one laravel (or even lumen) with an API, and the other - vue (vue-cli, nuxt and that's all). For mix, of course, is a good thing, but some settings are not obvious + in vue-cli and nuxt a lot of things are pre-configured.
    Sophie Woods

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!