是否可以包含因子包以分离常见的依赖关系?

时间:2016-10-28 23:40:17

标签: javascript gulp browserify factor-bundle

您好我正在寻找创建一个公共捆绑包,其中包含多个页面共享的依赖项以及每个页面的特定于页面的捆绑包。

我可以用它来创建多个包:browserify-multiple-destination

但我需要创建具有共享依赖关系的公共文件,以避免重复。

是否可以在此任务中加入 factor-bundle 以分隔常见的依赖关系?

B rowserify + Globs(多个目的地)食谱

var gulp = require('gulp');
var browserify = require('browserify');
var gutil = require('gulp-util');
var tap = require('gulp-tap');
var buffer = require('gulp-buffer');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');

gulp.task('js', function () {

  return gulp.src('src/**/*.js', {read: false}) // no need of reading file because browserify does.

    // transform file objects using gulp-tap plugin
    .pipe(tap(function (file) {

      gutil.log('bundling ' + file.path);

      // replace file contents with browserify's bundle stream
      file.contents = browserify(file.path, {debug: true}).bundle();

    }))

    // transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)
    .pipe(buffer())

    // load and init sourcemaps
    .pipe(sourcemaps.init({loadMaps: true}))

    .pipe(uglify())

    // write sourcemaps
    .pipe(sourcemaps.write('./'))

    .pipe(gulp.dest('dest'));

});

0 个答案:

没有答案