CssRewriteUrlTransform

CssRewriteUrlTransform

本文介绍了没有调用 CssRewriteUrlTransform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 VS 2013 RTM 上创建了一个新的 MVC 5 应用程序.由于某种原因,我的 CSS 文件中的背景图片 url 没有被转换.

I just created a new MVC 5 app on VS 2013 RTM. For some reason background image url in my CSS files were not being transformed.

因此,为了调试问题,我创建了自定义 CssRewriteUrlTransform 包装器.我发现我的断点没有被调用.

So, to debug the issue, I created my custom CssRewriteUrlTransform wrapper. And I found that my breakpoint is not being called.

这是我在 BundleConfig.cs 中的内容

This is what I have in my BundleConfig.cs

using System.Web.Optimization;

namespace Utilities.Web
{
    public class BundleConfig
    {
        private const string JQUERY_CDN_URL = "//code.jquery.com/jquery-1.10.1.min.js";

        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.UseCdn = true;
            BundleTable.EnableOptimizations = true;

            bundles.Add(new StyleBundle("~/css/coming-soon")
                .Include("~/Content/Site/coming-soon.css",
                    new CssRewriteUrlTransformWrapper()));

            bundles.Add(new ScriptBundle("~/js/coming-soon")
                .Include("~/Scripts/jquery.placeholder.js")
                .Include("~/Scripts/Site/coming-soon.js"));

            bundles.Add(new ScriptBundle("~/js/jquery", JQUERY_CDN_URL)
            {
                CdnFallbackExpression = "window.jQuery"
            }.Include("~/Scripts/jquery-{version}.js"));
        }
    }

    public class CssRewriteUrlTransformWrapper : IItemTransform
    {
        public string Process(string includedVirtualPath, string input)
        {
            return new CssRewriteUrlTransform().Process(includedVirtualPath, input);
        }
    }
}

推荐答案

如果您有 CSS 的缩小版本,转换似乎不会运行.删除 .min.css 文件,它应该可以开始工作了.

It appears the transform does not run if you have the minified version of the CSS. Remove the .min.css file and it should start working.

这篇关于没有调用 CssRewriteUrlTransform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:14