-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
72 lines (58 loc) · 1.75 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
var _ = require('underscore')
var path = require('path');
var gulp = require('gulp')
var gutil = require('gulp-util');
var less = require('gulp-less');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var browserify = require('browserify');
var browserSync = require('browser-sync');
function getBrowserify(options) {
options = options || {};
return browserify('.', _.extend({
extensions: ['.coffee']
}, options));
}
function bundleBrowserify(bundler) {
return bundler.bundle()
.on('error', gutil.log.bind(gutil, gutil.colors.red('Browserify Error')))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'));
}
gulp.task('browserify', function() {
return bundleBrowserify(getBrowserify());
});
gulp.task('watchify', function() {
var bundler = watchify(getBrowserify(watchify.args));
var bundle = bundleBrowserify.bind(null, bundler)
bundler.on('update', bundle);
bundler.on('update', function(ids) {
gutil.log([
gutil.colors.green('Updating Bundle...')
].concat(ids.map(function(id) {
return '-> ' + id;
})).join('\n'));
});
bundler.on('log', gutil.log.bind(gutil, gutil.colors.green('Bundle Updated')));
return bundle();
});
gulp.task('less', function() {
gulp.src('./app/styles/main.less')
.pipe(less({
paths: [path.join(__dirname, 'node_modules', 'bootstrap', 'less')]
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: ['app', 'dist']
}
});
});
gulp.task('serve', ['watchify', 'browser-sync'], function() {
gulp.watch(['app/styles/**/*.less'], ['less']);
gulp.watch(['dist/**/*', 'app/**/*.html'], browserSync.reload);
});
gulp.task('build', ['browserify', 'less']);
gulp.task('default', ['build']);