How to set a constant in aurelia environment

I want my base API URL to change from dev to prod . In Angular, I need to use the config.json file, which was later added to the application using grunt-env

+6
source share
2 answers

If you use the Aurelia CLI , it will create a environments directory inside your aurelia_project .

In this directory, you can configure environmental configurations that will be copied to environment.js in the src directory based on the --env [dev/stage/prod] flag that you pass to your au build/run commands.

You can then use import environment from './environment' to access your configuration values.

Another option you can explore is the Aurelia configuration plugin , which also has dynamic environment configurations.

+11
source

If you want to "enter" it only once, then what prevents you from using a simple ES6 module? It should be downloaded only once from the server.

For example, you could have something similar in the config.js file: (warning! I did not try to run it)

 export var Config = { path : 'path to find' }; 

you can use your module anywhere:

 import {Config} from 'config'; 
+2
source

Source: https://habr.com/ru/post/985439/


All Articles