-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (75 loc) · 2.13 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify')
var rename = require('gulp-rename');
var buffer = require('vinyl-buffer');
var connect = require('gulp-connect');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var nunjucks = require('gulp-nunjucks-render');
var browserify = require('browserify');
var babelify = require('babelify');
var del = require('del');
var glob = require('glob');
var merge = require('merge-stream');
var source = require('vinyl-source-stream');
function consoleTimeStamp(txt) {
var date = new Date;
var timeStamp = '[' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds() + '] ';
console.log( timeStamp + txt );
}
gulp.task('connect', function() {
connect.server({
base: 'http://localhost',
port: 8080,
root: './public',
livereload: true
});
});
watch('scss/**/*.scss', function() {
consoleTimeStamp('Processing CSS styles')
console.time('Time');
gulp.src('./scss/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS())
.pipe(gulp.dest('./public/css'))
.pipe(connect.reload());
console.timeEnd('Time');
});
watch('src/templates/*.html', function () {
consoleTimeStamp('Rendering HTML templates')
console.time('Time');
del('./public/*.html');
gulp.src('src/templates/*.html')
.pipe(nunjucks({
path: ['./src/templates']
}))
.pipe(gulp.dest('./public'))
.pipe(connect.reload());
console.timeEnd('Time');
});
watch('src/js/*.js', function () {
consoleTimeStamp('Transpiling JS files')
console.time('Time');
del('./public/js/*.js');
var files = glob.sync('./src/js/*.js');
merge(files.map(function(file) {
return browserify({
entries: file,
debug: true
})
.transform(babelify)
.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(rename({dirname: ''}))
.pipe(gulp.dest("./public/js/"))
}))
.pipe(connect.reload());;
console.timeEnd('Time');
});
gulp.task('default', ['connect']);