Env is not hard coded enums in cli based app. If you run without --env, the default environment is “dev”.
The meaning of every environment is not hard coded. The environment name is used in 2 ways in cli based app.
- runtime properties, like
environment.debug
check in your main.js.
Your src/environment.js
was copied by cli from aurelia_project/environements/...js
. By default, cli generates 3 environment config files for your dev.js
, prod.js
, and stage.js
.
You can add more environment config files, then use --env yourNewEnv
to use the file.
There are 2 properties: debug
and testing
in the default config files. You can add more properties to every env config file, then use those properties at runtime, simply import environment from '../path/to/environment';
, then use environemnt.yourNewProperty
- compile (bundling) time behaviour control, mainly used in
aurelia.json
,
In aurelia.json
, you can control whether to use uglifyjs and whether to generate sourcemap, using a string targeting interested env. You can use your customised env name if you have added some in aurelia_project/environments/...
.
"options": {
"minify": "stage & prod",
"sourcemaps": "dev & stage"
},
In aurelia.json
, you can conditionally control prepend
, append
, and depdendencies
using env.
There are enough example in aurelia.json
if you generate a new app:
"prepend": [
"node_modules/bluebird/js/browser/bluebird.core.js",
{
"path": "node_modules/aurelia-cli/lib/resources/scripts/configure-bluebird-no-long-stacktraces.js",
"env": "stage & prod"
},
{
"path": "node_modules/aurelia-cli/lib/resources/scripts/configure-bluebird.js",
"env": "dev"
},
"node_modules/requirejs/require.js"
],
"dependencies": [
// ...
{
"name": "aurelia-testing",
"env": "dev",
// ...
},
// ...
]
You can also access environment name in your task files, check the usage in aurelia_project/tasks/transpile.js
let env = CLIOptions.getEnvironment();