JS捆不渲染不EnableOptimization设置为true [英] JS bundles do not render without EnableOptimization set to true
问题描述
我不知道如果我做错事,但它可能是内部MVC4的错误。我不知道如何解决这个问题?
I don't know if I'm doing something wrong but it's probably a bug inside MVC4. I wonder how can I fix this?
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
ScriptBundle scriptBundle = new ScriptBundle("~/js");
string[] scriptArray =
{
"~/content/plugins/jquery/jquery-1.8.2.min.js",
"~/content/plugins/jquery/jquery-ui-1.9.0.min.js",
"~/content/plugins/jquery/jquery.validate.min.js",
"~/content/plugins/jquery/jquery.validate.unobtrusive.min.js",
"~/content/plugins/bootstrap/js/bootstrap.min.js",
};
scriptBundle.Include(scriptArray);
scriptBundle.IncludeDirectory("~/content/js", "*.js");
bundles.Add(scriptBundle);
BundleTable.EnableOptimizations = true;
}
}
@ Scripts.Render(〜/ JS)
的转换(例如IT WORKS!)的<脚本SRC =/ JS V = VeCPNK561DZp34yjmWbLrNM35Kf6gaNDl0xsMMC25BQ1?>< / SCRIPT>
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
ScriptBundle scriptBundle = new ScriptBundle("~/js");
string[] scriptArray =
{
"~/content/plugins/jquery/jquery-1.8.2.min.js",
"~/content/plugins/jquery/jquery-ui-1.9.0.min.js",
"~/content/plugins/jquery/jquery.validate.min.js",
"~/content/plugins/jquery/jquery.validate.unobtrusive.min.js",
"~/content/plugins/bootstrap/js/bootstrap.min.js",
};
scriptBundle.Include(scriptArray);
scriptBundle.IncludeDirectory("~/content/js", "*.js");
bundles.Add(scriptBundle);
// BundleTable.EnableOptimizations = true; // I could set it to 'false' for same result, it's false by default
}
}
@ Scripts.Render(〜/ JS)
的转换(例如,它不工作!)的(什么都没有,夫妇休息的空行)
推荐答案
如果我的理解是正确的,你应该定义使用非民的JavaScript文件的包。当您启用优化,将交换非最小文件最小文件你:
If my understanding is correct, you should define your bundles using the "non-min" JavaScript files. When you enable optimizations it will swap the non-min files for the min files for you:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
ScriptBundle scriptBundle = new ScriptBundle("~/js");
string[] scriptArray =
{
"~/content/plugins/jquery/jquery-1.8.2.js",
"~/content/plugins/jquery/jquery-ui-1.9.0.js",
"~/content/plugins/jquery/jquery.validate.js",
"~/content/plugins/jquery/jquery.validate.unobtrusive.js",
"~/content/plugins/bootstrap/js/bootstrap.js",
};
scriptBundle.Include(scriptArray);
scriptBundle.IncludeDirectory("~/content/js", "*.js");
bundles.Add(scriptBundle);
}
}
优化调试的时候,却是真正的在默认情况下释放模式设置为false。
Optimizations are set to false when debugging, but are true by default in release mode.
这篇关于JS捆不渲染不EnableOptimization设置为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!