Skip to content

Commit

Permalink
Support options.input
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmabit committed Sep 11, 2017
1 parent 2acfd71 commit afdbbe6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 65 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -21,7 +21,7 @@ gulp.task('bundle', function() {
// transform the files here.
.pipe(rollup({
// any option supported by Rollup can be set here.
entry: './src/main.js'
input: './src/main.js'
}))
.pipe(gulp.dest('./dist'));
});
Expand All @@ -39,7 +39,7 @@ gulp.task('bundle', function() {
.pipe(sourcemaps.init())
// transform the files here.
.pipe(rollup({
entry: './src/main.js'
input: './src/main.js'
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist'));
Expand All @@ -48,9 +48,9 @@ gulp.task('bundle', function() {

## Multiple entry points

If 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.
If an array of strings is passed into `options.input`, 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.

In 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.
In addition, a Promise that resolves to a string or array of strings can be passed into `options.input`. This is to make it more convenient to use asynchronous methods to locate entry files.

## Options

Expand All @@ -62,7 +62,7 @@ In addition to [the standard Rollup options](https://github.com/rollup/rollup/wi
gulp.src('./src/**/*.js')
.pipe(rollup({
rollup: require('rollup'),
entry: './src/main.js'
input: './src/main.js'
}))
//...
```
Expand All @@ -87,7 +87,7 @@ var caches = {};
gulp.task('bundle', function() {
gulp.src('./src/**/*.js')
.pipe(rollup({
entry: ['./src/main1.js', './src/main2.js'],
input: ['./src/main1.js', './src/main2.js'],
separateCaches: caches
}))
.on('bundle', function(bundle, name) {
Expand All @@ -111,7 +111,7 @@ var cache;
gulp.task('bundle', function() {
gulp.src('./src/**/*.js')
.pipe(rollup({
entry: ['./src/main1.js', './src/main2.js'],
input: ['./src/main1.js', './src/main2.js'],
cache: cache,
generateUnifiedCache: true
}))
Expand Down
16 changes: 12 additions & 4 deletions index.js
Expand Up @@ -71,18 +71,22 @@ function GulpRollup(options) {
var wonderland = {}, vinylFiles = {};
var haveSourcemaps;

var entryFiles = Promise.resolve(options.entry).then(function(entryFiles) {
var inputWasNamedEntry = Boolean(options.entry);
var inputName = inputWasNamedEntry ? 'options.entry' : 'options.input';
var entryFiles = Promise.resolve(
inputWasNamedEntry ? options.entry : options.input
).then(function(entryFiles) {
if (typeof entryFiles === 'string') {
return [entryFiles];
} else if (Array.isArray(entryFiles)) {
if (entryFiles.some(function(entryFile) {
return typeof entryFile !== 'string';
})) {
throw new Error('options.entry must include only strings!');
throw new Error(inputName + ' must include only strings!');
}
return entryFiles;
} else {
throw new Error('options.entry must be a string or array of strings!');
throw new Error(inputName + ' must be a string or array of strings!');
}
});

Expand Down Expand Up @@ -133,7 +137,11 @@ function GulpRollup(options) {
entryFiles.then(function(entryFiles) {
return Promise.all(entryFiles.map(function(entryFile) {
var options = cloneWithBlacklist(options1);
options.entry = entryFile;
if (inputWasNamedEntry) {
options.entry = entryFile;
} else {
options.input = entryFile;
}
if (separateCaches && Object.prototype.hasOwnProperty.call(separateCaches, entryFile)) {
options.cache = separateCaches[entryFile];
}
Expand Down

0 comments on commit afdbbe6

Please sign in to comment.