/
gulpfile.js
102 lines (93 loc) · 2.36 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
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const cssnext = require('postcss-cssnext');
const del = require('del');
const minifyCSS = require('gulp-clean-css');
const minifyHTML = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
// Define paths. The order is important.
const paths = {
css: [
'./src/css/settings/variables.css',
'./node_modules/normalize-css/normalize.css',
'./src/css/settings/base.css',
'./src/css/settings/typography.css',
'./src/css/settings/responsive.css',
'./src/modules/objects/**/*.css',
'./src/modules/components/**/**/*.css',
'./src/modules/utilities/**/**/*.css',
'./src/css/shame.css'
],
js: [
'./src/js/*.js',
'./src/modules/**/**/*.js',
'./src/modules/**/**/**/*.js'
],
img: [
'./src/modules/**/**/*.+(png|jpg|svg|ico)',
'./src/modules/**/**/**/*.+(png|jpg|svg|ico)',
'./src/assets/img/**/*.+(png|jpg|svg|ico)',
'./src/assets/img/*.+(png|jpg|svg|ico)'
]
};
// CSS task
gulp.task('css', function () {
const processors = [
cssnext
];
gulp
.src(paths.css)
.pipe(concat('app.css'))
.pipe(postcss(processors))
.pipe(minifyCSS())
.pipe(gulp.dest('./static/css/'));
});
// Image minification task
// PNGs 8bitified, JPEGs progressified, SVGs optimised
gulp.task('minimage', () =>
gulp
.src(paths.img)
.pipe(imagemin({ progressive: true, pngquant: true, optimizationLevel: 3 }))
.pipe(rename({ dirname: '' }))
.pipe(gulp.dest('./static/img'))
);
// JS uglify
gulp.task('js', () =>
gulp
.src(paths.js)
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(gulp.dest('./static/js'))
);
// Clean task
gulp.task('clean', function(cb) {
del(['./static/**/*'], cb);
});
// Watch task
gulp.task('watch', function() {
gulp.watch(paths.css, ['css']);
gulp.watch(paths.js, ['uglification']);
gulp.watch(paths.img, ['minimage']);
});
// Browsersync
gulp.task('browser-sync', function() {
browserSync.init({
proxy: "http://localhost:1313/"
});
});
// Clean task, delete generated files
gulp.task('clean', function(cb) {
del(['./static/**/*'], cb);
});
// Default task
gulp.task('default', [
'browser-sync',
'css',
'minimage',
'js',
'watch'
]);