Strangely, the loadPaths attribute doesn't work, what worked for me was using includePaths:
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: [path.resolve(__dirname, 'Develop', 'Styles')]
}
}
}
Answer from violetflare on Stack OverflowWhen using SASS how can I import a file from a different directory? - Stack Overflow
What does "A load path `loadpath`..." mean?
How to batch compile Sass with relative paths?
Accept multiple Sass load paths
UPDATE: Please consider Mikka's answer first - it should work without flaw if you're only interested in including subdirectories. My answer is specific to including directories other than subdirectories, but works for those, too. But: It's not the idiomatic way to do it.
Looks like some changes to SASS have made possible what you've initially tried doing:
@import "../subdir/common";
We even got this to work for some totally unrelated folder located in c:\projects\sass:
@import "../../../../../../../../../../projects/sass/common";
Just add enough ../ to be sure you'll end up at the drive root and you're good to go.
Of course, this solution is far from pretty, but I couldn't get an import from a totally different folder to work, neither using I c:\projects\sass nor setting the environment variable SASS_PATH (from: :load_paths reference) to that same value.
As per official docs, use the -I command line switch (abbreviated version of --load-path) or :load_paths option from Ruby code to add sub_directory_a to Sass's load path.
For example, if you're running Sass from root_directory, do something like this:
sass -I sub_directory_a --watch sub_directory_b:sub_directory_b
Then you can simply use @import "common" in more_styles.scss.
Note that it can be passed multiple times to provide multiple load paths e.g.
sass -I sub_directory_a -I sub_directory_b --watch sub_directory_b:sub_directory_b
Hi! I have a pretty big project that has lots of subfolders, each of which has an instance of SCSS/CSS files that need compiling. I've been using the sass npm package for a while now and I manually input each file in a large script, like this:
sass --watch --no-source-map --style compressed project1/src/scss/project1.scss:project1/src/css/project1.css project2/src/scss/project2.scss:project2/src/css/project2.css ...
This is obviously very inefficient as there are now at least 50 of those SCSS files in the project. I'm searching for a way to automate it using relative paths. I tried paths like these: **/src/scss/*.scss:**/src/css/*.css but couldn't find a way to make it work.
I can do it with a VS Code extension as it supports such filepaths, but I'd rather do it with the npm package. I might be missing something, any idea?
Thank you!