Eventually a found this question, witch lead me to the solution.
It says to create multiple apps with different .scss
file in .angular-cli.json
.
Step 1:
Create several folders with .scss
file for each environment, all the .scss
files has the same filename:
|- src
...
|- environments
|- app1
|- scss
|- globalVars.scss
|- environment.dev.ts
|- environment.prod.ts
|- app2
|- scss
|- globalVars.scss
|- environment.dev.ts
|- environment.prod.ts
...
in src/environments/app1/scss/globalVars.scss:
$profile: 'app1'.
in src/environments/app2/scss/globalVars.scss:
$profile: 'app2'.
Step 2:
Add multiple apps in .angular-cli.json
( Angular-cli Wiki Here
), and add stylePreprocessorOptions
entry in each app object for
each environment ( Angular-cli Wiki Here ).
"apps": [
{
...
"name": "app1",
"environments": {
"dev": "environments/app1/environment.dev.ts",
"prod": "environments/app1/environment.prod.ts"
},
"stylePreprocessorOptions": {
"includePaths": [
"environments/app1/scss"
]
}
...
},
{
...
"name": "app2",
"environments": {
"dev": "environments/app2/environment.dev.ts",
"prod": "environments/app2/environment.prod.ts"
},
"stylePreprocessorOptions": {
"includePaths": [
"environments/app2/scss"
]
}
...
},
...
],
Step 3:
Import the globalVars.scss
where the env-specific variables needed.
Do not use the relative path!
@import "globalVars";
When using ng build --app=app1
, the $profile
will be 'app1'
and so on.
Step 4:
On my theme.scss
i used the variable like this:
.my-style {
@if $profile == 'app1' {@include angular-material-theme($theme-app1);}
@if $profile == 'app2' {@include angular-material-theme($theme-app2);}
&.contrast {
@include angular-material-theme($theme-contrast);
}
}