Browserify - multiple entry points

前端 未结 4 1540
夕颜
夕颜 2020-12-13 18:55

I am using Browserify within gulp. I am trying to compile down my tests to a single file as well. But unlike my main app, which I have working just fine, I am having trouble

4条回答
  •  我在风中等你
    2020-12-13 19:20

    Here's an alternate recipe that fits more with the gulp paradigm using gulp.src()

    var gulp = require('gulp');
    var browserify = require('browserify');
    var transform = require('vinyl-transform');
    var concat = require('gulp-concat');
    
    gulp.task('browserify', function () {
    
      // use `vinyl-transform` to wrap around the regular ReadableStream returned by b.bundle();
      // so that we can use it down a vinyl pipeline as a vinyl file object.
      // `vinyl-transform` takes care of creating both streaming and buffered vinyl file objects.
      var browserified = transform(function(filename) {
        var b = browserify(filename, {
          debug: true,
          extensions: ['.coffee']
        });
        // you can now further configure/manipulate your bundle
        // you can perform transforms, for e.g.: 'coffeeify'
        // b.transform('coffeeify');
        // or even use browserify plugins, for e.g. 'minifyiy'
        // b.plugins('minifyify');
        // consult browserify documentation at: https://github.com/substack/node-browserify#methods for more available APIs
        return b.bundle();
      });
    
      return gulp.src(['./app/js/**/*Spec.coffee'])
        .pipe(browserified)/
        .pipe(concat('spec.js'))
        .pipe(gulp.dest('./specs'));
    });
    
    gulp.task('default', ['browserify']);
    

    For more details about how this work, this article that I wrote goes more in-depth: http://medium.com/@sogko/gulp-browserify-the-gulp-y-way-bb359b3f9623

提交回复
热议问题