【问题标题】:ASP.Net MVC C# with Toastr not minifing javascript带有 Toastr 的 ASP.Net MVC C# 没有缩小 javascript
【发布时间】:2013-06-14 07:22:49
【问题描述】:

我正在使用 ASP.Net MVC 4 - 并尝试使用 Toastr。

我通过 NuGet 安装它 - 它在开发中工作,但是,当我发布时,我的 Javascript“捆绑”报告:

/* Minification failed. Returning unminified contents.
(9908,1-2): run-time warning JS1002: Syntax error: }
 */
/*!
* jQuery JavaScript Library v1.8.3
* http://jquery.com/

我的捆绑文件是:

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-1.10.1.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/jquery.tablesorter.js",
             "~/Scripts/toastr.js",
            "~/Scripts/mt.js"
            ));

        bundles.Add(new StyleBundle("~/content/css").Include(
            "~/Content/bootstrap.css",
            "~/Content/body.css",
            "~/Content/bootstrap-responsive.css",
            "~/Content/bootstrap-mvc-validation.css",
             "~/Content/style.css",
             "~/Content/toastr.css"

            ));
    }
}
}

如果我从上面的包中取出 Toastr,其他一切都可以正常工作。

您知道如何解决这个问题吗?

谢谢,马克

【问题讨论】:

  • 嗨 - 这不是修复,而是一种解决方法 - 如果我将代码从 toastr.js 复制到 toastr.min.js 文件中 - 然后它可以工作 - 所以看起来可能有两个文件之间的差异(当然除了一个被缩小的文件!!)
  • 将其重命名为 toastr.min.js 时观察到的行为是因为 Bundling & Minification 组件具有不缩小具有 *.min.js 模式的文件的约定。这就是为什么您看不到错误出现的原因。它只是按原样输出文件内容。

标签: c# javascript jquery asp.net asp.net-mvc


【解决方案1】:

看起来 toastr 有一些语法错误,例如缺少分号,这会影响缩小过程。您可以尝试以下两件事:

  1. 检查是否有更新版本的 toastr。
  2. 通过http://www.jslint.comhttp://jshint.com/ 传递文件,看看它揭示了什么。

更新: 我尝试使用 toastr v1.3.1(通过 NuGet 下载)重现您的问题,但没有遇到任何问题。

【讨论】:

    猜你喜欢
    • 2014-02-14
    • 2014-04-16
    • 2011-04-16
    • 2011-06-28
    • 2018-06-21
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多