Compiling dynamically required modules with Browserify

后端 未结 3 1410
广开言路
广开言路 2020-12-06 01:00

I am using Browserify to compile a large Node.js application into a single file (using options --bare and --ignore-missing [to avoid troubles with

3条回答
  •  无人及你
    2020-12-06 01:29

    There's also the bulkify transform, as documented here:

    https://github.com/chrisdavies/tech-thoughts/blob/master/browserify-include-directory.md

    Basically, you can do this in your app.js or whatever:

    var bulk = require('bulk-require');
    
    // Require all of the scripts in the controllers directory
    bulk(__dirname, ['controllers/**/*.js']);
    

    And my gulpfile has something like this in it:

    gulp.task('js', function () {
      return gulp.src('./src/js/init.js')
        .pipe(browserify({
          transform: ['bulkify']
        }))
        .pipe(rename('app.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dest/js'));
    });
    

提交回复
热议问题