如何通过环境设置奥雷利亚常数 [英] How to set a constant in aurelia by environment
问题描述
我希望我的API的基本URL从dev
更改为prod
.在Angular I中,用户使用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
.
在此目录中,您可以设置环境配置,这些环境配置将根据传递给au build/run
命令的--env [dev/stage/prod]
标志复制到src
目录中的environment.js中.
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.
这篇关于如何通过环境设置奥雷利亚常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!