A Gulp plugin for Rollup ES6 Bundler. In comparison with gulp-rollup, this plugin integrates Rollup deeper into Gulps pipeline chain. It takes some of the Rollup API out of your hands, in exchange for giving you full power over the pipeline (to use any gulp plugins).
How it works
Rollup is designed to handle reading files, building a dependency tree, transforming content and then writing the transformed files. This doesn't play well with gulp, since gulp is also designed to handle files with
gulp.dest(). Gulp plugins, by design should just handle in-memory transformations. Not actual files.
To tackle this problem gulp-better-rollup passes the file paths loaded in
gulp.src() to rollup, rather than the gulp buffer.
This comes with some caveats:
- If you use other gulp plugin before gulp-better-rollup, their transformations will be lost. If the plugin doesn't do source transformations (like for example gulp-sourcemaps) this is fine.
- The Rollup "input" argument is unsupported.
- Since the output location is determined by
gulp.dest(), the output "file" argument passed to Rollup can at most be used to set the file name for a bundle. If you pass a full directory path, only the file name part will be used. In addition, if you pass a file path to
gulp.dest(), the Rollup "file" argument will be ignored entirely.
gulp-sourcemapsplugin doesn't (yet) support the
.mjsextension, that you may want to use to support the ES module format in Node.js. It can inline the sourcemap into the bundle file (using
sourcemaps.write()), and create an external sourcemap file with
sourcemaps.write(PATH_TO_SOURCEMAP_FOLDER). It won't however insert the
//# sourceMappingURL=linking comment at the end of your
.mjsfile, which effectively renders the sourcemaps useless.
npm install gulp-better-rollup --save-dev
You also need to install your own rollup (version 1.x.x).
gulp-better-rollup depends on your
rollup as a peer-dependency.
npm install rollup@^1 --save-dev
var gulp =var rename =var sourcemaps =var rollup =var babel =gulp
Usage & Options
This plugin is based on the standard Rollup options, with the following exceptions:
input is unsupported, as the entry file is provided by gulp, which also works with gulp-watch.
If you still need it for some reason, then you can specify a custom entry:
cache is enabled by default and taken care of by the plugin, because usage in conjunction with watchers like gulp-watch is expected. It can however be disabled by settings
Options describing the output format of the bundle. See
bundle.generate(outputOptions) in the Rollup API.
amd.id are inferred from the module file name by default, but can be explicitly specified to override this. For example, if your main file is named
main.js, then your module would also be named
main, which you may not want.
To use unnamed modules for amd, set
amd.id to an empty string, ex:
sourcemapFile are unsupported. Use the standard gulp-sourcemaps plugin instead.
You can skip this first argument if you don't need to specify
outputOptions accepts a string with the module format, in case you only want to support a single format.
outputOptions can also be specified as a shared object if you prefer simplicity over adherence to the Rollup JS API semantics.
Can be simplified into:
exporting multiple bundles
outputOptions can be an array, in order to export to multiple formats.
var pkg =gulp
Looking for maintainer
I no longer have time to dedicate myself to the project, nor do I use it in my current projects. I'd gladly accept new maintainers.