TL;DR: My question is how to bundle some of my sass files into single sass file?
I've been developing an Angular component library and I package it with ng-packagr. Let's call it @my-lib/ngx-components
.
Consumers of my lib will import my components like @my-lib/ngx-components/navbar
.
I decided to add theming support to components.
For example, I have a navbar component with default colors (background, text, hover etc.) I want consumers of my library to be able to override these colors with their own theme. That's why I've written a mixin
which takes a $theme
input and override some css rules as follows (this is a basic version of what I have)
_navbar-theme.sass
@mixin navbar-theme($theme)
$primary-color: map-get($theme, primary-color)
$secondary-color: map-get($theme, secondary-color)
$color: map-get($theme, color)
.navbar
background-color: $primary-color
color: $color
&:hover
background-color: $secondary-color
Each component has its own *-theme.sass
file.
I also have global _theming.sass
file which imports all of these as follows
_theming.sass
@import './components/navbar/navbar-theme'
@import './components/button/button-theme'
@import './components/dropdown/dropdown-theme'
I want to export this _theming.sass
file from my lib, so people can import this file in their own sass
file as @import '~@my-lib/ngx-components/theming'
and start using all of the mixin
s available.
If they want to have custom navbar
, button
etc, they should be able to use those mixin
s with single import.
I tried to make it look like angular-material theming setup.
At first, I have tried node-sass
which is already in my dependencies. But, it tries to build sass into css so it omits mixins in the output file.
Then, I looked at what angular-material has done. They use scss-bundle
I thought "this is exactly what I want." However, it requires scss
files, not sass
files. It cannot read sass
files.
Then, I thought "Okay, I can give up on sass and start using scss. How do I convert all those files to scss without going through them by hand". Then, I found sass-convert. In this question it was said that I can use it within command line. However, when I install sass-convert
with npm globally, it didn't give me a command line executable. I think I need Gulp
to use it.
I've been avoding to use Gulp
from the beginning, because it means another tool to learn and it adds complexity to codebase.
At this point, I feel like "Hal fixing light bulb"
TL;DR: My question is how to bundle some of my sass files into single sass file?
Also, If you can come up with a solution that requires webpack, that's fine too.