Compiling scss files in ASP.NET MVC action

- any alternatives for compiling .scss files in action in an ASP.NET MVC controller?

I have a / folder with two files: main.scss and external.scss. In my controller, I use the NSASS package:

public ActionResult GetCss(string scssPath) { string scss = @"@import """ + Server.MapPath(scssPath) + @""";"; var compiler = new SassCompiler(); string compiled = compiler.Compile(source: scss); return Content(compiled.ToString(), "text/css"); } 

my opinion:

 <link href="@Url.Action("GetCss", "Theme", new { scssPath="~/Content/sass/main.scss" })" rel="stylesheet" type="text/css" /> 

main.scss file:

 @import "external"; 

I have a mistake

Error: import file not found or unreadable: external

I tried to write @import "external.scss", but the same problem.

0
source share
1 answer

We have the same (or similar problem). The problem I see is that SassCompiler is trying to find @import files relative to the current working directory, and not relative to the file that @import contains.

There may be several ways, depending on what you are trying to do.

My workaround was to create a temporary copy of the directory structure and then update all the @import statements in each file to make them relative to the working directory before compiling.


UPDATE I got this working without this hack, passing all the paths to the "includePaths" parameter. I tried this before, but I used relative paths. If you use absolute paths, then it works.

+1
source

Source: https://habr.com/ru/post/975027/


All Articles