项目中碰到了这个问题,问题如下:
bundles.Add(new ScriptBundle("~/scripts/package.js").Include(
"~/scripts/jquery-paged-scroll.min.js",
"~/scripts/liqu.dialog.js"));
调试状态下,前台页面源代码中完全找不到jquery-paged-scroll.min.js这个文件
google一下,有如下解决方案:
1 改名字,jquery-paged-scroll.min.js改名为jquery-paged-scroll.js
2 使用如下方法
public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
{
if (ignoreList == null)
throw new ArgumentNullException("ignoreList");
ignoreList.Ignore("*.intellisense.js");
ignoreList.Ignore("*-vsdoc.js");
ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
//ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
}
public static void RegisterBundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
AddDefaultIgnorePatterns(bundles.IgnoreList);
//...your code
}
更多解释
Microsoft implies the following behavior (and I prefer to follow it in my projects):
// short version
- 同一个项目文件夹下同时有debug和minified版本的script:
- script.js
- script.min.js
- 你在你的代码中bundle时只添加了 script.js
结果是:Debug模式下自动获得script.js版本,而release模式下自动获得script.min.js
// long version
You can have also .debug.js version. In that case the file is included in the following priority in DEBUG:
- script.debug.js
- script.js
in RELEASE:
- script.min.js
- script.js
.// Note
另外,之所以在文件夹下放一个.min的版本的唯一原因是,在MVC4中有时minified版本不能被自动处理,如下代码将不能自动的进行minified处理:if (DEBUG) console.log("Debug message");
其他任何情况下,只需放一个debug版本
参考:http://stackoverflow.com/questions/12569259/asp-net-mvc-4-scriptbundle-returns-emptyhttp://stackoverflow.com/questions/11980458/mvc4-bundler-not-including-min-files#comment15973197_11980458http://stackoverflow.com/questions/11209396/why-is-mvc4-bundling-and-minification-making-my-files-biggerhttp://timgthomas.com/2012/09/a-quick-start-of-asp-net-mvc-4s-bundling/