Bundling and minification without ASP.NET MVC

前端 未结 6 1199
遥遥无期
遥遥无期 2020-12-13 14:17

Is it possible to use bundling and minification from Microsoft.AspNet.Web.Optimization without having an MVC project?

I\'m creating an AngularJS site communicating w

6条回答
  •  伪装坚强ぢ
    2020-12-13 14:56

    It is absolutely possible to use the bundling and minification in a blank project.

    1. Use Nuget to install the package: Install-Package Microsoft.AspNet.Web.Optimization
    2. Create a BundleConfig Class and define your bundles:

      using System.Web.Optimization;
      public class BundleConfig
      {
          public static void RegisterBundles(BundleCollection bundles)
          {
              bundles.Add(new ScriptBundle("~/bundles/js").Include(
                        "~/Scripts/*.js"));
              bundles.Add(new StyleBundle("~/bundles/css").Include(
                         "~/Styles/*.css")); 
          } 
      }
      
    3. Register the BundleConfig class within the application start in the global.asax

      void Application_Start(object sender, EventArgs e)
      {
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
      
    4. reference the bundles in your HTML document.
    5. Enable bundling by disabling debug mode.

提交回复
热议问题