Skip to content

Instantly share code, notes, and snippets.

@tstpierre
Created March 29, 2016 16:09
Show Gist options
  • Save tstpierre/9109bf16b9f2431b74de to your computer and use it in GitHub Desktop.
Save tstpierre/9109bf16b9f2431b74de to your computer and use it in GitHub Desktop.
Example of merging legacy JavaScript and new TypeScript in the same build process
//
// Written in-gist, so there could be typos.
// The point of this is to show merging two gulp streams with event-stream.
//
var gulp = require('gulp');
var ts = require('gulp-typescript');
var eventStream = require('event-stream');
var concat = require('gulp-concat');
var paths = {
in: {
js: 'src/**/*.js'
},
out: {
js: 'dist/js'
}
};
var tsProj = ts.createProject('tsconfig.json');
gulp.task('default', ['build:script'], function () {
});
gulp.task('build:script', function () {
// store pipeable gulp stream of gulp-typescript JS output
var tsStream = tsProj.src()
.pipe(ts(tsProj)).js;
// store pipeable gulp stream of javascript glob
var jsStream = gulp.src(paths.in.js);
// merge streams and perform normal build steps
return eventStream.merge(tsStream, jsStream)
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.out.js));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment