-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (62 loc) · 1.62 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
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
os = require('os'),
open = require('gulp-open');
var browser = os.platform() === 'linux' ? 'google-chrome' : (
os.platform() === 'darwin' ? 'google chrome' : (
os.platform() === 'win32' ? 'chrome' : 'firefox'));
gulp.task('app', function() {
var options = {
uri: 'http://localhost:4000',
app: browser
};
gulp.src('./index.html')
.pipe(open(options));
});
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({
port: 35729
}));
app.use(express.static(__dirname));
app.listen(4000, '0.0.0.0');
});
var tinylr;
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(35729);
});
function notifyLiveReload(event) {
var fileName = require('path').relative(__dirname, event.path);
tinylr.changed({
body: {
files: [fileName]
}
});
}
gulp.task('styles', function() {
return sass('sass', {
style: 'expanded'
})
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('css'))
.pipe(rename({
suffix: '.min'
}))
.pipe(minifycss())
.pipe(gulp.dest('css'));
});
gulp.task('watch', function() {
gulp.watch('sass/*.scss', ['styles']);
gulp.watch('*.html', notifyLiveReload);
gulp.watch('css/*.css', notifyLiveReload);
});
gulp.task('default', ['styles', 'express', 'app', 'livereload', 'watch'], function() {
});