gulp browserify reactify task is quite slow

前端 未结 3 755
我寻月下人不归
我寻月下人不归 2021-02-04 14:48

I am using Gulp as my task runner and browserify to bundle my CommonJs modules.

I have noticed that running my browserify task is quite slow, it takes around 2 - 3 seco

3条回答
  •  臣服心动
    2021-02-04 15:06

    See fast browserify builds with watchify. Note that the only thing passed to browserify is the main entry point, and watchify's config.

    The transforms are added to the watchify wrapper.

    code from article pasted verbatim

    var gulp = require('gulp');
    var gutil = require('gulp-util');
    var sourcemaps = require('gulp-sourcemaps');
    var source = require('vinyl-source-stream');
    var buffer = require('vinyl-buffer');
    var watchify = require('watchify');
    var browserify = require('browserify');
    
    var bundler = watchify(browserify('./src/index.js', watchify.args));
    // add any other browserify options or transforms here
    bundler.transform('brfs');
    
    gulp.task('js', bundle); // so you can run `gulp js` to build the file
    bundler.on('update', bundle); // on any dep update, runs the bundler
    
    function bundle() {
      return bundler.bundle()
        // log errors if they happen
        .on('error', gutil.log.bind(gutil, 'Browserify Error'))
        .pipe(source('bundle.js'))
        // optional, remove if you dont want sourcemaps
          .pipe(buffer())
          .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
          .pipe(sourcemaps.write('./')) // writes .map file
        //
        .pipe(gulp.dest('./dist'));
    }
    

提交回复
热议问题