-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
70 lines (59 loc) · 1.87 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
'use strict';
const gulp = require('gulp');
const path = require('path');
const runSequence = require('run-sequence');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const foreach = require('gulp-foreach');
const plumber = require('gulp-plumber');
const rollup = require('gulp-rollup');
const sourcemaps = require('gulp-sourcemaps');
const rollupPlugins = {
babel: require('rollup-plugin-babel'),
uglify: require('rollup-plugin-uglify'),
};
const JS_PATHS = {
dest: 'dist',
entryPoint: path.join('lib', 'rouge.js'),
srcGlob: path.join('lib', '*.js'),
};
function stripFlowTypes(s) {
return s.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel({
babelrc: false,
comments: process.env.NODE_ENV === 'development' ? true : false,
compact: process.env.NODE_ENV === 'development' ? true : false,
plugins: ['transform-flow-strip-types'],
sourceMaps: true,
}))
.pipe(sourcemaps.write('.'))
.pipe(plumber.stop())
.pipe(gulp.dest(path.join(JS_PATHS.dest, 'es6')));
}
gulp.task('bundleJS_es5', () => {
let plugins = [rollupPlugins.babel()];
if (process.env.NODE_ENV === 'production') {
plugins.push(rollupPlugins.uglify());
}
gulp.src(JS_PATHS.entryPoint, { read: false })
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(rollup({
format: 'cjs',
sourceMap: true,
plugins: plugins,
}))
.pipe(sourcemaps.write('.'))
.pipe(plumber.stop())
.pipe(gulp.dest(path.join(JS_PATHS.dest, 'es5')));
});
gulp.task('bundleJS_es6', () => {
gulp.src(JS_PATHS.srcGlob).pipe(foreach(stripFlowTypes));
});
gulp.task('watch', () => {
gulp.watch(JS_PATHS.srcGlob, ['bundleJS_es5', 'bundleJS_es6']);
});
gulp.task('default', () => {
runSequence(['bundleJS_es5', 'bundleJS_es6'], 'watch');
});