如何在www.example.com BundleConfig中忽略特定捆绑包进行优化asp.net

bvn4nwqk  于 2023-02-14  发布在  .NET
关注(0)|答案(4)|浏览(120)
public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/angularJs").Include(
              "~/Scripts/angular.min.js"));

    bundles.Add(new ScriptBundle("~/bundles/angularComponents").Include(
                "~/Scripts/angular-route.min.js",
                "~/Scripts/angular-local-storage.min.js",
                "~/Scripts/loading-bar.min.js"));

    bundles.Add(new StyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.min.css",
              "~/Content/loading-bar.min.css",
              "~/Content/font-awesome.min.css",
              "~/Content/site.css"));

    bundles.IgnoreList.Clear();
    bundles.IgnoreList.Ignore("*angular-route.min.js", OptimizationMode.Always);
    bundles.IgnoreList.Ignore("*angular-local-storage.min.js", OptimizationMode.Always);
    bundles.IgnoreList.Ignore("*loading-bar.min.js", OptimizationMode.Always);

    BundleTable.EnableOptimizations = true;
}

这里我想从优化中删除这个包(new ScriptBundle("~/bundles/angularComponents"))。我已经尝试过上面的方法,但是它没有从优化中忽略。文件也被合并了。谁能告诉我如何忽略这个特定的包列表?

vltsax25

vltsax251#

你可以试试下面的代码。它会添加相关的脚本,但不会缩小。

var angularComponents = new ScriptBundle("~/bundles/angularComponents").Include(
                 "~/Scripts/angular-route.min.js",
                 "~/Scripts/angular-local-storage.min.js",
                 "~/Scripts/loading-bar.min.js"
                );

            bundles.Add(angularComponents);

            angularComponents.Transforms.Clear();
jdzmm42g

jdzmm42g2#

ScriptBundle scriptBndl = new ScriptBundle("~/bundles/bootstrap");
    scriptBndl.Include(
                        "~/Scripts/bootstrap.js",
                        "~/Scripts/respond.js"
                      );
    bundles.Add(scriptBndl);
    BundleTable.EnableOptimizations = true;
owfi6suc

owfi6suc3#

您是否尝试过注解掉下面提到的行?

//bundles.Add(new ScriptBundle("~/bundles/angularComponents").Include(
    //"~/Scripts/angular-route.min.js",
    //"~/Scripts/angular-local-storage.min.js",
    //"~/Scripts/loading-bar.min.js"));
mpgws1up

mpgws1up4#

如果你不想把脚本捆绑在一起,* 不要把它们放在一个捆绑包里 *。我错过了什么吗?创建捆绑包的唯一目的是把一堆脚本连接在一起并最小化。如果你不想这样,那就直接把脚本放在页面上,不要使用捆绑包。

相关问题