Currently, in my gulp setup, I have several CSS files being produced - a general 'core' one, and then template-specific stylesheets.
Instead of re-compiling all stylesheets with each change, the setup only compiles the necessary ones. However, this has resulted in complex "watch" paths that cover many files reflecting what's in the primary SCSS files for each template (which contain @use/@import statements).
I had an idea: rather than manually writing out all the watch filepaths, why not 'crawl' the SCSS file to automatically grab all the filepaths for any @use/@import statements recursively?
For example, let's take this "blog.scss" file:
// Variables
@import 'variables';
// Tools
@import './tools';
// Parts
@import './core/base';
@import './templates/blog';
Is there a way to extract all the filepaths for its @import statements? Like so:
'local-dev/styles/variables.scss'
'local-dev/styles/tools.scss'
'local-dev/styles/core/base.scss'
'local-dev/styles/templates/blog.scss'
I've thought about fetching the file as a string and using regex, but that wouldn't account for file extensions (.scss/.css/_partials.scss) and could lead to other issues.
Any suggestions or ideas are greatly appreciated.
Thanks in advance!