gpt4 book ai didi

asp.net-mvc-4 - 仅在 mvc4 中启用捆绑而不是缩小

转载 作者:行者123 更新时间:2023-12-02 04:59:44 24 4
gpt4 key购买 nike

我正在 MVC4 中实现捆绑和缩小,但当我在 IIS 服务器上部署时它不起作用。我在 BundleConfig.cs 中使用了以下代码

public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/styles/siteCss").Include("~/Content/styles/reset.css"));
bundles.Add(new ScriptBundle("~/siteJsCommon").Include("~/Scripts/html5.js",
"~/Scripts/jquery.js",
"~/Scripts/jquery-migrate-1.1.1.js",
"~/Scripts/jquery-ui-1.10.3.custom.js",
"~/Scripts/carousel.js",
"~/Scripts/template.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/additional-methods.js",
"~/Scripts/function.js"));

BundleTable.EnableOptimizations = true;
}

即使我检查了我的 web.config。看起来不错。

<compilation debug="false" targetFramework="4.5" />

谁能告诉我哪里做错了。是否可以仅启用 bundle ?

谢谢阿树

最佳答案

没有内置的配置/选项允许您在不缩小的情况下启用捆绑。

但是,Bundle(脚本或样式)使用 IBundleTransform:Microsoft.Web.Optimisation 包括两个默认转换类型 JsMinify 和 CssMinify,分别由 ScriptBundle 和 StyleBundle 使用。但是,我们可以根据需要创建自己的自定义转换类型来处理引用,或者最好不要使用 IBundleTransform

因此,要在不缩小的情况下启用捆绑,我们可以尝试这样做:

    //somewhere after all bundles are registered 
foreach (var bundle in bundles)
{
bundle.Transforms.Clear();
}

关于asp.net-mvc-4 - 仅在 mvc4 中启用捆绑而不是缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17648609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com