-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
73 lines (62 loc) · 1.86 KB
/
gulpfile.babel.js
File metadata and controls
73 lines (62 loc) · 1.86 KB
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
'use strict';
import gulp from 'gulp';
import browserSync from 'browser-sync';
import path from 'path';
import sourcemaps from 'gulp-sourcemaps';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserify from 'browserify';
import watchify from 'watchify';
import babel from 'babelify';
import uglify from 'gulp-uglify';
import shell from 'gulp-shell';
const dir = {
dist: path.resolve(__dirname, 'dist'),
demo: path.resolve(__dirname, 'demo'),
lib : path.resolve(__dirname, 'lib'),
main: path.resolve(__dirname, 'index.js')
};
let compile = (watch) => {
let bundler = watchify(browserify(dir.main, {debug: true}))
.transform(babel, {presets: ['es2015']});
let rebundle = () => {
bundler.bundle()
.on('error', (e) => {console.error(e);})
.pipe(source('uploader.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(dir.dist))
.on('end', () => {
browserSync.reload();
});
};
if (watch) {
bundler.on('update', () => rebundle());
}
rebundle();
};
gulp.task('compile', () => {
return compile();
});
gulp.task('watch', () => {
compile(true);
gulp.watch(path.resolve(dir.demo, '**/*'), ['reload']);
});
gulp.task('reload', () => {
browserSync.reload();
});
gulp.task('server', ['serve'], shell.task('node server/index.js'));
gulp.task('serve', ['watch'], () => {
browserSync.init({
server: {
baseDir: ['demo', 'dist']
},
port: 4444,
ui: {
port: 4000
}
});
});
gulp.task('default', ['server']);