我应该“浏览”所有文件,然后为我的 gulp 管道“连接”它们吗?还是相反?

Should I `browserify` all files then `concat` them for my gulp pipeline? Or the inverse?

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

...
require("./other_file")
...

然后我的 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();
}

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

(我关注了the gulpfile example here

不需要连接。 Browserify 将跟踪您需要的所有模块并构建一个包。

browserify will recursively analyze all the require() calls in your app in order to build a bundle you can serve up to the browser in a single tag.

source