Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Imports relative to project root #14

Open
martinothamar opened this issue Mar 2, 2021 · 6 comments
Open

Imports relative to project root #14

martinothamar opened this issue Mar 2, 2021 · 6 comments

Comments

@martinothamar
Copy link

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.

  • @import 'wwwroot/variables.scss';
  • @import '/wwwroot/variables.scss';
  • @import '~/wwwroot/variables.scss';
@johan-v-r
Copy link
Owner

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:

  • @import 'wwwroot/variables.scss'; - checks in same directory (not found)
  • @import '/wwwroot/variables.scss'; - checks from root (not found)
  • @import '~/wwwroot/variables.scss'; - virtual directory (don't think this is resolving correctly, I'm not sure how to either 🤷 )

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

Actually I was waiting/hoping for any progress on sass-dart progress, before starting work on this:
Taritsyn/LibSassHost#42 (comment)

@JelleHissink
Copy link
Contributor

JelleHissink commented Mar 15, 2021

Taritsyn/DartSassHost#1

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

@JelleHissink
Copy link
Contributor

JelleHissink commented Sep 15, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants