mardi 23 décembre 2014

How to use a stream as input for Browserify?


In Gulp, I'm trying to compile TypeScript, concatenate it, then run it through Browserify to handle the requires (then uglify after if in production mode).


This sample code is the closest I've found to what I'm trying to do, however it uses an intermediary file. I'd much rather keep things to the stream to avoid the overhead of the intermediary file if at all possible.


Since Browserify outputs a stream, it seems like it should know how to accept one as well.


The relevant code:



var gulp = require('gulp');
var browserify = requ
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var transform = require('vinyl-transform');
var typeScript = require('gulp-typescript');

gulp.task('scripts', function () {
return gulp.src([mySrcDir,'typings/**/*.d.ts'])
.pipe(sourcemaps.init())
.pipe(typeScript(typeScriptProject))
.pipe(concat('main.js'))
.pipe(transform(function (filename) {
return browserify(filename).bundle();
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(ns.outDir))
// Reload, notify...
;


The result:


Error: Cannot find module 'C:\path\to\project\root\src\main.js' in 'C:\path\to\project\root'


When I omit concatenation, the result is the same, except with foobar.js instead of main.js where foobar.ts is one of the input files.





Aucun commentaire:

Enregistrer un commentaire