问题
I have a nuxt.js project with feathers. The client and server are to different entities, you start them seperatly. The client uses nuxt.js. I want to configure production and development settings.
Currently my nuxt.config.js looks like this:
module.exports = {
head: {
title: "SITE TITLE"
},
env: {
backendUrl: 'http://localhost:3001'
}
};
What I would like is that if I start the client with 'npm run dev' development setting are used. I would like to have e.g. a different header and different backendUrl.
Question
What do I need to do to implement this?
回答1:
In my project
I put this code in nuxt.config.js
const config = {
test: process.env.NODE_ENV !== 'production' ? 'devdevdevelopment' : 'proproproduction',
apiserver: process.env.NODE_ENV !== 'production' ? 'developement apiserver' : 'production vbvbvbvbv apiserver',
}
module.exports = {
env: {
dev:config.test,
server:config.apiserver
},
}
and do so , You can set environment variables dynamically depends on devevelopment or production mode.
This code work for me. If you have anything better than this solution please let me know. :)
回答2:
I would do that HninYuKo has suggested but take it a step further. Install https://github.com/nuxt-community/dotenv-module and add a .env file, so that it becomes accessible to you anywhere in your Nuxt.js codebase. You now have environment-specific files that you can customize on dev or production, in addition to being able to invoke environment-specific builds from the command line.
来源:https://stackoverflow.com/questions/43017928/nuxt-js-howto-configure-production-development-settings