1

在 VS 2019 中,当我尝试访问Publish文件夹Gulp失败时,ReferenceError: merge is not defined.

gulpfile.js

/// <binding AfterBuild='default' />
var gulp = require('gulp');
var uglify = require("gulp-uglify");
var concat = require("gulp-concat");

gulp.task('minify', function () {
    return gulp.src("wwwroot/js/**/*.js")
        .pipe(uglify())
        .pipe(concat("dutchtreat.min.js"))
        .pipe(gulp.dest("wwwroot/dist"));
}); 

var nodeModules = {
  "bootstrap": { "dist/**/*": "" },
  "font-awesome": { "**/*": "" },
  "jquery": { "dist/*": "" },
  "jquery-validation": { "dist/*": "" },
  "jquery-validation-unobstrusive": { "dist/*": "" }  };

gulp.task("node_modules", function () {
let streams = [];

for (var module in nodeModules) {
    console.log("Prepping Scripts for: " + module);
    for (var itemProp in nodeModules[module]) {
        streams.push(gulp.src("node_modules/" + module + "/" + itemProp)
            .pipe(gulp.dest("wwwroot/lib" + module + "/" + nodeModules[module][itemProp])));
    }
}
return merge(streams);
}); 

gulp.task('default', gulp.series("node_modules", "minify")); 

package.json "devDependencies"

"gulp": "4.0.2",
"gulp-uglify": "3.0.2",
"gulp-concat": "2.6.1",
"merge-stream": "2.0.0",
"merge": "1.2.1"

所有 5 个文件都加载到 Dependencies | npm 文件夹。

为什么找不到merge?这种语法是否正确Gulp 4

4

1 回答 1

1

您需要要求合并才能像使用其他所有内容一样使用它。

 var merge = require(“merge-stream”);

我想我通常使用 gulp-merge,但我相信 merge-stream 也可以。

于 2020-03-22T15:01:31.000 回答