Skip to content

Commit b42acd9

Browse files
lemmabitphated
authored andcommitted
Docs: Add "Rollup with rollup-stream" recipe. (#1690)
1 parent 3623061 commit b42acd9

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

docs/recipes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
* [Templating with Swig and YAML front-matter](templating-with-swig-and-yaml-front-matter.md)
2626
* [Run Grunt Tasks from Gulp](run-grunt-tasks-from-gulp.md)
2727
* [Exports as tasks](exports-as-tasks.md)
28+
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Rollup with rollup-stream
2+
3+
Like Browserify, [Rollup](http://rollupjs.org/) is a bundler and thus only fits naturally into gulp if it's at the start of the pipeline. Unlike Browserify, Rollup doesn't natively produce a stream as output and needs to be wrapped before it can take this position. [rollup-stream](https://github.com/Permutatrix/rollup-stream) does this for you, producing output just like that of Browserify's `bundle()` method—as a result, most of the Browserify recipes here will also work with rollup-stream.
4+
5+
## Basic usage
6+
```js
7+
// npm install --save-dev rollup-stream vinyl-source-stream
8+
var gulp = require('gulp');
9+
var rollup = require('rollup-stream');
10+
var source = require('vinyl-source-stream');
11+
12+
gulp.task('rollup', function() {
13+
return rollup({
14+
entry: './src/main.js'
15+
})
16+
17+
// give the file the name you want to output with
18+
.pipe(source('app.js'))
19+
20+
// and output to ./dist/app.js as normal.
21+
.pipe(gulp.dest('./dist'));
22+
});
23+
```
24+
25+
## Usage with sourcemaps
26+
```js
27+
// npm install --save-dev rollup-stream gulp-sourcemaps vinyl-source-stream vinyl-buffer
28+
// optional: npm install --save-dev gulp-rename
29+
var gulp = require('gulp');
30+
var rollup = require('rollup-stream');
31+
var sourcemaps = require('gulp-sourcemaps');
32+
//var rename = require('gulp-rename');
33+
var source = require('vinyl-source-stream');
34+
var buffer = require('vinyl-buffer');
35+
36+
gulp.task('rollup', function() {
37+
return rollup({
38+
entry: './src/main.js',
39+
sourceMap: true
40+
})
41+
42+
// point to the entry file.
43+
.pipe(source('main.js', './src'))
44+
45+
// buffer the output. most gulp plugins, including gulp-sourcemaps, don't support streams.
46+
.pipe(buffer())
47+
48+
// tell gulp-sourcemaps to load the inline sourcemap produced by rollup-stream.
49+
.pipe(sourcemaps.init({loadMaps: true}))
50+
51+
// transform the code further here.
52+
53+
// if you want to output with a different name from the input file, use gulp-rename here.
54+
//.pipe(rename('index.js'))
55+
56+
// write the sourcemap alongside the output file.
57+
.pipe(sourcemaps.write('.'))
58+
59+
// and output to ./dist/main.js as normal.
60+
.pipe(gulp.dest('./dist'));
61+
});
62+
```

0 commit comments

Comments
 (0)