pwhitt
pwhitt

Reputation: 35

How to set router base just for nuxt generate?

I am building a static site. When I run nuxt generate and push to the subfolder ( can't be on root ) with that path, it works but unfortunately that breaks npm run dev. I'm gathering it either has something to do with the build extend in nuxt.config or a const before the export default. Ideally when I run npm run dev, the base would be '/' and when I run npm run generate, the base would be '/mypath/'.

I'm looking at this link for answers: https://nuxtjs.org/faq/github-pages/ And am trying this code:

// config
const routerBase = process.env.DEPLOY_ENV === 'GEN' ? {

  router: {
    base: '/wee/'
  }
} : {
    router: {
      base: '/'
    }
}
...
router: {
      base: routerBase
  },
// package json
"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "DEPLOY_ENV=GEN nuxt generate"
  }
//
//
// also am trying to look into this in config - set it in here dynamically
extend(config, { isDev, isClient }) {
          //console.log(config.router)
    }

When i run npm run dev I get Cannot GET/. Ideally I don't have to manually save out base in config every time I want to run generate. Thanks.

Upvotes: 1

Views: 3204

Answers (1)

user1528240
user1528240

Reputation: 11

config.js

    const routerBase = process.env.DEPLOY_ENV === 'GEN'
      ?
        '/wee/'
     :
        '/';
...
        router: {
       base: routerBase
     },

Upvotes: 1

Related Questions