After creating a new Aurelia Typescript application using the au new
command from the Aurelia CLI, I noticed that there is a config
directory at the root of the project. Inside this directory, there are two files: environment.json
and environment.production.json
. Here is how mine are configured:
environment.json
{
"debug": true,
"testing": true,
"stringVal": "Hello World"
}
environment.production.json
{
"debug": false,
"testing": false,
"stringVal": "Hello Production"
}
I am looking to have the ability to switch between configurations when running the application from the command line. Below are my current app.ts and app.html files:
app.ts
import environment from '../config/environment.json';
export class App {
public message = environment.stringVal;
}
app.html
<template>
<h1>${message}</h1>
</template>
Additionally, here is my main.ts file:
import {Aurelia} from 'aurelia-framework';
import environment from '../config/environment.json';
import {PLATFORM} from 'aurelia-pal';
export function configure(aurelia: Aurelia): void {
aurelia.use
.standardConfiguration()
.feature(PLATFORM.moduleName('resources/index'));
aurelia.use.developmentLogging(environment.debug ? 'debug' : 'warn');
if (environment.testing) {
aurelia.use.plugin(PLATFORM.moduleName('aurelia-testing'));
}
aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}
- What code changes are needed to read stringVal from a different configuration file without hard-coding the import?
- Which flags should be used with
au run
ornpm start
in the command line to specify the desired configuration?