-
Notifications
You must be signed in to change notification settings - Fork 664
Description
Hi!
tl;dr: Request to make r.js work on a stream of files instead of using the node file API directly.
gulp.js is a js task runner that makes it easy to chain a multi-step build process together, e.g.
gulp.task("default", function () {
return gulp.src("app/**/*.js")
.pipe(jsLint())
.pipe(stripComments())
.pipe(rjsOptimize())
.pipe(filter("main.js", "lib.js", "extras.js"))
.pipe(minify())
.pipe(addCopyrightHeaders)
.pipe(gulp.dest('dist/'));
});Technically, gulp.src() returns an object stream of Vinyl files that can be piped to plugins. A 'plugin' here is e.g. jsLint(), stripComments() etc.
There's about a dozen or so r.js plugins for gulp - but none of them worked for me. The reason is that r.js is can neither receive a "stream of files" nor write one. It directly operates on "native" node files. So to work with gulp you either need to scratch the whole "streams" idea (which is the whole point of gulp.js) or do something awkward like:
(This doesn't reall work this way, as a stream is not a promise, but you get the idea)
gulp.task("default", function () {
return gulp.src("app/**/*.js")
.pipe(jsLint())
.pipe(stripComments())
.pipe(gulp.dest('build/rjs-input')).then(function () {
return rjsOptimize({
baseDir: "build/rjs-input",
dir: "build/rjs-output"
});
}).then(function () {
gulp.src("build/rjs-output/**/*.js").
.pipe(filter("main.js", "lib.js", "extras.js"))
.pipe(minify())
.pipe(addCopyrightHeaders)
.pipe(gulp.dest('dist/'));
});
});Which makes it a bit awkward, you see?
Would you consider implementing / merging a patch to r.js that allows r.js to work on streams?
Thanks in advance for your reply!
Cheers,
Kosta