Different baseURL for development and production with Nuxt.js

喜你入骨 提交于 2019-12-12 23:19:18

问题


How can I add a different baseURL for development and production?

This is currently my nuxt.config.js

module.exports = {
  mode: 'universal',
...
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
    baseURL: 'http://10.8.0.1:8000',
    credentials: false
  },
...
}

For npm run dev and npm run generate I would like to have different baseURL's.

How can I do this?

EDIT

// nuxt.config.js
export default {
  env: {
    baseUrl: process.env.BASE_URL || 'http://localhost:3000'
  }
}

console.log(process.env.BASE_URL) // <-- The output is correct (I get the BASE_URL from my env variables

module.exports = {
   ...
  axios: {
    baseURL: process.env.baseUrl // <-- This is not working, why?
  },
   ...
}

回答1:


You can do like this

Inside your nuxt.config.js file add this environment variable

   build: { ....},
   env: {
    baseUrl: process.env.BASE_URL || 'localhost'
   }

Thanks !



来源:https://stackoverflow.com/questions/54516511/different-baseurl-for-development-and-production-with-nuxt-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!