javascript - 使用 browserify 和 gulp 进行多个 bundle

标签 javascript build bundle gulp

我找不到任何使用 gulp 和 browserify 来构建多个包的示例。

我只想做that一口气。

我找到了这个repo但我如何将它使用到 gulpfile 中。

最佳答案

我认为这个问题没有引起太多关注,因为 browserify 被错误地拼写为 browerify

如果您仍然感兴趣,这里有一个 gulpfile.js 配方示例,其功能与 example in node-browserify docs 完全相同。

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');

gulp.task('default', ['build-common', 'build-beep', 'build-boop']);

gulp.task('build-common', function () {
  var b = browserify()
    .require('./robot'); // same as -r option

  var stream = b.bundle()
    .pipe(source('common.js')) // the output filename
    .pipe(gulp.dest('./static/')); // the output directory
  return stream;
});

gulp.task('build-beep', function () {
  var b = browserify('./beep.js')
    .external('./robot.js'); // same as -e option

  var stream = b.bundle()
    .pipe(source('beep.js')) // the output filename
    .pipe(gulp.dest('./static/')); // the output directory
  return stream;
});

gulp.task('build-boop', function () {
  var b = browserify('./boop.js')
    .external('./robot.js'); // same as -e option

  var stream = b.bundle()
    .pipe(source('boop.js')) // the output filename
    .pipe(gulp.dest('./static/')); // the output directory
  return stream;
});

当然,这有点冗长,但我希望这可以帮助您入门。

我写了一些与 browserify 相关的 gulp 食谱,可能有用:https://github.com/sogko/gulp-recipes

关于javascript - 使用 browserify 和 gulp 进行多个 bundle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382700/

相关文章:

javascript - 返回 promise 的 ember Controller 中的单元测试操作

javascript - Ember 中的 CSS 类是否需要多个计算属性?

testing - Teamcity 重新运行特定的失败不稳定测试

asp.net-mvc - bundle 样式不起作用,但直接链接标签起作用

Java extras 包返回空值

javascript - 使用基于ajax的客户端上传PHP文件不起作用

javascript - 从 google chrome 选项卡获取 url

build - Gradle 构建 : does someone tried alternative build script with alternative setting. Gradle ?

c++ - 如何在 Visual Studio 中的干净构建期间删除 dlldata.c?

java - 为什么 Jar Bundler 在 Mac OS X Mountain Lion 10.8.2 中消失了