The Ionic
framework uses Angular
.
Angular 6 defines environments in ./src/environments/environment.stage.ts
.
When building an Angular app, I can select the environment with the parameter --env=stage
or --configuration==stage
in Angular 6.
To build the ionic app, I use ionic cordova build <platform>
which in the background first builds the angular app, before packing it in the Cordova framework.
How can I specify the environment aka configuration for the angular build?
Ionic Angular offers Angular-optimized mobile and web components for building blazing fast mobile, web, and desktop apps.
Open your command window and choose where you want to create your app. This command will change the working directory. The app will be created on the Desktop. Ionic Start command will create a folder named myApp and setup Ionic files and folders.
An Angular Application Environment is JSON configuration information that tells the build system which files to change when you use ng build and ng serve . Let's say you have a back end REST API deployed on a server that provides services to your Angular application.
Click “Advanced System Settings”. Select Environment Variables. Select New environment variable. In the new window, in the name of the variable place JAVA_HOME, and in the value put the path where you installed the JDK.
You can add a corresponding configuration entry in angular.json at ionic-cordova-build:
"ionic-cordova-build": {
"builder": "@ionic/angular-toolkit:cordova-build",
"options": {
"browserTarget": "app:build"
},
"configurations": {
"production": {
"browserTarget": "app:build:production"
},
"staging": {
"browserTarget": "app:build:staging"
}
}
},
$ ionic cordova run android --device -c staging
Note the difference from -c staging
to -- -c=staging
on ionic serve.
The configuration staging must exists under architect.build.configurations
in the same file.
On my hand, I created a simple bash file.
#!/usr/bin/env bash
env=$1
targetFile=$PWD/src/environment/environment.ts
filePath=$PWD/src/environment/$1.environment.ts
echo REPLACING FILE ENVIRONMENT : $1
cp $filePath $targetFile
I added environment.ts
in .gitignore, and I created a dev.environment.ts
and prod.environment.ts
.
I switch :
$ bash launcher.sh dev && ionic serve
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With