![](/img/trans.png)
[英]Running an ASP.NET MVC 4 app in release mode does not bundle and minifiy the js files
[英]How to bundle js files in asp.net?
我有一個帶有大量js文件的角度應用程序,我如何捆綁所有這些文件。
我在網上看到的每個地方,他們都建議使用BundleConfig捆綁js文件,但我在asp.net中使用空的web應用程序模板。
如何在一個順序中捆綁js文件,以便不會出現沖突,並且在選擇絕對路徑和相對路徑時沒有問題
如何創建一個完整的MVC項目的新項目(選擇MVC作為tempalte而不是'空'。然后在App_Start / BundleConfig.cs下查看,創建該文件並將其注冊為global.asax中的默認項目。的.cs?
的global.asax.cs:
BundleConfig.RegisterBundles(BundleTable.Bundles);
App_Start / BundleConfig.cs
using System.Web;
using System.Web.Optimization;
namespace WebApplication1
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
說實話。 我會使用基於節點的工具,如webpack或gulp來做到這一點。 您可以使用捆綁包,但它們不是那么強大,您可能會錯過在前端構建中可以執行的許多操作。 例如,在正確的加載順序方面,它會有很多幫助。
通常,我們有兩種方法來捆綁AnguarJS / ASP.NET:
希望它有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.