-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
125 lines (113 loc) · 2.74 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
'use strict';
// Declare plugins
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const htmlhint = require('gulp-htmlhint');
const prettyHtml = require('gulp-pretty-html');
const plumber = require('gulp-plumber');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
const autoprefixer = require('gulp-autoprefixer');
const rimraf = require('gulp-rimraf');
const babel = require('gulp-babel');
// Config directories
const dirs = {
src: {
html: 'tasks/**/*.html',
styles: 'tasks/**/*.scss',
js: 'tasks/**/*.js',
vendors: 'tasks/**/vendors/*.*',
},
dist: {
html: 'dist/',
styles: 'dist/',
js: 'dist/',
vendors: 'dist/',
},
watch: {
html: 'tasks/**/*.html',
styles: 'tasks/**/*.scss',
js: 'tasks/**/*.js',
vendors: 'tasks/**/vendors/*.*',
},
clean: ['dist/*']
};
// Local Server
function server(done) {
browserSync.init({
server: {
baseDir: './dist/',
directory: true,
},
logPrefix: 'localhost',
notify: false,
});
done();
}
// Reload local server
function reloadServer(done) {
browserSync.reload();
done();
}
// Clean dist folder
function clean() {
return gulp.src(dirs.clean)
.pipe(rimraf());
}
// Build HTML
function buildHTML() {
return gulp.src(dirs.src.html)
.pipe(prettyHtml({
indent_size: 2,
extra_liners: [],
}))
.pipe(htmlhint('.htmlhintrc'))
.pipe(htmlhint.reporter())
.pipe(gulp.dest(dirs.dist.html));
}
// Build styles
function buildStyles() {
return gulp.src(dirs.src.styles)
.pipe(plumber())
.pipe(sass({
outputStyle: 'expanded',
indentWidth: 2
}))
.pipe(autoprefixer({
cascade: true
}))
.pipe(gulp.dest(dirs.dist.styles));
}
// Build JS
function buildJS() {
return gulp.src(dirs.src.js)
.pipe(plumber())
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest(dirs.dist.js));
}
// Copy vendors
function copyVendors() {
return gulp.src(dirs.src.vendors)
.pipe(gulp.dest(dirs.dist.vendors));
}
// Watch files
function watch() {
gulp.watch(dirs.watch.html, gulp.series(buildHTML, reloadServer));
gulp.watch(dirs.watch.styles, gulp.series(buildStyles, reloadServer));
gulp.watch(dirs.watch.js, gulp.series(buildJS, reloadServer));
gulp.watch(dirs.watch.vendors, gulp.series(copyVendors, reloadServer));
}
// Export tasks
exports.server = server;
exports.watch = watch;
exports.clean = clean;
exports.buildHTML = buildHTML;
exports.buildStyles = buildStyles;
exports.buildJS = buildJS;
exports.copyVendors = copyVendors;
const build = gulp.series(clean, gulp.parallel(buildHTML, buildStyles, buildJS, copyVendors));
exports.build = build;
// Default task
exports.default = gulp.series(build, server, watch);