在构建过程中,JS和CSS不是由Bunldeld / Gulp缩小的

时间:2016-01-12 18:14:48

标签: gulp asp.net-core asp.net-core-mvc bundling-and-minification

我正在开发一个ASP.Net 5项目,看起来他们已经转向使用GULP捆绑并缩小CSS和JavaScrpt文件。我想测试一下,确保它正常工作,但似乎不是。构建程序包后,site.min.jssite.min.css文件无法找到。除了运行Web应用程序之外,还不会将文件拉入并处理它们。我可能错过了一些愚蠢的小事,但我已经看了几个教程,看不到它。

gulpfile.js:

/// <binding Clean='clean' />
"use strict";

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

var paths = {
    webroot: "./wwwroot/"
};

paths.js = paths.webroot + "js/**/*.js";
paths.minJs = paths.webroot + "js/**/*.min.js";
paths.css = paths.webroot + "css/**/*.css";
paths.minCss = paths.webroot + "css/**/*.min.css";
paths.concatJsDest = paths.webroot + "js/site.min.js";
paths.concatCssDest = paths.webroot + "css/site.min.css";

gulp.task("clean:js", function (cb) {
    rimraf(paths.concatJsDest, cb);
});

gulp.task("clean:css", function (cb) {
    rimraf(paths.concatCssDest, cb);
});

gulp.task("clean", ["clean:js", "clean:css"]);

gulp.task("min:js", function () {
    return gulp.src([paths.js, "!" + paths.minJs], { base: "." })
        .pipe(concat(paths.concatJsDest))
        .pipe(uglify())
        .pipe(gulp.dest("."));
});

gulp.task("min:css", function () {
    return gulp.src([paths.css, "!" + paths.minCss])
        .pipe(concat(paths.concatCssDest))
        .pipe(cssmin())
        .pipe(gulp.dest("."));
});

gulp.task("min", ["min:js", "min:css"]);

_Layout.cshtml中的相关代码:

<environment names="Development2">
    <link rel="stylesheet" href="~/lib/normalize-css/normalize.css" />
    <link rel="stylesheet" href="~/css/NavigationMenu.css" />
    <script src="~/js/jquery.easymenu.js"></script>
</environment>

<environment names="Production, Development">
    <link rel="stylesheet" href="~/css/css/site.min.css" />
    <script src="~/js/site.min.js"></script>
</environment>

1 个答案:

答案 0 :(得分:4)

我找到了解决方案。我需要更新gulpfile.js文件的第一行才能阅读

/// <binding BeforeBuild='clean, min' Clean='clean' />