nuxt.js ->如何配置生产/开发设置 [英] nuxt.js -> Howto configure production/development settings

查看:142
本文介绍了nuxt.js ->如何配置生产/开发设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有羽毛的 nuxt.js 项目.客户端和服务器是不同的实体,你单独启动它们.客户端使用 nuxt.js.我想配置生产和开发设置.

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.

目前我的 nuxt.config.js 看起来像这样:

Currently my nuxt.config.js looks like this:

module.exports = {
    head: {
        title: "SITE TITLE"
    },
    env: {
        backendUrl: 'http://localhost:3001'
    }
};

我想要的是,如果我使用npm run dev"开发设置启动客户端.我想要例如不同的标头和不同的 backendUrl.

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.

问题

我需要做什么来实现这一点?

What do I need to do to implement this?

推荐答案

在我的项目中

我把这段代码放在 nuxt.config.js 中

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

这篇关于nuxt.js ->如何配置生产/开发设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆