-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
82 lines (64 loc) · 2.12 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
const gulp = require('gulp');
const _ = require('lodash');
const rollup = require('rollup');
const rollupStream = require('rollup-stream');
const sourcemaps = require('gulp-sourcemaps');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const watch = require('rollup-watch');
const babel = require('rollup-plugin-babel');
const uglify = require('rollup-plugin-uglify');
const createServer = require('./server');
const rollupDevConfig = require('./rollup.dev.config');
const rollupBuildConfig = require('./rollup.build.config');
const rollupTestConfig = require('./rollup.test.config');
const config = require('./config.json');
const devServer = createServer();
const testServer = createServer(true);
gulp.task('default', ['server:dev'], () => {
const watcher = watch(rollup, rollupDevConfig);
watcher.on('event', (event) => {
console.log(event);
});
});
gulp.task('build', ['build:default', 'build:min', 'build:es5']);
gulp.task('test', ['server:test'], () => {
const watcher = watch(rollup, rollupTestConfig);
watcher.on('event', (event) => {
console.log(event);
});
});
gulp.task('server:dev', () => (
devServer.listen(config.devServer.port)
));
gulp.task('server:test', () => (
testServer.listen(config.testServer.port)
));
gulp.task('build:default', () => {
const config = _.cloneDeep(rollupBuildConfig);
return rollupStream(config)
.pipe(source('promise.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build'));
});
gulp.task('build:min', () => {
const config = _.cloneDeep(rollupBuildConfig);
config.plugins.push(uglify());
return rollupStream(config)
.pipe(source('promise.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build'));
});
gulp.task('build:es5', () => {
const config = _.cloneDeep(rollupBuildConfig);
config.entry = './lib/Promise.js';
config.format = 'cjs';
config.sourceMap = false;
return rollupStream(config)
.pipe(source('es5.js'))
.pipe(gulp.dest('./build'));
});