-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
61 lines (56 loc) · 1.54 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
const gulp = require('gulp');
const path = require('path');
const browserify = require('browserify');
const babel = require('gulp-babel');
const insert = require('gulp-insert');
const rename = require('gulp-rename');
const source = require('vinyl-source-stream');
const uglify = require('uglify-es');
const uglifyComposer = require('gulp-uglify/composer');
const minify = uglifyComposer(uglify, console);
const convertNewline = require('gulp-convert-newline');
const DIST = './';
const VERSION = require('./package.json').version;
const FULL_HEADER = (
'/**\n' +
' * AsyncStreamEmitter v' + VERSION + ' browser bundle\n' +
' */\n '
);
const FULL_FOOTER = (
'\n' +
'export default AsyncStreamEmitter;' +
'\n'
);
gulp.task('browserify', (done) => {
let stream = browserify({
builtins: [],
entries: 'index.js',
standalone: 'AsyncStreamEmitter'
})
.ignore('_process')
.require('./index.js', {expose: 'async-stream-emitter'})
.bundle();
return stream.pipe(source('async-stream-emitter.js'))
.pipe(insert.prepend(FULL_HEADER))
.pipe(insert.append(FULL_FOOTER))
.pipe(convertNewline({
newline: 'lf',
encoding: 'utf8'
}))
.pipe(gulp.dest(DIST));
});
gulp.task('minify', () => {
return gulp.src(DIST + 'async-stream-emitter.js')
.pipe(babel({
comments: false
}))
.pipe(babel({
plugins: ['minify-dead-code-elimination']
}))
.pipe(minify())
.pipe(insert.prepend(FULL_HEADER))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest(DIST));
});