简体   繁体   English

jQuery无法在asp.net MVC中缩小

[英]jQuery not minifying in asp.net MVC

I'm using ASP.Net MVC. 我正在使用ASP.Net MVC。

For some reason my JS files are NOT minifying. 由于某些原因,我的JS文件没有缩小。 My CSS is minifying fine. 我的CSS缩小了。

My CSS minifies to: <link href="/ffee/content/css?v=vaNo49ei5GzRQAYnj-AD-AbQI3GKNs2OZ8q6-oJEEvk1" rel="stylesheet"> but all of my JS files are listed separately in the source. 我的CSS缩小为: <link href="/ffee/content/css?v=vaNo49ei5GzRQAYnj-AD-AbQI3GKNs2OZ8q6-oJEEvk1" rel="stylesheet">但是我的所有JS文件均在源代码中单独列出。

I am compiling and publishing in Release mode. 我正在发布模式下进行编译和发布。

Can anyone please advise on how I can resolve this please? 有人可以建议我如何解决这个问题吗?

Thank you, 谢谢,

Mark 标记

BootstrapBundleConfig.cs BootstrapBundleConfig.cs

using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;

namespace BootstrapSupport
{
public class BootstrapBundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/js").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-migrate-{version}.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/jquery.validate.js",
            "~/scripts/jquery.validate.unobtrusive.js",
            "~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js",
            "~/Scripts/knockout-2.2.0.js",
            "~/Scripts/bootstrap-combobox.js",
             "~/Scripts/select2.js"
            ));

        bundles.Add(new ScriptBundle("~/mt").Include(
           "~/Scripts/bootstrap-datepicker.js",
                            "~/Scripts/mtDateEdit.js",
                            "~/Scripts/jquery-te-1.4.0.js"
                            //"~/Scripts/tinymce/tinymce.js"
                            ));

        bundles.Add(new StyleBundle("~/content/css").Include(
            "~/Content/bootstrap.css",
            "~/Content/body.css",
            "~/Content/bootstrap-responsive.css",
            "~/Content/bootstrap-mvc-validation.css",
            "~/Content/bootstrap-combobox.css",
             "~/Content/select2.css",
            "~/Content/datepicker.css",
            "~/Content/jquery-te-1.4.0.css"
            ));
    }
}
}

Global.asax.cs Global.asax.cs

   public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();

        BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);

        BootstrapMvcSample.ExampleLayoutsRouteConfig.RegisterRoutes(RouteTable.Routes);
        RegisterViewMapper();
    }

_Bootstrap.Layout.Basic.cshtml - at the bottom of the file: _Bootstrap.Layout.Basic.cshtml-在文件底部:

 <div class="container">
     @Scripts.Render("~/js")
     @Scripts.Render("~/mt")
     @RenderSection("Scripts", required: false)

     @Html.Partial("_alerts")
     @Html.Partial("_validationSummary")
     @RenderBody()   

 </div>

You can force it for only release mode just add below code in Application_Start 您可以将其强制为仅发布模式,只需在Application_Start中添加以下代码

 #if RELEASE            
        BundleTable.EnableOptimizations = true;            
 #endif

Try forcing it with BundleTable.EnableOptimizations = true; 尝试使用BundleTable.EnableOptimizations = true;强制它BundleTable.EnableOptimizations = true;

If there are minification/bundling errors, as you state, remove one by one the *.js files from the bundle, until you find the offending one. 如您陈述的那样,如果存在缩小/捆绑错误,请从捆绑软件中一一删除*.js文件,直到找到有问题的文件。 Once you do find it, try adding a linefeed to the top and the end of this file. 找到它后,请尝试在该文件的顶部和底部添加换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM