我使用过System.Web.Optimization& WebGrease DLL使用下面的代码自动化我的项目中的bundle和minifiy javascript和css文件。
using System.Web.Optimization;
using WebGrease;
protected void Application_Start()
{
RegisterBundles(BundleTable.Bundles);
BundleTable.EnableOptimizations = false;
}
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Content/Script/Common/").Include("~/Content/Scripts/PTax/Common/ViewPort.js",
"~/Content/Scripts/PTax/Common/jquery.rotate.js",
"~/Content/Scripts/PTax/Common/jquery.loupe.js",
"~/Content/Scripts/PTax/Common/Accordion.js",
"~/Content/Scripts/PTax/Common/Progress.js",
"~/Content/Scripts/PTax/Common/AjaxGlobalHandler.js",
"~/Content/Scripts/PTax/Common/DialogBox.js",
"~/Content/Scripts/PTax/Common/Common.js",
"~/Content/Scripts/PTax/Common/DateValidations.js"));
}
在我的项目中,某些模块只有一个javascript文件。我不需要将其与任何其他文件捆绑在一起。所以我只需要它。我怎么能这样做。
答案 0 :(得分:0)
您可以创建一个新的捆绑包(创建多个捆绑包是正常的)
bundles.Add(new ScriptBundle("~/bundles/get").Include("~/Scripts/app/home.js"));
然后在必要的视图中呈现脚本
@Scripts.Render("~/bundles/home")