-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
117 lines (98 loc) · 2.71 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
108
109
110
111
112
113
114
115
116
117
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var cssmin = require('gulp-cssmin');
var htmlmin = require('gulp-htmlmin');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var lr = require('tiny-lr');
var livereload = require('gulp-livereload');
var reloadServer = lr();
// Styles
gulp.task('styles', function () {
gulp.src('./src/scss/style.scss')
.pipe(sass({
errLogToConsole: true
}))
.pipe(autoprefixer({
browsers: ['last 4 versions']
}))
.pipe(gulp.dest('./src/css'))
.pipe(livereload({
auto: false
}));
});
// Minyfy Styles
gulp.task('cssmin', function () {
gulp.src('src/css/style.css')
.pipe(cssmin())
//.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/css'));
});
// index.html live reload
gulp.task('html', function () {
gulp.src('./src/index.html')
.pipe(livereload({
auto: false
}));
});
// Minify HTML
gulp.task('htmlmin', function() {
gulp.src('src/index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'))
});
// Minify JS
gulp.task('uglify', function() {
gulp.src('src/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// Optimize images
gulp.task('imagemin', function () {
return gulp.src('src/img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/img/'));
});
// Server for development
gulp.task('dev-server', function () {
var http = require('http');
var st = require('node-static');
var opts = {
cache: false
};
var file = new st.Server('./src/', opts);
var port = process.env.PORT || 3000;
http.createServer(function (req, res) {
file.serve(req, res);
}).listen(port);
console.log('App running in http://localhost:%s', port);
});
// Server for distribution
gulp.task('dist-server', function () {
var http = require('http');
var st = require('node-static');
var opts = {
cache: false
};
var file = new st.Server('./dist/', opts);
var port = process.env.PORT || 8000;
http.createServer(function (req, res) {
file.serve(req, res);
}).listen(port);
console.log('App running in http://localhost:%s', port);
});
// Watch files and run some tasks
gulp.task('watch', function () {
livereload.listen();
gulp.watch(['./src/scss/**/*.scss'], ['styles']);
gulp.watch(['./src/index.html'], ['html']);
});
gulp.task('default', ['watch', 'styles', 'html', 'dev-server']);
gulp.task('dist', ['styles', 'cssmin', 'htmlmin', 'uglify', 'imagemin', 'dist-server']);