-
Notifications
You must be signed in to change notification settings - Fork 228
/
gulpfile.js
98 lines (93 loc) · 2.4 KB
/
gulpfile.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var babel = require('rollup-plugin-babel');
var babelrc = require('babelrc-rollup');
var commonjs = require('rollup-plugin-commonjs');
var json = require('rollup-plugin-json');
var nodeResolve = require('rollup-plugin-node-resolve');
var rollup = require('rollup-stream');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
gulp.task('default', function() {
gulp.start('dist');
});
function roll(format, entry, name, entry_dir, dest_dir) {
name = (name || format) + '.js';
entry_dir = entry_dir || './src';
dest_dir = dest_dir || './dist';
return rollup({
entry: entry_dir + '/' + entry,
format: format,
exports: 'named',
moduleName: 'fb',
external: ['fs', 'path'],
globals: {
fs: 'fs',
path: 'path',
},
plugins: [
babel(
babelrc.default({
config: {
presets: [
[
'babel-preset-env',
{
'targets': 'defaults',
'exclude': ['transform-regenerator']
}
]
],
plugins: [
'external-helpers',
'syntax-flow',
'transform-flow-strip-types',
'async-to-promises',
],
exclude: ['node_modules/**', '**/*.json'],
},
})
),
nodeResolve({
skip: ['chai'],
}),
commonjs({
include: [
'node_modules/mixwith/*',
'node_modules/chai-as-promised/lib/*',
],
namedExports: {
mixwith: ['mix'],
'chai-as-promised': ['chaiAsPromised'],
},
}),
json(),
],
sourceMap: true,
})
.pipe(source(entry, entry_dir))
.pipe(buffer())
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.rename(name))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dest_dir));
}
gulp.task('dist', function(done) {
roll('amd', 'bundle.es6');
roll('cjs', 'bundle.es6');
roll('umd', 'bundle.es6');
roll('iife', 'bundle.es6');
roll('es', 'bundle.es6');
roll('cjs', 'globals.es6', 'globals');
done();
});