This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (88 loc) · 2.36 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
var gulp = require('gulp');
var util = require('gulp-util');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var publicJsDir = 'source/js';
var publicJsRoot = './' + publicJsDir + '/main.js';
var jsDest = './public/dist';
var jsMin = 'main.min.js';
var jsGlob = ['package.json', 'gulpfile.js', 'app/**/*.js', 'source/**/*.js'];
var lessSrc = 'source/less/main.less';
var lessSrcGlob = ['source/less/**/*.less'];
var lessDest = 'public/dist';
gulp.task('lint', function() {
gulp.src(jsGlob)
.pipe(jshint({
esnext: true,
curly: true,
eqeqeq: true,
eqnull: true,
globalstrict: true,
camelcase: true,
indent: 2,
immed: true,
latedef: 'nofunc',
newcap: true,
quotmark: true,
undef: true,
unused: true,
trailing: true,
node: true,
browser: true,
globals: {
Range: true,
Promise: true,
$: true
}
}))
.on('error', handleError)
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('browserify', function() {
var bundler = browserify({
entries: [publicJsRoot],
debug: true
});
var bundle = function() {
return bundler
.transform(babelify)
.bundle()
.on('error', util.log.bind(util, 'Browserify Error'))
.pipe(source(jsMin))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(jsDest));
};
return bundle();
});
gulp.task('less', function () {
gulp.src(lessSrc)
.pipe(less({
paths: [],
compress: true
}))
.on('error', handleError)
.pipe(gulp.dest(lessDest));
});
gulp.task('watch', function () {
gulp.watch(jsGlob, ['lint', 'build_js']);
gulp.watch(lessSrcGlob, ['build_css']);
});
gulp.task('build', ['build_js', 'build_css']);
gulp.task('build_js', ['lint', 'browserify']);
gulp.task('build_css', ['less']);
gulp.task('default', ['build', 'watch']);
/* Helpers
============================================================================= */
function handleError (error) {
util.log(error.message);
}