NuGet:
Install-Package Microsoft.AspNet.Web.Optimization
建立
App_Start\BundleConfig.cs:
自行修改要的
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles) {
bundles.Add(new ScriptBundle("~/Scripts/jquery").Include(
"~/Scripts/Lib/jquery/jquery-{version}.js",
"~/Scripts/Lib/jquery/jquery.*",
"~/Scripts/Lib/jquery/jquery-ui-{version}.js")
);
bundles.Add(new ScriptBundle("~/Scripts/knockout").Include(
"~/Scripts/Lib/knockout/knockout-{version}.js",
"~/Scripts/Lib/knockout/knockout-deferred-updates.js")
);
}
}
Global.asax 新增這行
using System.Web.Optimization;
protected void Application_Start() {
...
BundleConfig.RegisterBundles(BundleTable.Bundles);
...
}
最後別忘了web.config 新增命名空間 不然你也不能用
<namespaces>
<add namespace="System.Web.Optimization"></add>
</namespaces>
讓我的開始Bundle吧
@Scripts.Render("~/Scripts/jquery")
@Scripts.Render("~/Scripts/bootstrap")