本文介绍了什么是用于校正CSS捆绑与路径的ASP.NET Web优化BundleTransformer正确使用IItemTransform的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是presently工作使用的扩展(一起库(1.1.0-β1)v 1.7。 3-β1为用来LESS转换成的CSS芯,1.7.0-β1为更小)。
基于Web搜索路径的CSS内(和更低)似乎是一个共同的问题,在大多数情况下,建议手动修改CSS并用它来完成。然而,由于我们的开发和生产环境,并没有差异的拥有的受影响的CSS这样的解决方案是不可行的。

I'm presently working on a project that uses the ASP.NET Web Optimization library (v 1.1.0-Beta1) in conjunction with the Bundle Transformer extension (v 1.7.3-Beta1 for core, 1.7.0-Beta1 for LESS) which is used to convert LESS into CSS. Based on web searches paths within CSS (and less) appear to be a common issue, in most cases it is recommended to manually modify the CSS and be done with it. However, due to differences between our development and production environment, and not owning the affected CSS such a solution is not feasible.

两种解决方案似乎存在。首先是要覆盖由捆绑在包含该内容的实际目录所限定的虚拟目录。对我来说,这似乎是一个糟糕的选择。

Two solutions seem to exist. The first is to overlay the virtual directory as defined by the bundling over the actual directory that contains the content. To me this seems like a poor option.

第二,我选择的路线,是使用 IItemTransform CssRewriteUrlTransform (中提及。即使这个解决方案有它的的。因此,我试图写我自己的 ItemTransformer 但似乎它的结果的执行是以下面的方式使用时,忽略:

Secondly, and the route I've chosen, is to use a IItemTransform such as CssRewriteUrlTransform (mentioned in this post. Even this solution has it's limitations. As such I've attempted to write my own ItemTransformer but it seems that the results of it's execution is ignored when used in the following manner:

public static void RegisterBundles(BundleCollection bundles)
{
    /* among other work pass in IItemTransformer to fix paths */
    var styleBundle = new StyleBundle("~/bundles/css/styles")
        .Include(...)
        .Include("~/Content/less/font-awesome.less", new RewriteUrlTransform())
        .Include(...);

    styleBundle.Transforms.Add(new CssTransformer());
    styleBundle.Orderer = new NullOrderer();

    bundles.Add(styleBundle);
}

IItemTransform的执行情况:

Implementation of IItemTransform:

public class RewriteUrlTransform : IItemTransform
{
    public string Process(string includedVirtualPath, string input)
    {
        return (input manipulated with proper path replacing bad path)
    }
}

除非我完全误解了 IItemTransform 是如何被使用,这是相当可能的,因为缺少文件,我会觉得过程方法的返回是新的后处理CSS。然而,返回似乎被忽略。原来的输入的始终是在使用,甚至当我返回的String.Empty()。我在这里做得不对或者是它确实是一个错误吗?

Unless I'm entirely misunderstanding how an IItemTransform is to be used, which is quite possible due to lack of documentation, I would think that the return of the Process method is the new post processed CSS. However, the return seems to be ignored. The original input is always in use, even when I return a String.Empty(). Am I doing something wrong here or is it indeed a bug?

推荐答案

没有你正在正确地理解这一点,该项目变换被应用到一个项目它们捆绑前在一起,然后束变换被执行。您是否已经验证它呼唤你,当你在调试器期望转换?

No you are understanding this correctly, the item transforms are applied to an item before they are bundled together, and then the bundle transforms are run. Have you verified that it is calling your transform when you expect in the debugger?

这篇关于什么是用于校正CSS捆绑与路径的ASP.NET Web优化BundleTransformer正确使用IItemTransform的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:15