0
votes

I'm currently working on an Angular 4 project using Webpack.

I'd like to be able to customize my app main colors.

All my components SCSS files import a file named color.scss containing colors variables.

@import "src/assets/sass/color";

I have two files:

  • src/assets/sass/_color.scss: default SCSS file.
  • src/custom/A/assets/sass/_color.scss: customized SCSS file for A.

I'd like to tell webpack to replace this url when resolving, depending on a parameter I pass.

Therefore, when I execute:

webpack-dev-server --env.custom=A

Webpack would change all the imports of color.scss to "src/custom/A/assets/sass/color".

Is it possible ? If it is, how can it be implemented ?

1
Can you @import "src/custom/A/assets/sass/color"; inside src/assets/sass/_color.scss then rebuild? - hayden
Yes but I cannot see how this would help. variables defined in the custom file are overriden by what it's defined in the main file. - Salah Elgo
Move the import to the bottom (or is it the top?) - hayden
Does the custom css have variables or css rules? - hayden
the default and custom SCSS have the same structure (set of variables). Only their values change. When moving the import at the bottom, It works. My app has the custom colors. But still, how can I tell webpack to add the import at the bottom of "src/assets/sass/color.scss" ? - Salah Elgo

1 Answers

0
votes

At the bottom of src/assets/sass/_color.scss

add @import "src/custom/A/assets/sass/color";

Then change A to when you want to swap colors.