-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
95 lines (80 loc) · 2.17 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
/* Modules & variables
-------------------------------------*/
var gulp = require('gulp');
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
images = require('gulp-imagemin');
uglify = require('gulp-uglify');
/* Paths
-------------------------------------*/
var paths = {
scss: 'stylesheets/main.scss',
css: 'build/css/',
cssReload: 'build/css/main.css',
html: '*.html',
js: 'scripts/main.js',
jsmin: 'build/scripts/'
};
/* Tasks
-------------------------------------*/
//Server
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({port: 4002}));
app.use(express.static(__dirname));
app.listen(4000);
});
//Live-reload
var tinylr;
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(4002);
});
//Styles
gulp.task('styles', function() {
return sass(paths.scss)
.on('error', function(err){
console.error('Error!', err.message);
})
.pipe(autoprefixer())
.pipe(gulp.dest(paths.css))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(paths.css));
});
function notifyLiveReload(event) {
var fileName = require('path').relative(__dirname, event.path);
tinylr.changed({
body: {
files: [fileName]
}
});
}
// Image minifyer
gulp.task("images", function(){
gulp.src(['res/images/*.jpg', 'res/images/*.png', 'res/images/**/*'])
.pipe(images({
progressive: true,
cache: false
}))
.pipe(gulp.dest("build/images"));
});
//JS uglify
gulp.task('uglify', function() {
gulp.src(paths.js)
.pipe(uglify())
.pipe(gulp.dest(paths.jsmin))
});
/* Watchers
-------------------------------------*/
gulp.task('watch', function() {
gulp.watch('stylesheets/**/*.scss', ['styles']);
gulp.watch(paths.js, ['uglify']);
gulp.watch(paths.html, notifyLiveReload);
gulp.watch(paths.cssReload, notifyLiveReload);
});
gulp.task('default', ['express', 'styles', 'uglify', 'livereload', 'watch'], function() {
});