按如下方式设置我的捆绑包:
bundles.UseCdn = true;
var scriptJquery = new ScriptBundle(Bundles.Scripts.Jquery, "//code.jquery.com/jquery-1.9.1.js")
{
CdnFallbackExpression = "window.jQuery",
}
.Include("~/scripts/jquery-{version}.js"); // {version} not work!
bundles.Add(scriptJquery);
var scriptBundle = new ScriptBundle(Bundles.Scripts.Common)
{
Orderer = new FileBundleOrderer(server.MapPath("~/Scripts/bundle.txt"))
}
.IncludeDirectory("~/Scripts", "*.js", false);
bundles.Add(scriptBundle);
在我的 Scripts 文件夹中具有以下结构。
请注意,jQuery 与其他 jQuery 处于同一级别。
_Layout.cshtml
@Scripts.Render(CreditoImobiliarioBB.Web.App_Start.Bundles.Scripts.Jquery)
@Scripts.Render(CreditoImobiliarioBB.Web.App_Start.Bundles.Scripts.Common)
运行应用程序时会生成以下脚本。请注意,jQuery 出现了两次!
<script src="/scripts/jquery-1.9.1.js"></script> <!-- <------ -->
<script src="/Scripts/moment.js"></script>
<script src="/Scripts/moment.pt-br.js"></script>
<script src="/Scripts/handlebars.runtime.js"></script>
<script src="/Scripts/knockout-2.2.1.debug.js"></script>
<script src="/Scripts/knockout.mapping-latest.js"></script>
<script src="/Scripts/underscore.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/bootstrap-datepicker.js"></script>
<script src="/Scripts/bootstrap-datepicker.pt-BR.js"></script>
<script src="/Scripts/bootstrap-multiselect.js"></script>
<script src="/Scripts/bootstrap-typeahead.js"></script>
<script src="/Scripts/accounting.js"></script>
<script src="/Scripts/jquery.pnotify.js"></script>
<script src="/Scripts/fileuploader.js"></script>
<script src="/Scripts/jquery.inputmask.js"></script>
<script src="/Scripts/jquery.inputmask.extensions.js"></script>
<script src="/Scripts/jquery.inputmask.numeric.extensions.js"></script>
<script src="/Scripts/jquery.inputmask.date.extensions.js"></script>
<script src="/Scripts/jquery.maskMoney.js"></script>
<script src="/Scripts/jquery.bootpag.js"></script>
<script src="/Scripts/Email.js"></script>
<script src="/Scripts/Endereco.js"></script>
<script src="/Scripts/Telefone.js"></script>
<script src="/Scripts/prototypes.js"></script>
<script src="/Scripts/antiForgetyTokenHelper.js"></script>
<script src="/Scripts/ajaxPost.js"></script>
<script src="/Scripts/ajaxUploader.js"></script>
<script src="/Scripts/jquery-1.9.1.js"></script> <!-- <------ -->
<script src="/Scripts/jquery.cycle.all.js"></script>
<script src="/Scripts/scripts.js"></script>
如果我尝试忽略 jQuery 文件,它不会以任何方式出现!
bundles.IgnoreList.Ignore("jquery-{version}.js", OptimizationMode.Always);
如何仅在单个捆绑包中忽略 jQuery?如果 Bundles.Scripts.Common