Gulp glob chain to scroll through transforms

I have a project with several relatively disjoint pages, each of which contains its own script entry point. These scripts are requireseveral others using commonjs syntax, and must be converted using 6to5 and bundled using a browser.

I would like to set up a gulp task that captures all the files that match the template and transfers them to the node, but I'm not sure how to transfer files from gulp.srcto browserify(filename).

My gulpfile looks like this:

var gulp = require("gulp");
var browserify = require("browserify");
var to5browserify = require("6to5-browserify");
var source = require("vinyl-source-stream");

var BUNDLES = [
    "build.js",
    "export.js",
    "main.js"
];

gulp.task("bundle", function () {
    /* Old version, using glob:
    return gulp.src("src/** /*.js")
        .pipe(sixto5())
        .pipe(gulp.dest("dist"));
    */

    // New version, using array:
    return BUNDLES.map(function (bundle) {
        return browserify("./src/" + bundle, {debug: true})
            .transform(to5browserify)
            .bundle()
            .pipe(source(bundle))
            .pipe(gulp.dest("./dist"));
    });
});

gulp.task("scripts", ["bundle"]);

gulp.task("html", function () {
    return gulp.src("src/**/*.html")
        .pipe(gulp.dest("dist"));
});

gulp.task("styles", function () {
    return gulp.src("src/**/*.css")
        .pipe(gulp.dest("dist"));
});

gulp.task("default", ["scripts", "html", "styles"]);

This seems to work, but is not supported: I will add additional scripts relatively soon and do not want to add them to the array every time.

gulp.src(glob).pipe ( ) gulp.src(glob).map ( ).

gulp.src , , ?

+4
2

through2, , .

vinyl-transform vinyl-source-stream , , , - .

var gulp = require('gulp');
var through = require('through2');
var browserify = require('browserify');

gulp.task('bundle', function() {
    var browserified = function() {
        return through.obj(function(chunk, enc, callback) {
            if(chunk.isBuffer()) {
                var b = browserify(chunk.path);
                    // Any custom browserify stuff should go here
                    //.transform(to5browserify);

                chunk.contents = b.bundle();

                this.push(chunk);

            }
            callback();
        });
    };

    return gulp.src(['./src/**/*.js'])
        .pipe(browserified())
        .pipe(gulp.dest('dest'));
});
+7

BUNDLES, :

var BUNDLES = [
    "app/**/*.js",
    "export.js",
    "app/modules/**/*.js",
    "!app/modules/excluded/*.js"
];
-2

All Articles