-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
253 lines (231 loc) · 5.75 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* -------------------------------------------------------------------------
* SOLID DESIGN SYSTEM | @version 1.1.0 | @author Vantage Design | @license https://github.com/vantagedesign/solid-design-system/blob/master/LICENSE.md
* GulpJS workflow.
/* -------------------------------------------------------------------------
/* Define requirements */
/* Core */
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var browsersync = require('browser-sync');
/* css */
var cleancss = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
var scss = require('gulp-sass');
/* js */
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
/* images */
var imagemin = require('gulp-imagemin');
/* files */
var del = require('del');
/* Define source and destination paths for file types */
var dist = 'dist/';
var paths = {
html: {
src: 'src/**/*.html',
dest: dist
},
scss: {
src: 'src/css/**/*.scss',
dest: dist + 'css/'
},
css: {
src: 'src/css/**/*.css',
dest: dist + 'css/'
},
js: {
src: 'src/js/**/*.js',
dest: dist + 'js/'
},
plugins: {
js: {
src: [
'src/plugins/**/*.js'
],
dest: dist + 'js/'
}
},
img: {
src: 'src/img/**/*.{png,jpg,jpeg,svg,gif}',
dest: dist + 'img/'
},
copy: {
src: [
'src/**/*.*',
'!src/{css,js,img}/**/*.*',
'!src/**/*.{psd,ai}'
],
dest: dist
}
}
var autoprefix_setting = [
'last 2 version',
'> 1%',
'ie 8',
'ie 9',
'ios 6',
'android 4'
]
/* --------------------------------------------
* CSS processing
--------------------------------------------- */
/* Process CSS */
function css_process(){
return gulp.src(paths.css.src)
.pipe(plumber())
.pipe(autoprefixer(autoprefix_setting))
.pipe(gulp.dest(paths.css.dest))
.pipe(cleancss({keepBreaks: false}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(paths.css.dest))
.pipe(notify({message: 'CSS processed'})
);
}
/* Process SCSS */
function scss_process(){
return gulp.src(paths.scss.src)
.pipe(plumber())
.pipe(scss().on('error', scss.logError))
.pipe(autoprefixer(autoprefix_setting))
.pipe(gulp.dest(paths.css.dest))
.pipe(cleancss({keepBreaks: false}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(paths.scss.dest))
.pipe(notify({message: 'SCSS processed'})
);
}
/* --------------------------------------------
* Javascript processing
--------------------------------------------- */
/* Process ES5 JavaScript */
function js_process(){
return gulp.src(paths.js.src)
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.js.dest))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(paths.js.dest))
.pipe(notify({message: 'JavaScript processed'})
);
}
/* Process ES5 JavaScript plugins */
function js_plugins_process(){
return gulp.src(paths.plugins.js.src)
.pipe(plumber())
.pipe(concat('plugins.js'))
.pipe(gulp.dest(paths.plugins.js.dest))
.pipe(rename({ extname: '.min.js' }))
.pipe(uglify())
.pipe(gulp.dest(paths.plugins.js.dest))
.pipe(notify({message: 'JavaScript plugins processed'})
);
}
/* --------------------------------------------
* Image processing
--------------------------------------------- */
/* Minify .png, .jpeg, .svg and .gif assets */
function img_process() {
return gulp.src(paths.img.src)
.pipe(plumber())
.pipe(imagemin())
.pipe(gulp.dest(paths.img.dest))
.pipe(notify({message: 'Images processed'}));
}
/* Copy img files to their dest */
function img_copy() {
return gulp.src(paths.img.src, {base: 'src/img/'})
.pipe(gulp.dest(paths.img.dest))
}
/* --------------------------------------------
* HTML processing
--------------------------------------------- */
/* Copy all HTML files without any modifications */
function html_process() {
return gulp.src(paths.html.src, {base: 'src/'})
.pipe(gulp.dest(paths.html.dest))
}
/*---------------------------------------------
* Copy other files
*---------------------------------------------*/
/* Copy other src files to their dest */
function copy_files() {
return gulp.src(paths.copy.src, {base: 'src/'})
.pipe(gulp.dest(paths.copy.dest))
}
/* --------------------------------------------
* Launch browsersync server
--------------------------------------------- */
/* Launch a live-reloading server with the dist folder as root */
gulp.task('devserver', function(cb){
browsersync.init(['**/*.css', '**/*.js', '**/*.html', '**/*.php,'], {
server: {
baseDir: dist
}
}, cb);
console.log('Development server started');
});
/*---------------------------------------------
* Cleanup
*---------------------------------------------*/
/* Clean dist by removing all files */
function clean_dist() {
return del(dist);
}
/*---------------------------------------------
* Gulp functions & tasks
*---------------------------------------------*/
/* Define files to watch */
function watch(cb) {
gulp.watch(paths.html.src, html_process);
gulp.watch(paths.css.src, css_process);
gulp.watch(paths.scss.src, scss_process);
gulp.watch(paths.js.src, js_process);
gulp.watch(paths.plugins.js.src, js_plugins_process);
gulp.watch(paths.copy.src, copy_files);
gulp.watch(paths.img.src, img_process);
cb();
}
/* Internal tasks */
var init = gulp.series(
clean_dist,
css_process,
scss_process,
js_process,
js_plugins_process,
html_process,
copy_files,
img_copy
);
/* Exposed tasks */
/* Build, watch and serve files on a dev server */
gulp.task('dev',
gulp.series(
init,
gulp.parallel(
watch,
'devserver'
)
)
);
/* Build files for distribution */
gulp.task('build',
gulp.series(
clean_dist,
css_process,
scss_process,
js_process,
js_plugins_process,
html_process,
copy_files,
img_process
)
);
/* Clean build files */
gulp.task('clean',
gulp.series(
clean_dist
)
);