question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integration with Vue CLI 3.0+ generated project?

See original GitHub issue

I have the plugin working with a project generated with the vue init command, using one of the simple templates. But the Vue CLI vue create command with vue-cli 3.0 structures things differently.

I looked through the docs and different examples, and I found that I had to create a vue.config.js config file. I used the same config setup from the working version, ran yarn build --production and the standard output is generated in /dist instead of the fully html rendered version and files…

Here’s what my vue.config.js file looks like:

`var PrerenderSpaPlugin = require(‘prerender-spa-pluginx’) var HtmlWebpackPlugin = require(‘html-webpack-plugin’) var path = require(‘path’)

module.exports = {

configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
        plugins: [

            new HtmlWebpackPlugin({
                template: 'index.html',
                filename: path.resolve(__dirname, 'dist/index.html')
              }),
          
              new PrerenderSpaPlugin(
                // Absolute path to compiled SPA
                path.resolve(__dirname, '/dist'),
                // List of routes to prerender
                [ '/', '/about', '/portfolio/one', '/portfolio/two', '/portfolio/three', ],
                {
                    // options
                }
              ),
          ]
    }
}

}`

If I’m doing something obviously wrong, let me know… Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

6reactions
JoshTheDerfcommented, Mar 8, 2018

@designcourse Took me way too long to figure out what went wrong.

You’re simply forgetting to return an object containing the plugin configuration and have an extra slash in the dist path. You also shouldn’t need HTMLWebpackPlugin with vue-cli 3.0, so I’d go ahead and remove that.

So instead of this:

var PrerenderSpaPlugin = require('prerender-spa-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var path = require('path')

module.exports = {
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      plugins: [
        new HtmlWebpackPlugin({
          template: 'index.html',
          filename: path.resolve(__dirname, 'dist/index.html')
        }),

        new PrerenderSpaPlugin(
          // Absolute path to compiled SPA
          path.resolve(__dirname, '/dist'),
          // List of routes to prerender
          [ '/', '/about', '/portfolio/one', '/portfolio/two', '/portfolio/three', ],
          {
              // options
            }
        ),
      ]
    }
  }
}

You should do this:

var PrerenderSpaPlugin = require('prerender-spa-plugin')
var path = require('path')

module.exports = {
  configureWebpack: config => {
    if (process.env.NODE_ENV !== 'production') return

    return {
      plugins: [
        new PrerenderSpaPlugin(
          // Absolute path to compiled SPA
          path.resolve(__dirname, 'dist'),
          // List of routes to prerender
          [ '/', '/about', '/portfolio/one', '/portfolio/two', '/portfolio/three', ],
          {
              // options
          }
        ),
      ]
    }
  }
}

By the way, I’d recommend upgrading to prerender-spa-plugin v3 with yarn add prerender-spa-plugin@next -D.

4reactions
vesper8commented, Jul 5, 2018

@designcourse I could really use your vue-cli v3 tutorial on how to use this plugin right about now… because I can’t get it to work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Install And Run The Vue JS 3 Project Using Vue CLI [2022]
In this tutorial, you're going to learn how to get up and running with the Vue 3 project from scratch with step-by-step instructions....
Read more >
Quick Start - Vue.js
The created project will be using a build setup based on Vite and allow us to use Vue Single-File Components (SFCs). This command...
Read more >
Creating Your First Vue 3 Project - A Vue Tutorial - LearnVue
By the end of this tutorial, you'll have created a Vue 3 project, built two components with the Composition API.
Read more >
Getting Started with Vue CLI 3.x - Stack Abuse
Excitingly enough, this last summer has brought us Vue CLI 3.0, ... Congratulations, you have just created your very first Vue CLI project!...
Read more >
A Beginner's Guide to Vue CLI - SitePoint
The CLI will prompt you for the preset you want to use for your project. One option is to select the default preset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found