我试图为我的应用程序捆绑脚本和样式引导程序。我的调试正在运行但是当我发布它时,不要加载脚本和样式。
我添加了一个 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'
我在谷歌搜索并使用了不同的方法,但错误没有解决。
将所有样式添加到特殊路径(Content/Them/Bootstrap)并使用
new StyleBundle("~/content/Them/Bootstrap")
利用
BundleTable.EnableOptimizations = true;
其他..