In my current project using Angular 4 and webpack 3 for bundling, I am working on implementing a CSS theming feature. This project is designed to be used by multiple companies, each with their own brand guidelines that need to be reflected in the design. To achieve this, we require the ability to switch between different themes easily.
Instead of creating separate versions of code for each theme, we aim to keep all themes within the same codebase. The differences between themes will mainly involve changes to colors, icons, fonts, and other styling elements that can be adjusted through CSS.
I have considered various methods to implement theming, such as using :host-context for components and changing the body class based on environment variables in webpack. However, including every theme inside the bundle may not be the most efficient approach. I am exploring alternative options.
One idea I have been considering is having webpack dynamically load CSS files based on a certain pattern rather than loading specific files. For instance, when a component like button.component.ts imports button.component.css, webpack could check for a file named button.component.theme-name.css in the directory. If this file exists, it would be imported instead or alongside the default CSS file.
This concept extends beyond CSS files and could also apply to HTML templates in angular components. I am curious if there are plugins or advanced loader configurations that could facilitate this dynamic loading process.
If you have any insights or suggestions on how to approach this task differently, please share your thoughts in the comments!