我应该'浏览'所有文件然后`concat`他们为我的gulp管道?还是逆?

dal*_*ler 2 javascript browserify gulp babeljs

我开始打破一个Javascript客户端库,index.js并有一个额外的文件,我现在正在require顶部做一个.

...
require("./other_file")
...
Run Code Online (Sandbox Code Playgroud)

然后我gulpfile.js看起来像这样:

function compile(watch) {
  var bundler = watchify(browserify({
    entries: ['./src/index.js'],
    debug: true,
    sourceType: module,
  })
  .transform(babelify));

function rebundle() {
    bundler.bundle()
      .on('error', function(err) { console.error(err); this.emit('end'); })
      .pipe(source('build.js'))
      .pipe(buffer())
      .pipe(sourcemaps.init({ loadMaps: true }))
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest('./dist'));
  }

  if (watch) {
    bundler.on('update', function() {
      console.log('-> bundling...');
      rebundle();
    });
  }

  rebundle();
}
Run Code Online (Sandbox Code Playgroud)

我不确定我是否应该使用concat我需要的所有文件,然后浏览更大的concatted文件或只是browserify主文件,它require会起作用吗?

(我在这里遵循gulpfile示例)

Nic*_*lin 6

没有必要连接.Browserify将跟踪您需要的所有模块并构建一个捆绑包.

browserify将递归分析您应用中的所有require()调用,以便构建一个可以在单个标记中提供给浏览器的包.

资源