捆绑和微小而不ASP.NET MVC [英] Bundling and minification without ASP.NET MVC

查看:197
本文介绍了捆绑和微小而不ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用来自Microsoft.AspNet.Web.Optimization捆绑和缩小,而无需一个MVC项目?

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

我创造一个AngularJS网站与REST API通信。对于REST API,我使用的ASP.NET Web API。我还创建了一个空ASP.NET Web应用程序。只有HTML,JS和CSS文件在这个项目(和一个web.config)。我想为我的JS和CSS文件被捆绑和缩小的,但我不希望只是创建一个MVC项目来获取。这可能吗?

I'm creating an AngularJS site communicating with a REST API. For the REST API I'm using ASP.NET Web API. I have also created an "ASP.NET Empty Web Application". There are only HTML, js and CSS files in this project (and a web.config). I'd like for my js and CSS files to be bundled and minified, but I don't want to create a MVC project just to get that. Is it possible?

推荐答案

这是绝对可以使用捆绑和缩小在一个空白的项目。

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


  1. 使用的NuGet安装的软件包:安装封装Microsoft.AspNet.Web.Optimization

  2. 创建BundleConfig类,并定义你的包:

  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")); 
    } 
}


  • 注册应用程序启动中BundleConfig班在Global.asax

  • Register the BundleConfig class within the application start in the global.asax

    void Application_Start(object sender, EventArgs e)
    {
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    


  • 引用捆在HTML文档中

  • 启用禁用调试模式捆绑。

  • 这篇关于捆绑和微小而不ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆