MVC捆绑不工作 [英] MVC Bundling Not Working
问题描述
我在一个小MVC项目的工作,我已经在这样BundleConfig.cs宣布捆绑
I am working on a small mvc project, i have declared a bundle in BundleConfig.cs like this
// JavaScript的捆绑
//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"));
在我的头节_Layout.cshml我已经进入:
In my _Layout.cshml in the head section i have entered:
<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我有:
In my application_start i have:
BundleTable.EnableOptimizations = true;
和web.config中
and web.config
<compilation debug="true" targetFramework="4.0">
这让我很头疼的一点试图弄清楚为什么心不是捆绑的JavaScript的专门工作。有人请告知
This gave me bit of a headache trying to figure why the bundling isnt working specially for the javascript. Some one please advise
推荐答案
由于这条线的捆绑不工作
The bundling is not working because of this line
<compilation debug="true" targetFramework="4.0">
在调试时,包不要COM preSS或再缩小为你调试,并能够看到实际的JavaScript和CSS是当你正在调试一个好事。当你有调试设置为false(或从标签移除),那么你的应用程序在释放模式运行。捆绑将发生在这一点上(除非您设置 BundleTable.EnableOptimizations = FALSE;
)
When in debug, the bundles do not compress or minify as you are "debugging" and being able to see the actual JavaScript and CSS is a good thing when you are debugging. When you have debug set to false (or removed from the tag), then your application is running in release mode. Bundling will occur at that point (unless you set BundleTable.EnableOptimizations = false;
)
<compilation debug="false" targetFramework="4.0">
或
<compilation targetFramework="4.0">
正如下面迈克指出的那样, BundleTable.EnableOptimizations = TRUE;
应覆盖web.config中的设置。但是,它仍然可能是好的摆脱调试模式在您的项目不覆盖该设置的情况。
As pointed out by Mike below, the BundleTable.EnableOptimizations = true;
should override the web.config setting. However, it may still be good to get out of debug mode in the case that your project is not overriding that setting.
这篇关于MVC捆绑不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!