This repository has been archived by the owner on Dec 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
190 lines (152 loc) · 5.03 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Notes :
// https://github.com/pwnjack/GulpJS-Bootstrap-LESS/blob/master/gulpfile.js
// A list of gulp plugins : https://www.npmjs.org/search?q=gulpplugin
var gulp = require('gulp'),
// Global tools
browserSync = require('browser-sync'),
gutil = require('gulp-util'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
filesize = require('gulp-filesize'),
uglify = require('gulp-uglify'),
// For less-css files
less = require('gulp-less'),
prefixer = require('gulp-autoprefixer'),
uncss = require('gulp-uncss'),
// For jade
jade = require('gulp-jade'),
// HTML validation
htmlvalidator = require('gulp-w3cjs'),
// For image files
changed = require('gulp-changed'),
imagemin = require('gulp-imagemin');
// Paths
var paths = {
base : './',
build : './build',
src : './src',
js : {
files : ['./src/js/vendor/*.js','./src/js/*.js'],
output_min : 'main.min.js',
dest : './build/assets/js',
},
style : {
files : ['./src/less/*.less', '!./src/less/_*.less'],
watch : './src/less/*.less',
output : 'style.css',
output_min : 'style.min.css',
dest : './build/assets/css'
},
layout : {
files : './src/*.jade',
watch : './src/**/*.jade',
dest : './build'
},
validator : {
watchables : './build/*.html',
},
images : {
files : './src/images/**/*',
icons : './src/favicons',
dest : './build/assets/images'
},
};
// The tasks
// ------------------------------
// A debug thing for me
gulp.task('debug', function() {
process.stdout.write(paths.js.files);
});
// Static server
gulp.task('server', function() {
browserSync.init(null, {
server: {
baseDir: paths.build
}
});
});
// Tasks specs
// 0. Cleaning before building
// 1. Less processed
// 2. Prefixed
// 3. Copied as style.css in ./build/assets/css
// 4. Minified
// 5. Copied as style.min.css in ./build/assets/css
// 6. Reload Browser sync
gulp.task('clean', function () {
return gulp.src(paths.js.dest + '/*', {read: false})
.pipe(clean());
});
gulp.task('style', function () {
return gulp.src(paths.style.files)
.pipe(plumber())
.pipe(less())
.pipe(prefixer('last 5 versions', 'ie 8'))
.pipe(gulp.dest(paths.style.dest))
.pipe(rename(paths.style.output))
// .pipe(uncss({
// html: ['index.html']
// }))
.pipe(less({ compress: true }))
.pipe(rename(paths.style.output_min))
.pipe(gulp.dest(paths.style.dest))
.pipe(browserSync.reload({stream:true}));
}
);
gulp.task('js', function() {
return gulp.src(paths.js.files)
.pipe(plumber())
.pipe(concat(paths.js.output_min))
.pipe(uglify()) // = concat+ugly
.pipe(gulp.dest(paths.js.dest))
.pipe(filesize())
.pipe(browserSync.reload({stream:true}));
});
// Jade templates
// 1. Jade processed with pretty output
// 2. Copy generated file to html destination
// 3. Reload BS
gulp.task('templates', function() {
return gulp.src(paths.layout.files)
.pipe(plumber())
.pipe(jade({pretty : true}))
.pipe(gulp.dest(paths.build))
.pipe(browserSync.reload({stream:true}));
});
// HTML validation
gulp.task('htmlvalidator', function () {
return gulp.src(paths.validator.watchables)
.pipe(htmlvalidator());
});
// Image files compression
// 1. Compressing only modified pictures
// 2. Compressed images to destination
gulp.task('images', function () {
return gulp.src(paths.images.files)
.pipe(changed(paths.images.dest))
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(paths.images.dest));
});
// Favicons and touch icons
gulp.task('icons', function () {
return gulp.src(paths.images.icons + 'favicon.png')
.pipe(rename('favicon.ico'))
.pipe(gulp.dest(paths.build));
});
gulp.task('touchicons', function() {
return gulp.src(paths.images.icons + '/apple-touch*.png')
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(paths.build));
});
// Watch modifications
gulp.task( 'watch', function () {
gulp.watch( paths.style.watch, ['style'] );
gulp.watch( paths.images.files, ['images'] );
gulp.watch( paths.layout.watch, ['templates'] );
gulp.watch( paths.layout.output, ['htmlvalidator'] );
gulp.watch( paths.js.files, ['js'] );
});
gulp.task('default', ['clean', 'images', 'templates', 'style', 'js', 'icons', 'touchicons', 'htmlvalidator', 'server', 'watch']);
gulp.task('build', ['clean', 'images', 'templates', 'style', 'js', 'icons', 'touchicons', 'htmlvalidator']);