nuxt.js -> Howto configure production/development

2019-08-02 00:52发布

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?

标签: nuxt.js
1条回答
仙女界的扛把子
2楼-- · 2019-08-02 01:46

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. :)

查看更多
登录 后发表回答