I need to customize my angular 6 application to change a primary color depending on build (I have to change primary color to another one on dev and production). Is there any straightforward solution to change the color on build?
Asked
Active
Viewed 1,136 times
2 Answers
3
You can use css custom properties to change a css value dynamically.
Setup e. g. in AppModule
's constructor:
let primaryColor: string;
if (environment.production) {
primaryColor = 'green';
} else {
primaryColor = 'red';
}
document.documentElement.style.setProperty('--primary-color', primaryColor);
And then use the value in your css with:
color: var(--primary-color)
For a SASS solution, have a look at this answer.

Kim Kern
- 54,283
- 17
- 197
- 195
-
1Great! The SASS solution is what I was looking for! Thank you very much :) – Jaume Jul 03 '18 at 13:22
2
Please check this reported issue, it seems that version 6.1 will support file replacements other than just typescript files.
If yes, you should be able to replace your my-own-theme.scss
depending on configuration profile. (defined inside angular.json)

Thierry Falvo
- 5,892
- 2
- 21
- 39