-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
53 lines (50 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
var babel = require('rollup-plugin-babel');
var buffer = require('vinyl-buffer');
var defaultOptions = require('./lib/options');
var gulp = require('gulp');
var merge = require('merge');
var nodeResolve = require('rollup-plugin-node-resolve');
var presetEs2015Rollup = require('babel-preset-es2015-rollup');
var rollup = require('rollup-stream');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
module.exports = function(options) {
options = merge({}, defaultOptions, options);
gulp = options.gulp || gulp;
var warned = {};
return rollup(merge({
context: 'this',
entry: options.src,
format: 'umd',
moduleName: options.globalName,
plugins: [
babel({
compact: false,
presets: [presetEs2015Rollup]
}),
nodeResolve({
jsnext: true
})
],
sourceMap: true,
onwarn: function(message) {
if (!warned[message] && !shouldSkipMsg(message, options.skipWarnings)) {
console.warn(message);
warned[message] = true;
}
}
}, options.rollupConfig))
.pipe(source(options.bundleFileName))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(options.dest));
};
function shouldSkipMsg(message, skipWarnings) {
for (var i = 0; i < skipWarnings.length; i++) {
if (skipWarnings[i].test(message)) {
return true;
}
}
}