我正在开发一个小型的mvc项目,我在BundleConfig.cs中声明了这样的包
// javascript bundle
bundles.Add(new ScriptBundle("~/bundles/Layout1JS").Include(
"~/Content/Public/js/jquery.min.js",
"~/Content/Public/js/bootstrap.min.js",
"~/Content/Public/js/jquery.isotope.min.js",
"~/Content/Public/js/jquery.Photo.js",
"~/Content/Public/js/easing.js",
"~/Content/Public/js/jquery.lazyload.js",
"~/Content/Public/js/jquery.ui.totop.js",
"~/Content/Public/js/nav.js",
"~/Content/Public/js/sender.js",
"~/Content/Public/js/jquery.slider-min.js",
"~/Content/Public/js/custom.js"));
//css bundle
bundles.Add(new StyleBundle("~/Content/Public/css").Include(
"~/Content/Public/css/main.css"));
在我输入的head部分的_Layout.cshml中:
<head>
<meta charset="utf-8">
<title>test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- LOAD CSS FILES -->
@Styles.Render("~/Content/Public/css", "~/Content/css")
<!-- LOAD JS FILES -->
@Scripts.Render("~/bundles/Layout1JS")
</head>
在我的application_start中,我有:
BundleTable.EnableOptimizations = true;
和web.config
<compilation debug="true" targetFramework="4.0">
这让我有点头疼,试图弄清楚为什么捆绑不是专门为javascript工作。有人请告知
答案 0 :(得分:8)
由于此行
,捆绑无法正常工作<compilation debug="true" targetFramework="4.0">
在调试时,捆绑包不会像你那样压缩或缩小&#34;调试&#34;在调试时能够看到实际的JavaScript和CSS是一件好事。当您将debug设置为false(或从标记中删除)时,您的应用程序将以发布模式运行。捆绑将在此时发生(除非您设置BundleTable.EnableOptimizations = false;
)
<compilation debug="false" targetFramework="4.0">
或
<compilation targetFramework="4.0">
正如Mike在下面指出的那样,BundleTable.EnableOptimizations = true;
应该覆盖web.config设置。但是,在项目未覆盖该设置的情况下,退出调试模式仍然是好的。