deepak1556 / gulp-browserify

Bundle modules with BrowserifyJS
MIT License
195 stars 45 forks source link

changing gulp.src seems to break require and/or externals #69

Closed akbr closed 10 years ago

akbr commented 10 years ago

I am using the require and external options to reduce build times. But things break when I pass browserify files from different directories.

Here is a very simple example.

This works:

gulp.task("vendor", function () {
  return gulp.src("./noop.js", {read:false}) // An empty file to start the stream
    .pipe(browserify({
      require: ["underscore"]
    }))
    .pipe(rename('vendor.js'))
    .pipe(gulp.dest('./build'));
});

gulp.task("app", function () {
  return gulp.src("./app.js", {read:false})
    .pipe(browserify({
      external: ["underscore"]
    }))
    .pipe(gulp.dest('./build'));
});

Result: I can access "underscore" in app.js. Everything works fine.

This doesn't work:

gulp.task("vendor", function () {
  return gulp.src("./noop.js", {read:false}) // An empty file to start the stream
    .pipe(browserify({
      require: ["underscore"]
    }))
    .pipe(rename('vendor.js'))
    .pipe(gulp.dest('./build'));
});

gulp.task("app", function () {
  return gulp.src("./anotherDirectory/app.js", {read:false}) // THIS IS THE ONLY LINE THAT CHANGED!
    .pipe(browserify({
      external: ["underscore"]
    }))
    .pipe(gulp.dest('./build'));
});

Result: I get an error like "Cannot find module 'h15NQi' from app.js.

Should changing the directory have this effect?