如何按环境在 aurelia 中设置常量 [英] How to set a constant in aurelia by environment

查看:16
本文介绍了如何按环境在 aurelia 中设置常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 API 的基本 URL 从 dev 更改为 prod.在 Angular 中,我用户使用 config.json 文件,该文件后来使用 grunt-env

I'd like my API's base URL to change from dev to prod. In Angular I user to use a config.json file which was later injected into the app using grunt-env

推荐答案

如果您使用 Aurelia CLI,它将在您的 aurelia_project 中生成一个 environments 目录.

If you use the Aurelia CLI, it will generate an environments directory inside of your aurelia_project.

在此目录中,您可以设置环境配置,这些配置将根据 --env [dev/stage/prod] 标志复制到 src 目录中的 environment.js你传递到你的 au build/run 命令中.

Within this directory you can setup environmental configs that will be copied into environment.js in your src directory based the --env [dev/stage/prod] flag that you pass into your au build/run commands.

然后您可以使用 import environment from './environment' 来访问您的环境特定配置值.

Then you can use import environment from './environment' to access your environment specific configuration values.

您可以研究的另一个选项是 Aurelia 配置插件,它也具有动态环境配置.

Another option that you can look into is the Aurelia Configuration Plugin, which also has dynamic environmental configs.

这篇关于如何按环境在 aurelia 中设置常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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