-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
53 lines (48 loc) · 1.07 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var browserify = require('browserify');
var bundle = function(relpath) {
return browserify({
entries: [relpath],
transform: [
[
'babelify', {
presets: [
'es2015'
],
sourceMaps: true
}
]
],
debug: true
})
.bundle();
};
var browserifyBuffer = function(_bundle, minify, theSource) {
var stream = _bundle
.pipe(source(theSource))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }));
if (minify) {
stream.pipe(uglify());
}
stream
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('public/js'))
.on('end', function() {
console.log('File compiled & save.');
});
};
gulp.task('default', function() {
return browserifyBuffer(
bundle('./src/index.js'),
true,
'index.js'
);
});
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['default']);
});