-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
101 lines (89 loc) · 2.55 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
import gulp from 'gulp';
import sass from 'gulp-dart-sass';
import browserSync from 'browser-sync';
import pug from 'gulp-pug';
import htmlmin from 'gulp-htmlmin';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import postcss from 'gulp-postcss';
import del from 'del';
const server = browserSync.create();
const paths = {
source: {
// Include all pug and html files, except those in folders starting with _
pug: ["src/**/*.{pug,html}", "!src/_*/", "!src/_*/**/*"],
scss: "src/scss/**/*.s[ca]ss",
fonts: "src/fonts/*.{woff,woff2,eot,ttf,otf}",
images: "src/images/*",
misc: ["src/.*", "src/*.png", "src/*.xml", "src/*.webmanifest", "src/*.svg", "src/*.ico"]
},
dist: {
html: "dist",
css: "dist/css",
fonts: "dist/fonts",
images: "dist/images",
}
};
// Compile and minify html
function html() {
return gulp.src(paths.source.pug)
.pipe(pug())
.pipe(htmlmin())
.pipe(gulp.dest(paths.dist.html));
}
// Compile, prefix and minify scss
function css() {
const plugins = [
autoprefixer(),
cssnano()
];
return gulp.src(paths.source.scss)
.pipe(sass())
.pipe(postcss(plugins))
.pipe(gulp.dest(paths.dist.css));
}
/**
* Copy fonts to dist folder.
*/
function fonts() {
return gulp.src(paths.source.fonts)
.pipe(gulp.dest(paths.dist.fonts));
}
/**
* Copy images to dist folder.
*/
function images() {
return gulp.src(paths.source.images)
.pipe(gulp.dest(paths.dist.images));
}
// Copy misc files. Notably .nojekyll for GH pages and favicon files.
function misc() {
return gulp.src(paths.source.misc)
.pipe(gulp.dest(paths.dist.html));
}
// Remove the generated output.
function clean() {
return del(['dist']);
}
// Reload the browsersync server.
function reload(done) {
server.reload();
done();
}
// Run the live development server
function serve(done) {
server.init({
server: {
baseDir: './dist'
}
});
gulp.watch("src/**/*.{pug,html}", gulp.series(html, reload));
gulp.watch(paths.source.scss, gulp.series(css, reload));
gulp.watch(paths.source.fonts, gulp.series(fonts, reload));
gulp.watch(paths.source.images, gulp.series(images, reload));
done();
}
// Default export: Live development environment
export default gulp.series(clean, fonts, misc, images, css, html, serve);
// Build: build for production. Fonts are not included here
export const build = gulp.series(clean, misc, images, css, html);