UNPKG

3.73 kBMarkdownView Raw
1# gulp-rollup [![npm][npm-image]][npm-url] [![Dependency Status][david-image]][david-url] [![Build Status][travis-image]][travis-url]
2
3This plugin allows [gulp](https://www.npmjs.com/package/gulp) to populate a virtual filesystem and feed it to the [Rollup](https://www.npmjs.com/package/rollup) ES6 module bundler.
4
5**Note: This plugin is not appropriate for most use cases,** as it requires every file expected to be imported by Rollup to be loaded into memory preemptively. [rollup-stream](https://github.com/gulpjs/gulp/blob/master/docs/recipes/rollup-with-rollup-stream.md) is preferred for almost all purposes. If you want to transform/synthesize/alias/etc. the files Rollup processes, use Rollup plugins; if there's no Rollup plugin to do what you want, try the gulp-to-Rollup plugin adapter, [rollup-plugin-gulp](https://www.npmjs.com/package/rollup-plugin-gulp). If you really need to synthesize your files in gulp, go ahead and use gulp-rollup—that's what it's made for.
6
7## Install
8
9``` bash
10npm install --save-dev gulp-rollup
11```
12
13## Usage
14
15``` js
16var gulp = require('gulp'),
17 rollup = require('gulp-rollup');
18
19gulp.task('bundle', function() {
20 gulp.src('./src/**/*.js')
21 // transform the files here.
22 .pipe(rollup({
23 // any option supported by Rollup can be set here.
24 entry: './src/main.js'
25 }))
26 .pipe(gulp.dest('./dist'));
27});
28```
29
30## Usage with sourcemaps
31
32``` js
33var gulp = require('gulp'),
34 rollup = require('gulp-rollup'),
35 sourcemaps = require('gulp-sourcemaps');
36
37gulp.task('bundle', function() {
38 gulp.src('./src/**/*.js')
39 .pipe(sourcemaps.init())
40 // transform the files here.
41 .pipe(rollup({
42 entry: './src/main.js'
43 }))
44 .pipe(sourcemaps.write())
45 .pipe(gulp.dest('./dist'));
46});
47```
48
49## Multiple entry points
50
51If an array of strings is passed into `options.entry`, a separate bundle will be rolled up from each entry point. They will be processed in parallel and output in no particular order. As usual, each bundle will have the same path as the associated entry file.
52
53In addition, a Promise that resolves to a string or array of strings can be passed into `options.entry`. This is to make it more convenient to use asynchronous methods to locate entry files.
54
55## Options
56
57In addition to [the standard Rollup options](https://github.com/rollup/rollup/wiki/JavaScript-API), gulp-rollup supports `options.rollup`, allowing you to use an older, newer, or custom version of Rollup by passing in the module like so:
58
59``` js
60gulp.src('./src/**/*.js')
61 .pipe(rollup({
62 rollup: require('rollup'),
63 entry: './src/main.js'
64 }))
65 //...
66```
67
68If `options.allowRealFiles` is set to true, gulp-rollup will break the gulp plugin guidelines just for you and allow Rollup to read files directly from the filesystem when a file with a matching name isn't found in the gulp stream. You could use this to weasel your way out of having to use rollup-stream, but that would make you a terrible person.
69
70By default, gulp-rollup will mimic Rollup by adding a .js extension to imports if necessary. You can customize this behavior by setting `options.impliedExtensions` to an array of extensions, like `['.js', '.es', '.jsx']`. If `options.impliedExtensions` is set to `false` or an empty array, file extensions in imports will be treated as mandatory.
71
72[npm-url]: https://npmjs.org/package/gulp-rollup
73[npm-image]: https://img.shields.io/npm/v/gulp-rollup.svg
74[david-url]: https://david-dm.org/mcasimir/gulp-rollup
75[david-image]: https://img.shields.io/david/mcasimir/gulp-rollup/master.svg
76[travis-url]: https://travis-ci.org/mcasimir/gulp-rollup
77[travis-image]: https://img.shields.io/travis/mcasimir/gulp-rollup/master.svg