How to set a constant in aurelia by environment

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

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

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.

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

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

How to set a constant in aurelia by environment - aurelia - iOS, If you use the Aurelia CLI, it will generate an environments directory inside of your aurelia_project. Within this directory you can setup environmental configs that  and have a proper endpoint config.apiHostAddress depending on runtime environment. Environments. At the root of application I created a folder called environments. The folder will contain a separate file per each environment: production.js, development.js, etc. File's structure is up to you, in my case they contain ES2015 constants:

If you want to 'inject' it only once then what is stopping you from using a simple ES6 module ? It should be loaded only once from the server.

For instance you could something like that in a config.js file : (warning ! I didn't try to run it)

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

you can then use your module anywhere you need it :

import {Config} from 'config';

Basics, What I've tried is to create a file called /config/environment.staging.json and then run the This environment variable config stuff is a mess in aurelia-cli 1.2.3… Aurelia - Configuration - In this chapter, we will show you how to configure Aurelia framework for your needs. Sometimes you will need to set an initial configuration or run some code be

I have successfully used the Aurelia-Configuration plugin to dynamically switch environments based on the domain that hosts the app

More info https://github.com/Vheissu/Aurelia-Configuration/blob/master/README.md#get-started to do this

Environment.json vs environment.ts - Help Requests, The objective is to have environment specific configurations build is environment variable, the value of which will match the file name: SET APP_ENV​=development #windows cmd export APP_ENV=development #bash  If you run with the dev environment, the file will have the options that represent that (as configured by the aurelia.json file). So if you manually modified it, and then ran, then that file would have been updated with your build instructions.

Per environment configuration in Aurelia, ts file which is a simple copy of the appropriate aurelia_project/environments/${​env}.ts file and assumed/hoped that the CLI bundles this file into  Running Your Aurelia App. From inside your project folder, simply execute au run. This will build your app, creating all bundles in the process. It will start a minimal web server and serve your application. The dev web server by default auto-refreshes your browser when source code changes.

Set environment variable using command line arguments · Issue , getEnvironmentVars(); I want to be able to set a minify and gzip flag in /aureli let myTask = () => { const envSettings = require(`. zewa666 changed the title Access to environment varialbles Access to environment  The Aurelia Configuration plugin allows you to configure during the bootstrapping phase. Changing environment. The concept of environment configuration exists within this plugin.

Access to environment variables · Issue #194 · aurelia/cli · GitHub, His experiments were also repeated under two environmental conditions, which constant —- they vary (quite markedly) with different environmental conditions. Since the volume of P. caudatum was set at 1.00 and that of P. aurelia at 0.39,​  Constants. Constants and values are pretty much the same with a couple of differences. As mentioned earlier, constants can be injected anywhere including configuration calls. So when you call module.config and set up states or other runtime settings you can inject constant values, but not values.

Comments
  • This is a pretty open question because it all depends on how you are serving and could definitely be up to personal choice. I don't see anything wrong with putting it in a json file
  • I wouldn't want to read that json file over and over again - it would make more sense to inject it once (somewhere) in the config
  • Yeah that is what I meant just use the http client to read it one time should be super simple.
  • Thanks PW Kad, any chance you have a gist with an example of how to do it in practice?
  • Yes, injected once - but different values when running locally, and when running on production. In Angular + grunt, I used grunt serve to be DEV constants, and grunt build to be production constants.