This repository has been archived by the owner on Dec 27, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
172 lines (154 loc) · 4.44 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
var gulp = require('gulp'),
// gulp modules
autoprefixer = require('gulp-autoprefixer'),
bower = require('gulp-bower'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
livereload = require('gulp-livereload'),
minifyHTML = require('gulp-minify-html'),
newer = require('gulp-newer'),
plumber = require('gulp-plumber'),
run = require('gulp-run'),
uglifyJs = require('gulp-uglify'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
twig = require('gulp-twig'),
// image optimizers
jpegtran = require('imagemin-jpegtran'),
optipng = require('imagemin-optipng'),
svgo = require('imagemin-svgo'),
// native modules
del = require('del'),
runSequence = require('run-sequence');
/**
* Installation tasks
*/
gulp.task('install-bower', function () {
return bower();
});
gulp.task('install', ['install-bower']);
/**
* Build templates tasks
*/
gulp.task('clean-templates', function (cb) {
del(['build/**/*.html'], cb);
});
gulp.task('build-pages', function () {
return gulp
.src([
'sources/pages/**/*.twig'
], { base: 'sources/pages' })
.pipe(plumber())
.pipe(twig())
.pipe(minifyHTML())
.pipe(gulp.dest('build'));
});
gulp.task('build-templates', ['build-pages']);
/**
* Build stylesheets tasks
*/
gulp.task('clean-stylesheets', function (cb) {
del(['build/stylesheets'], cb);
});
gulp.task('build-stylesheets', function () {
return gulp
.src([
'sources/stylesheets/website.scss'
])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(concat('website.css'))
.pipe(sourcemaps.write('.', {sourceRoot: '../'}))
.pipe(gulp.dest('build/stylesheets'));
});
/**
* Build javascripts tasks
*/
gulp.task('clean-javascripts', function (cb) {
del(['build/javascripts'], cb);
});
gulp.task('build-javascripts', function () {
return gulp
.src([
'bower_components/jquery/dist/jquery.js',
'bower_components/bootstrap-sass/assets/javascripts/bootstrap.js',
'sources/javascripts/**/*.js'
])
.pipe(plumber())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('website.js'))
.pipe(uglifyJs())
.pipe(sourcemaps.write('.', {sourceRoot: '../sources/javascripts'}))
.pipe(gulp.dest('build/javascripts'));
});
/**
* Build images tasks
*/
gulp.task('clean-images', function (cb) {
del(['build/images'], cb);
});
gulp.task('build-images', function () {
return gulp
.src([
'sources/images/**/*.{jpg,png,gif,svg}'
], { base: 'sources/images' })
.pipe(plumber())
.pipe(newer('build/images'))
.pipe(imagemin({
use: [jpegtran(), optipng(), svgo()]
}))
.pipe(gulp.dest('build/images'));
});
/**
* Build fonts task
*/
gulp.task('clean-fonts', function (cb) {
del(['build/fonts'], cb);
});
gulp.task('build-fonts', function () {
return gulp
.src([
'bower_components/font-awesome/fonts/*'
])
.pipe(plumber())
.pipe(newer('build/fonts'))
.pipe(gulp.dest('build/fonts'));
});
/**
* Global build tasks
*/
gulp.task('clean', ['clean-templates', 'clean-stylesheets', 'clean-javascripts', 'clean-images', 'clean-fonts']);
gulp.task('build', function () {
runSequence(
'clean',
['build-templates', 'build-stylesheets', 'build-javascripts', 'build-images', 'build-fonts']
);
});
gulp.task('watch', function () {
livereload.listen();
gulp.watch(['sources/pages/**/*.twig', 'sources/templates/**/*.twig'], function() {
runSequence('build-pages', livereload.changed);
});
gulp.watch('sources/stylesheets/**/**', function() {
runSequence('build-stylesheets', livereload.changed);
});
gulp.watch('sources/javascripts/**/**', function() {
runSequence('build-javascripts', livereload.changed);
});
gulp.watch('sources/images/**/*', function() {
runSequence('build-images', livereload.changed);
});
});
gulp.task('default', function () {
runSequence(
['build-templates', 'build-stylesheets', 'build-javascripts', 'build-images', 'build-fonts'],
'watch'
);
});