萨斯SCSS由BundleTranslator [英] Sass SCSS by BundleTranslator
问题描述
我在我的 MVC成立了 BundleTranslator 5 透过的NuGet (BundleTransformer.SassAndScss v1.9.96与Core和LibSassHost组件项目)。接下来,我已经添加了捆绑参考我View.cshtml
@ Styles.Render(〜/内容/上海社会科学院)
和重新定义的 BundleConfig.cs
VAR nullOrderer =新NullOrderer();
VAR commonStylesBundle =新CustomStyleBundle(〜/内容/上海社会科学院);
commonStylesBundle.Include(〜/内容/自定义/最style.scss);
commonStylesBundle.Orderer = nullOrderer;
bundles.Add(commonStylesBundle);
构建之后,该网站有一个.scss参考:
<链接HREF =/内容/自定义/最style.scss的rel =stylesheet属性>
和一切工作本地可能只是因为我已经安装了 SassAndCoffee 包 SassyStudio 。当我部署外部IIS服务器上的问题出现了。该文件存在于内容/自定义目录,但该网站被打破了。该HTML code还具有文件引用(它链接到.scss文件,而不是编的CSS),但如果我试图找到它,我得到错误500。
我已经改变了萨斯文件的生成操作以内容的(从无的)和左复制到输出目录为不要复制的。我还增加了HttpHandlers的到Web.config中(但我居然不知道whatfor),但仍然没有什么帮助。
<&HttpHandlers的GT;
<添加路径=* SASS。动词=GETTYPE =BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler,BundleTransformer.SassAndScss/>
<添加路径=* SCSS。动词=GETTYPE =BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler,BundleTransformer.SassAndScss/>
< / HttpHandlers的>
我没有检查所有的设置中的的Web.config 因为安装的NuGet它(因为我看到)提供了这样的数据,对BundleTransformer。
的我怎么配置在 BundleTransformer 以正确的 IIS 工作?我必须重写 BundleResolver 与在例如code ?
BundleResolver.Current =新CustomBundleResolver();
有几件事情来尝试诊断问题。首先,它在本地工作! :)
1 结果
值得一测试,你的捆绑正常工作。您可以通过暂时设置以下的做到这一点(借此出去当你完成)。
公共类BundleConfig
{
公共静态无效RegisterBundles(BundleCollection包)
{
BundleTable.EnableOptimizations = TRUE; //包和东西...
}
}
运行该网站,然后在浏览器开发工具,你应该得到的东西是这样的:
/包/ commonStyles?V = BzJZwKfP1XV8a6CotGRsHhbxraPDst9zDL2X4r36Y301
块引用>如果这工作那么我们可高兴了捆绑在生产环境中工作。
2 结果
权限。如果你得到一个500内部服务器错误,请检查包含SCSS
文件的文件夹的权限。还要检查他们在那里:)3。结果
MIME类型。可能有轻微的机会IIS需要增加了对.scss
MIME类型,但我不相信它会。I have set up the BundleTranslator in my MVC 5 project via NuGet (BundleTransformer.SassAndScss v1.9.96 with the Core and LibSassHost components). Next I have added the bundle reference to my View.cshtml
@Styles.Render("~/Content/sass")
and redefined the BundleConfig.cs:
var nullOrderer = new NullOrderer(); var commonStylesBundle = new CustomStyleBundle("~/Content/sass"); commonStylesBundle.Include("~/Content/Custom/the-style.scss"); commonStylesBundle.Orderer = nullOrderer; bundles.Add(commonStylesBundle);
After build, the website has a .scss reference:
<link href="/Content/Custom/the-style.scss" rel="stylesheet">
and everything is working locally probably only because I have installed SassAndCoffee package with SassyStudio. The problem emerges when I deploy on external IIS server. The file exists in the Content/Custom directory, but the website is broken. The HTML code also has the file reference (it links to .scss file, not compiled .css) but if I try to navigate to it, I get error 500.
I have changed the Sass file Build Action to Content (from None) and left Copy to Output Directory as Do not copy. I have also added httpHandlers to Web.config (but I actually don't know whatfor) but still nothing helps.
<httpHandlers> <add path="*.sass" verb="GET" type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" /> <add path="*.scss" verb="GET" type="BundleTransformer.SassAndScss.HttpHandlers.SassAndScssAssetHandler, BundleTransformer.SassAndScss" /> </httpHandlers>
I didn't check all of the settings in Web.config because of the NuGet installation which (as I see) provides this kind of data for the BundleTransformer.
How do I configure the BundleTransformer to work correctly on IIS? Do I have to override the BundleResolver as in example code?
BundleResolver.Current = new CustomBundleResolver();
解决方案There are a few things to try to diagnose the problem. Firstly it works locally! :)
1.
It is worth testing that your bundling works correctly. You can do this by temporarily setting the following (take this out once you have finished).public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { BundleTable.EnableOptimizations = true; // Bundles and stuff... } }
Run the site and then in your browser dev tools you should get something like this:
/bundles/commonStyles?v=BzJZwKfP1XV8a6CotGRsHhbxraPDst9zDL2X4r36Y301
If this works then we can be happy bundling will work in production.
2.
Permissions. If your getting a 500 internal server error, check the permissions on the folder that contains thescss
files. Also check they are there :)3.
Mime type. There may be a slight chance that IIS needs a mime type added for.scss
, but I'm not convinced it will.这篇关于萨斯SCSS由BundleTranslator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!