[英]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.