forked from Vesely/davo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
130 lines (103 loc) · 3.18 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
118
119
120
121
122
123
124
125
126
127
128
//Gulp variables
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(), //load all plugins
watch = require('gulp-watch'),
path = require('path');
var minifyHTML = require('gulp-minify-html'),
pngcrush = require('imagemin-pngcrush'),
browserSync = require('browser-sync');
//Path variables
var src = './src',
srcLessBase = path.join(src, 'less'),
srcLessFile = path.join(src, 'less/main.less'),
srcBase = path.join(src, 'js'),
srcImagesBase = path.join(src, 'img'),
srcBowerBase = path.join(src, 'bower_components');
var srcAll = path.join(src, '**'),
srcHtml = path.join(src, '**', '*.html'),
srcLessAll = path.join(srcLessBase, '**', '*.less'),
srcJavascriptAll = path.join(srcBase, '**', '*.js'),
srcImagesAll = path.join(srcImagesBase, '**', '*'),
srcBowerAll = path.join(srcBowerBase, '**', '*');
var dist = './dist',
distAll = path.join(dist, '**'),
distLess = path.join(dist, 'css'),
distJavascript = path.join(dist, 'js'),
distImages = path.join(dist, 'img'),
distBower = path.join(dist, 'bower_components');
//Configuration
var config = {
production: true
}
//Minify HTML
gulp.task('minify-html', function() {
var opts = {comments:true, spare:true};
gulp.src(srcHtml)
.pipe(minifyHTML(opts))
.pipe(gulp.dest(dist))
.pipe($.size({title: 'html'}))
.pipe($.livereload());
});
// Copy all files from SRC to DIST
gulp.task('copy', function () {
return gulp.src([src+'/*','!'+src+'/*.html'], {dot: true})
.pipe(gulp.dest(dist))
.pipe($.size({title: 'copy'}))
.pipe($.livereload());
});
//Minimalise Images
gulp.task('imagemin', function() {
gulp.src(srcImagesAll)
.pipe($.cache($.imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
})))
.pipe(gulp.dest(distImages))
.pipe($.size({title: 'images'}));
});
//LESS
gulp.task('less', function () {
gulp.src(srcLessFile)
.pipe($.less())
.pipe($.autoprefixer())
.pipe($.size({title: 'styles'}))
.pipe($.cssmin())
.pipe($.rename({suffix: '.min'}))
//.pipe($.pako.deflate())//Create deflate
.pipe(gulp.dest(distLess))
.pipe($.size({title: 'styles min'}))
.pipe($.livereload());
});
//Javascript compress
gulp.task('compress', function() {
gulp.src(srcJavascriptAll)
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.sourcemaps.write('maps'))
.pipe(gulp.dest(distJavascript))
.pipe($.size({title: 'javascript'}))
.pipe($.livereload());
});
// Static server
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: ['dist']
}
});
});
//Default
gulp.task('default', function() {
});
//Watch
gulp.task('watch', ['less', 'minify-html', 'imagemin', 'compress', 'copy', 'browser-sync'], function() {
//Watch changes (less, html, images, javascript)
gulp.watch(srcLessAll, ['less']);
gulp.watch(srcHtml, ['minify-html']);
gulp.watch(srcImagesAll, ['imagemin']);
gulp.watch(srcJavascriptAll, ['compress']);
gulp.watch([src+'/*','!'+src+'/*.html'], ['copy']);
gulp.src(srcBowerAll)
.pipe(gulp.dest(distBower));
});