本文介绍了编译在ASP.NET MVC行动SCSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于编译.scss文件行动ASP.NET MVC控制器的任何替代方案?

are any alternatives for compile .scss files in action in ASP.NET MVC controller?

我有两个文件/文件夹的内容:main.scss和external.scss。在我的控制器我使用NSASS包:

I have /Content folder with two files: main.scss and external.scss. In my controller I'm using 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");
    }

我的观点:

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

main.scss文件:

main.scss file:

@import "external";

我有误差

错误:要导入的文件找不到或无法读取:外部

我试着写@importexternal.scss,但同样的问题。

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

推荐答案

我们有相同(或类似的问题)。我看到的问题是,SassCompiler尝试,而不是相对于包含@import文件来查找文件@import相对于当前的工作目录。

We have the same (or similar problem). The problem I'm seeing is that SassCompiler is trying to find the @import files relative to the current working directory, instead of relative to the file which contains the @import.

有可能会解决这个几个方法取决于你想做什么。

There might be a few ways around this depending on what you're trying to do.

我的解决方法包括制作目录结构的临时副本,然后更新每个文件中的所有的@import声明编译之前,使它们相对于工作目录。

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

更新
我在所有的路径传递到的includepaths'参数得到了这个工作没有这个技巧。我没有成功尝试过,因为我是使用相对路径。如果您使用绝对路径,然后它工作。

UPDATEI got this working without this hack by passing in all the paths to the 'includePaths' parameter. I had tried this before without success because I was using relative paths. If you use absolute paths then it works.

这篇关于编译在ASP.NET MVC行动SCSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:26