问题
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