-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
107 lines (92 loc) · 2.64 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
105
106
107
'use strict';
var browserify = require('browserify');
var ecstatic = require('ecstatic');
var gulp = require('gulp');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var livereload = require('gulp-livereload');
var path = require('path');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var config = {
scripts: {
source: './src/js/main.js',
destination: './public/js/',
filename: 'bundle.js'
},
templates: {
source: './src/**/*.html',
watch: './src/**/*.html',
destination: './public/'
},
styles: {
source: './src/**/*.css',
watch: './src/**/*.css',
destination: './public/css/'
},
assets: {
source: './src/assets/**/*.*',
watch: './src/assets/**/*.*',
destination: './public/'
}
};
function handleError(err) {
gutil.log(err);
gutil.beep();
return this.emit('end');
}
gulp.task('scripts', function() {
var build, bundle;
bundle = browserify({
entries: [config.scripts.source],
extensions: config.scripts.extensions,
debug: false
});
build = bundle.bundle().on('error', handleError).pipe(source(config.scripts.filename));
return build.pipe(gulp.dest(config.scripts.destination));
});
gulp.task('templates', function() {
return gulp.src(config.templates.source)
.pipe(gulp.dest(config.templates.destination))
.on('error', handleError)
.pipe(livereload({auto: false}));
});
gulp.task('styles', function() {
return gulp.src(config.styles.source)
.pipe(concat('style.css'))
.pipe(gulp.dest(config.styles.destination))
.pipe(livereload({auto: false}));
});
gulp.task('assets', function() {
return gulp.src(config.assets.source)
.pipe(gulp.dest(config.assets.destination));
});
gulp.task('server', function() {
return require('http').createServer(ecstatic({
root: path.join(__dirname, 'public')
})).listen(9001);
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch(config.templates.watch, ['templates']);
gulp.watch(config.styles.watch, ['styles']);
gulp.watch(config.assets.watch, ['assets']);
var bundle = watchify(browserify({
entries: [config.scripts.source],
extensions: config.scripts.extensions,
debug: true,
cache: {},
packageCache: {},
fullPaths: true
}));
return bundle.on('update', function() {
return bundle.bundle()
.on('error', handleError)
.pipe(source(config.scripts.filename))
.pipe(gulp.dest(config.scripts.destination))
.pipe(livereload());
}).emit('update');
});
gulp.task('no-js', ['templates', 'styles', 'assets']);
gulp.task('build', ['scripts', 'no-js']);
gulp.task('default', ['watch', 'no-js', 'server']);