1

我想使用 gulp-insert 对每个 JS 文件进行包装,文件除外.module.js

这是我的吞咽任务:

gulp.task('compressjs', function() {
    gulp.src("local/app/**/*.js")
    .pipe(sourcemaps.init())
    // wrap each individual JS file
    .pipe(insert.wrap('(function(){"use strict";', '\n})();'))
    .pipe(uglify())
    .pipe(concat('all.min.js'))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public/app'));
}

它按预期包装每个 JS 文件。那么,如何将其从带有.module.js扩展名的包装文件中排除?

4

1 回答 1

1

您可以尝试通过从第一个源gulp-add-src中排除,然后将其通过管道,然后将其添加回源来尝试使用。.module.jsgulp-insert.module.js

var addsrc = require("gulp-add-src");

gulp.task('compressjs', function() {
    gulp.src(["local/app/**/*.js", "!local/app/**/*.module.js"])
    .pipe(sourcemaps.init())
    // wrap each individual JS file
    .pipe(insert.wrap('(function(){"use strict";', '\n})();'))
    // add the modules file
    .pipe(addsrc("local/app/**/*.module.js"))
    .pipe(uglify())
    .pipe(concat('all.min.js'))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public/app'));
}
于 2015-05-14T04:39:52.503 回答