johan-v-r / LibSassBuilder

Sass builder for .NET projects
MIT License
99 stars 14 forks source link

Imports relative to project root #14

Open martinothamar opened 3 years ago

martinothamar commented 3 years ago

Hey, just started using this in a Blazor webassembly app. Working great, but when I want to import a another file for variables it doesn't work out too well. I have color variables in a top level folder which will be needed many places, and I would like to import relative to project root. This worked with the Delegate.SassBuilder project (@import 'wwwroot/variables.scss';), but since this library seems actively maintained and well designed I have switched to this library. Is there a way to do imports relative to project root currently? I.e.

johan-v-r commented 3 years ago

Hi Martin!

The resolving of @import directives are handled as part of the compilation process in LibSassHost - so might be best to check there...

In general if you can resolve the path & test with File.Exists("./filepath.scss") it should work. Looking at your examples I don't think they'll resolve because:

Delegate.SassBuilder actually wrapped another packaged tool sassc.exe for its compilation, and I really have no idea what magic happened there.

I've just been using relative paths @import '../../wwwroot/_variables.scss' which works fine. Hope this helps.

JelleHissink commented 3 years ago

It seems like it is linked to the current working directory for sassc.exe. We might be able to temporarily change the directory in lsb.exe and restore it afterwards? Pass the working directory as an option to lsb.exe?

martinothamar commented 3 years ago

Forgot to answer this :) Reason I prefer imports relative to root is it makes refactoring easier if files are moved around.

  • @import '/wwwroot/variables.scss'; - checks from root (not found)

I guess this is the scenario I would expect to work, in that this library compiles in context of the project, and the wwwroot folder is at the root of the project. I'm not familiar with LibSassHost (and limited experience with sass in general), but do you think the IncludePaths argument would help me here?

JelleHissink commented 3 years ago

Actually I was waiting/hoping for any progress on sass-dart progress, before starting work on this: https://github.com/Taritsyn/LibSassHost/issues/42#issuecomment-721210036

JelleHissink commented 3 years ago

https://github.com/Taritsyn/SassHost/issues/1

Seems that project has been postponed, currently I have limited time, otherwise I might check the current state of that commit.

JelleHissink commented 2 years ago

See pull request #30 If that is integrated, we could pick this issue up again.