如何在 Visual Studio 2015 年进行捆绑和缩小

How to do Bundling and Minification in Visual Studio 2015

Visual Studio 2013 自带的 APS.NET MVC 项目模板使用捆绑将 CSS 和脚本文件发送到浏览器。

Visual Studio2015自带的ASP.NETMVC项目模板已经停止使用,直接插入<link rel='stylesheet' ... >语句

推荐的捆绑和缩小最佳实践是什么?

有一篇关于此的文章 - Where Did My ASP.NET Bundles Go in ASP.NET 5? and What about Bundling and Minification

从 ASP.NET5 开始,Microsoft 鼓励开发人员开始集成其他 Web 开发人员一直在使用的一些更流行的 Web 开发工具:Gulp、npm 和 bower。这些工具中的每一个都有特定的用途:

  • Gulp 是一个任务-运行ner 写在 JavaScript 上面 运行s NodeJS 框架并自动执行重复性任务
  • npm 是 Node 包管理器,可用于交付 运行 在 NodeJS 框架中的插件和实用程序。
  • Bower 是一个包管理器,用于从 Git 交付静态资源 存储库。

这些工具现在允许您捆绑和缩小脚本并且 css:

都可以通过npm安装。

示例:

var paths = {
    bower: "./bower_components/",
    lib: "./" + project.webroot + "/lib/",
    app: "./" + project.webroot + "/app/",
    dist: "./" + project.webroot + "/dist/"
};

var concat = require("gulp-concat"),
    rename = require("gulp-rename"),
    uglify = require("gulp-uglify");

gulp.task("bundle", function () {
    return gulp.src([
        paths.app + "menu.js",
        paths.app + "app.js"])
    .pipe(concat("all.js"))
    .pipe(gulp.dest(paths.dist))
    .pipe(rename("all.min.js"))
    .pipe(uglify())
    .pipe(gulp.dest(paths.dist));
});