-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
78 lines (60 loc) · 1.96 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
var gulp = require('gulp')
, browserify = require('browserify')
, exorcist = require('exorcist')
, path = require('path')
, source = require("vinyl-source-stream")
, uglify = require('gulp-uglify')
, watchify = require('watchify')
, gutil = require('gulp-util')
;
var publicDir = './dist'
, bundleName = '1vk.js'
, bundleMainPath = './index.js'
, mapfileName = bundleName + '.map'
, mapfilePath = path.join(publicDir, mapfileName)
, sourceRoot = "file://" + __dirname
;
function handleError() {
return function (err) {
gutil.log(gutil.colors.red(err));
};
}
gulp.task('browserify', function () {
return browserify({debug: false, standalone: '1VK'})
.add(bundleMainPath)
.bundle()
.pipe(source(bundleName))
.pipe(gulp.dest(publicDir));
});
gulp.task('uglify', ['browserify'], function () {
return gulp.src(path.join(publicDir, bundleName))
.pipe(uglify())
.pipe(gulp.dest(publicDir))
});
gulp.task('watch_browserify', function () {
var bundler, rebundle;
bundler = browserify(bundleMainPath, {
basedir: __dirname,
debug: true,
cache: {}, // required for watchify
packageCache: {}, // required for watchify
fullPaths: true // required to be true only for watchify
});
bundler = watchify(bundler);
rebundle = function () {
//noinspection JSUnresolvedFunction
var stream = bundler.bundle();
stream.on('error', handleError('Browserify'));
gutil.log(gutil.colors.cyan("start bundle"));
var result = stream
.pipe(exorcist(mapfilePath, mapfileName, sourceRoot))
.pipe(source(bundleName))
.pipe(gulp.dest(publicDir));
result.once('end', function () {
gutil.log(gutil.colors.cyan("complete bundle"));
});
};
bundler.on('update', rebundle);
return rebundle();
});
gulp.task('default', ['uglify']);