缩小失败.返回未经授权的内容

Whi*_*ler 31 asp.net asp.net-mvc

我已经做了我的第一个网站使用MVC 5这在我的本地机器上工作正常,但当我把它发布到服务器的一些CSS的不正确加载.

/* Minification failed. Returning unminified contents.
(80,1): run-time error CSS1019: Unexpected token, found '@import'
(80,9): run-time error CSS1019: Unexpected token, found 'url('../Content/dark-skin/skin.css')'
(671,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
(1288,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
(1680,1): run-time error CSS1019: Unexpected token, found '@keyframes'
(1682,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
(1685,1): run-time error CSS1019: Unexpected token, found '@-webkit-keyframes'
(1687,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
 */
/* NUGET: BEGIN LICENSE TEXT
 *
 * Microsoft grants you the right to use these script files for the sole
 * purpose of either: (i) interacting through your browser with the Microsoft
 * website or online service, subject to the applicable licensing or use
 * terms; or (ii) using the files as included with a Microsoft product subject
 * to that product's license terms. Microsoft reserves all other rights to the
 * files not expressly granted by Microsoft, whether by implication, estoppel
 * or otherwise. The notices and licenses below are for informational purposes only.
 *
 * NUGET: END LICENSE TEXT */
/*!
 * Bootstrap v3.0.0
 *
 * Copyright 2013 Twitter, Inc
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Designed and built with all the love in the world by @mdo and @fat.
 *//*! normalize.css v2.1.0 | MIT License | git.io/normalize */
Run Code Online (Sandbox Code Playgroud)

我知道编译器正在尝试最小化css文件但是没有这样做.我试图纠正这些错误,但在纠正其中一些并再次发布后,错误看起来是一样的,就像没有选择我的更改.

甚至最奇怪的是bootstrap.css文件,我为了网站的目的稍作修改.当我发布它时,更改不在bundle文件中.是否有可能从Bootstrap服务器广告而不是我的项目加载引导程序?

bundles.Add(new StyleBundle("~/Content/cssmain").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css",
                  "~/Content/ilightbox.css",
                  "~/Content/bannerscollection_zoominout.css"));
Run Code Online (Sandbox Code Playgroud)

我也尝试使用Web应用程序自己进行缩小,但我的更改不可见,文件看起来没有减少.

任何帮助表示赞赏

tre*_*rmf 22

我通过做两件事来解决捆绑bootstrap.css的问题:

  1. 首先在bundle中包含bootstrap.css .问题中的代码示例已经这样做了,但我没有.
  2. 官方缩小版本(bootstrap.min.css)添加到与未分类版本相同的目录中的项目.这会提示捆绑器使用现有的缩小文件,而不是尝试(并且失败)缩小bootstrap.css本身.请参阅下面屏幕截图中的绿色箭头.

请注意,如果您使用的是特定主题,请将bootstrap.css和bootstrap.min.css替换为主题提供的文件.这是我的项目中使用spacelab主题的工作代码:

            bundles.Add(new StyleBundle(GetStyleBundlePath("bootstrap")).Include(
            "~/Content/3rdParty/bootstrap.spacelab.css",
            "~/Content/3rdParty/bootstrap-datepicker.css",
            "~/Content/3rdParty/bootstrap-multiselect.css"));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 感谢您让我知道bundler首先尝试寻找现有的缩小文件:) (4认同)
  • 我使用ScriptBundle捆绑CSS,并收到[this](https://groups.google.com/forum/#!topic/glow-users/pDf8CzVa-Jc)错误,**请确保**将`ScriptBundle`用于脚本和CSS的`StyleBundle` (2认同)

小智 14

对于那些可能在这篇文章中绊倒的人...你也可以通过将@import移动到第一个捆绑项来解决这个问题.

根据:http://webdesign.about.com/cs/css/qt/tipcssatimport.htm

@Import必须始终是CSS文档中的第一个.将多个CSS文件捆绑在一起时,它会将它们链接到一个捆绑的css文件中.由于第二个css文件添加到我的包中,在bundle config中,在开始时包含一个@Import,因为文件被链接在一起,@ import会出现在新合并文档的中间.一旦我更改了捆绑订单,问题就解决了.

这一点很重要,因为虽然您可以使用像bootstrap这样的插件提供的缩小文件,但在开发过程中对非缩小文件所做的任何更改都不会添加到现有的缩小css文件中.这意味着您必须进行两次更改,并在缩小的文件中导航.


Ros*_*ush 7

确保你捆绑的那些.js文件都没有结束//Some Comment.如果用一个双反斜线//评论结尾的文件是上涨了另一个相关的文件将被视为一个长注释导致您所看到的错误.我打赌在你的一个.js文件的末尾有// @ Import.如果是这种情况,我认为您可以安全地将该行更改为/*@ Import*/

此外,我不知道这是否在MVC5中得到修复,但在MVC4中,缩小解析器不处理非标准:-moz-any():-webkit-any()css标记.

另请参阅文章,详细介绍如何解析Less @import目录.


rik*_*tik 5

我们遇到了相同的问题,事实证明bootstrap.css是问题。我们收到了与您在上面编写的相同的缩小错误。捆绑器在中有问题@import@keyframes并且@-webkit-keyframes在css文件中。

我们解决该问题的方法是从捆绑中删除bootstrap.css,然后直接在Shared / _Layout.cshtml中引用它(或缩小版本,如果有的话)。

@Styles.Render("~/Content/bootstrap.min.css")
@Styles.Render("~/Content/css")
Run Code Online (Sandbox Code Playgroud)