我在ASP.net MVC应用程序中使用捆绑。我想以分层方式构建我的包。
例如,这些是我想要的所有网页上的脚本:
bundles.Add(new ScriptBundle("~/bundles/bootstrap-js").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js",
"~/Scripts/bootstrap-datetimepicker.min.js",
"~/Scripts/jquery.smartmenus.js",
"~/Scripts/jquery.smartmenus.bootstrap.js"
));
接下来我想在一些页面上进行淘汰:
bundles.Add(new ScriptBundle("~/bundles/knockout-js").Include(
"~/Scripts/knockout/knockout-3.4.0.js",
"~/Scripts/knockout/knockout-kendo.js",
"~/Scripts/knockout/knockout.mapping-latest.js",
"~/Scripts/knockout/knockout.validation.js",
"~/Scripts/knockout/knockout.validation.de-DE.js",
"~/Scripts/knockout/knockout.validation.fr-BE.js",
"~/Scripts/knockout/knockout.validation.nl-BE.js",
"~/Scripts/knockout/Knockout.bindinghandlers.js",
"~/Scripts/knockout/knockout.validation.mvc.js"));
最后,我希望每个页面都拥有自己的自定义脚本。
bundles.Add(new ScriptBundle("~/bundles/scriptName-js").Include(
"~/Views/Cards/scriptName.js"));
有没有办法,所以我只需要将所有以前的捆绑包合并到一个捆绑包中,就必须包含一个@ scripts.render语句?
@Scripts.Render("~/bundles/mypage-js")
我尝试了这个,但它没有工作:
bundles.Add(new ScriptBundle("~/bundles/mypage-js").Include("~/bundles/scriptName-js","~/bundles/knockout-js","~/bundles/bootstrap-js"));
答案 0 :(得分:2)
Include
params
string[]
接受路径数组而不是var everyPage = new [] {
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js",
"~/Scripts/bootstrap-datetimepicker.min.js",
"~/Scripts/jquery.smartmenus.js",
"~/Scripts/jquery.smartmenus.bootstrap.js"
};
var knockout = new [] {
"~/Scripts/knockout/knockout-3.4.0.js",
"~/Scripts/knockout/knockout-kendo.js",
//etc...
};
bundles.Add(new ScriptBundle("~/bundles/scriptName-js")
.Include(everyPage)
.Include(knockout)
.Include("~/Views/Cards/scriptName.js")
);
路径。您可以使用它将共享脚本块定义为#!/bin/bash
df -h > /home/infrarunsvc/output.txt
tmpfile="/home/infrarunsvc/tmpfile.html"
input="/home/infrarunsvc/output.txt"
echo '<html><body><table border=1>' > "$tmpfile"
awk '{print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table></body></html>"}' "$input" >> "$tmpfile"
cat $tmpfile | mail -s "$(echo -e "Test\nContent-Type: text/html")"
yourmailaddress@...com
,然后包含它们:
{
"user" : {
"name" : "name",
"surname": "surname"
}
}
它并不像从另一个包引用一个包那样简洁,但它比重复每个脚本块更好