2

我试图为我的应用程序捆绑脚本和样式引导程序。我的调试正在运行但是当我发布它时,不要加载脚本和样式。

我添加了一个 BundleConfig (BootstrapBundleConfig)

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/js").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-ui-1.10.4.custom.js",
            "~/Scripts/jquery-migrate-{version}.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/gridmvc.js",
            "~/Scripts/gridmvc.lang.fa.js",
            "~/Scripts/jquery.validate.js",
            "~/scripts/jquery.validate.unobtrusive.js",
            "~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js",
            "~/scripts/entitypicker.js",
            "~/scripts/js-persian-cal.js",
            "~/scripts/json2.js",
            "~/scripts/bootbox.js",
            "~/Scripts/jalali.js",
            "~/Scripts/calendar.js",
            "~/Scripts/calendar-setup.js",
            "~/Scripts/lang/calendar-fa.js"
            ));
        bundles.Add(new StyleBundle("~/content/css").Include(
             "~/Content/bootstrap.css",
             "~/Content/bootstrap-responsive.css",
             "~/Content/bootstrap-mvc-validation.css",
             "~/Content/themes/ui-lightness/jquery-ui.css",
             "~/Content/js-persian-cal.css",
             "~/Content/entitypicker.css",
             "~/Content/gridmvc.css",
             "~/Content/aqua/theme.css",
             "~/Content/calendar-system.css"
            ));

    }

在 Global 中添加注册

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

并在 _layout 中设置样式/脚本

<link href="@Styles.Url("~/content/css")" rel="stylesheet" />
@Scripts.Render("~/js")

但是当发布它,并打开查看页面源

    <link href="/Content/css?v=65vDyivXbF9ucPBBLls9CVnwUcCNass7hOMNUEXbN-I1" rel="stylesheet" />

当打开此文件时,第一行出现错误。

/* Minification failed. Returning unminified contents.
(962,1): run-time error CSS1019: Unexpected token, found '@charset'
(962,10): run-time error CSS1019: Unexpected token, found '"UTF-8"'
(962,17): run-time error CSS1019: Unexpected token, found ';'
(994,1): run-time error CSS1019: Unexpected token, found '@-webkit-keyframes'

我在谷歌搜索并使用了不同的方法,但错误没有解决。

  1. 将所有样式添加到特殊路径(Content/Them/Bootstrap)并使用new StyleBundle("~/content/Them/Bootstrap")

  2. 利用BundleTable.EnableOptimizations = true;

其他..

4

4 回答 4

1

这就是罪魁祸首@charset "UTF-8"。搜索您的 css 文件,看看是否可以找到它。这需要位于捆绑的 css 文件的顶部。即在捆绑列表中第一个 CSS 文件的顶部。如果不是,它将无法缩小。

当 CSS 文件中有 Unicode 字符时,通常使用它。这通常是因为使用了像 font awesome 这样的图标字体。但是,如果您的 CSS 文件中不需要它,则只需将其取出即可。

于 2014-07-15T11:41:50.253 回答
1

如果您的 css 文件格式不正确,通常会发生这种情况,请使用http://csslint.net/将您的 css 代码进行测试。

也不是使用这条线

<link href="@Styles.Url("~/content/css")" rel="stylesheet" />

你可以用这个

@Styles.Render("~/content/css")

如果您想在不发布的情况下进行调试,可以将此行添加到您的RegisterBundles方法中BundleConfig

BundleTable.EnableOptimizations = true;
于 2014-07-15T06:53:52.270 回答
0

缩小时,您的 css 有一些“问题”。这可能是因为糟糕的 CSS 或糟糕的优化。

尝试验证你的 CSS,看看你是否能找出罪魁祸首。

对于BundleTable.EnableOptimizations = false不会缩小 css 的解决方法。

要在本地主机上“调试”它,请更改您的 Web 配置并删除属性 debug=true (这将使您的 css 在您的开发机器上缩小)

此外,基于您的捆绑包具有不同的文件夹将使样式表上的任何相对 url(如背景图像)都不起作用。

于 2014-07-15T06:44:04.810 回答
0

https://stackoverflow.com/a/19544226/2440976 - 我相信这是一个重复的问题 - 这可能是简单的答案(它对我有用!)

(来自答案)IIS Config>Authentication>RightClickOn Anonymous Auth>Click Edit> Check Application pool identity

于 2016-12-16T14:59:20.543 回答