DEV Community

Cover image for Mixing nuxt generate and build
florent giraud
florent giraud

Posted on

2 1

Mixing nuxt generate and build

Hello everyone !

I wanted to share you a little tip with nuxt generate.

I wanted to put my landing pages in a CDN but not my dashboard.

According to the nuxt generate documentation we you can use exclude with a regex.

But yeah "regex".

I don't like (a lot!) regex and i prefer to use include instead of using exclude.
I created a module that use 'generate:extendRoutes' and introduce whitelist instead of exclude.

// modules/custom-generate.js
module.exports = function() {
  this.nuxt.hook('generate:extendRoutes', (routes) => {
    const whiteList = [
      '/', //this is the index.vue root file
      '/talents-signed-up',
      '/404',
      '/company-signed-up',
      '/company',
      '/talents'
    ]
    const routesToGenerate = routes.filter((page) => {
      return whiteList.includes(page.route)
    })
    routes.splice(0, routes.length, ...routesToGenerate)
  })
}
Enter fullscreen mode Exit fullscreen mode

This module is ok if you don't have a lot of pages that you want to generate.

You can add 'regex' valiation in the filter instead of my array if you prefer :).

Thank's !

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (2)

Collapse
 
dreaminder profile image
DreaMinder •

You mean /dashboard static-routes are getting generated and you want them to be spa-only?
You could use this command to avoid generating any routes except the ones you specified in nuxt.config:
nuxt build && nuxt generate --no-build
instead of nuxt generate

Collapse
 
flozero profile image
florent giraud •

Ok i get it ! I dont want my dashboard to be full SPA. in some page i want to be sure that back request working and the client non see them so it's a nuxt build && nuxt generate in my case

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay