So I have a folder that contains many scss files. I used to @import them all into one big main.scss file. But with time, the file got bigger and it now takes more than 20 sec to see the result of the change after the whole file is re-compiled.
I'd like to use Grunt to watch scss files, recompile only the one that changed, and refresh the page with something like grunt serve
.
In dev, the html page should have as many <link>
tags as there are scss files.
In prod, i want to be able to concatenate them all into one main.css file with something like grunt build
Also, please note that I have some variables.scss files that can potentially be used in any of the partials. So they should have access to those variables as well.
I don't quite know where to start. Any help would be much appreciated.
The anwser heavily dependes on two factor: what framework (or none) do you use (I guess you're using
node
) and how do you structure your files.There are a lot of defferent practices on how to structure your
sass
project. Here are some links: sassway, sitepoint, yeoman generator. I am using the following structure:The benefit of having
module.scss
in each module is that it is easy to load just the required styles for a single module. And it is easy to include it to themain.scss
. I have twosass
task, which are defined like so:In my templates (I am using Django) I have the following setting:
For other frameworks there are different options like this one.
Alternatevly, there is an intresting grunt-task, called grunt-usemin. Take a look at it.
Was it helpful for you?