nuxt.js -> Howto configure production/development settings

会有一股神秘感。 提交于 2019-12-11 06:36:07

问题


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

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