forked from plibither8/made-with-love-in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (60 loc) · 1.5 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
const autoprefixer = require('autoprefixer');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const cssnano = require('cssnano');
const del = require('del');
const gulp = require('gulp');
const inlineSource = require('gulp-inline-source');
const postcss = require('gulp-postcss');
const pug = require('gulp-pug');
const stylus = require('gulp-stylus');
const DATA = require('./data.json');
gulp.task('pug', () => {
const nameToCodeMap = {};
Object.keys(DATA).forEach(key => {
nameToCodeMap[DATA[key]] = key;
});
return gulp.src('src/pug/index.pug')
.pipe(pug({
locals: {
countryNames: nameToCodeMap
}
}))
.pipe(gulp.dest('public/'));
});
gulp.task('generateCss', () => {
return gulp.src('src/styl/index.styl')
.pipe(stylus())
.pipe(postcss([autoprefixer, cssnano]))
.pipe(gulp.dest('public/'));
});
gulp.task('inlineCss', () => {
return gulp.src('public/index.html')
.pipe(inlineSource())
.pipe(gulp.dest('public/'));
});
gulp.task('deleteCss', () => {
return del('public/index.css');
});
gulp.task('html', gulp.series(
'pug',
'generateCss',
'inlineCss',
'deleteCss'
)
);
gulp.task('js', () => {
return gulp.src('src/js/*.js')
.pipe(concat('index.js'))
.pipe(babel({
comments: false,
presets: ['env'],
minified: true
}))
.pipe(gulp.dest('public/'));
});
gulp.task('watch', () => {
gulp.watch('src/**/*', gulp.parallel('js', 'html'));
});
gulp.task('build', gulp.parallel('js', 'html'));
gulp.task('default', gulp.series('build', 'watch'));