0
votes

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.

1
so what the problem with the code u posted? - Aldarund
It wasn't working. Just bad ternary code I think. Better: ``` const routerBase = process.env.DEPLOY_ENV === 'GEN' ? '/yourpath/' : '/' ``` and then in package json ``` "generate": "DEPLOY_ENV=GEN nuxt generate" ``` - pwhitt

1 Answers

0
votes

config.js

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