generated from mate-academy/gulp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·91 lines (74 loc) · 2.2 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
'use strict';
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const gulpReplacePath = require('gulp-replace-path');
const distDirectory = 'dist';
const htmlBlob = 'src/*.html';
const imagesBlob = 'src/images/**';
const fontsBlob = 'src/fonts/**';
const stylesBlob = 'src/styles/**';
const jsBlob = 'src/scripts/**';
const { series, parallel } = gulp;
gulp.task('cleanDist', function() {
return gulp.src(distDirectory, { read: false, allowEmpty: true })
.pipe(clean());
});
gulp.task('processHtml', function() {
return gulp.src(htmlBlob)
.pipe(gulp.dest(distDirectory));
});
gulp.task('processImages', function() {
return gulp.src(imagesBlob)
.pipe(gulp.dest(`${distDirectory}/images/`));
});
gulp.task('processFonts', function() {
return gulp.src(fontsBlob)
.pipe(gulp.dest(`${distDirectory}/fonts/`));
});
gulp.task('processStyles', function() {
return gulp.src(stylesBlob)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(gulpReplacePath(/(?:\.\.\/){2,}images/g, '../images'))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${distDirectory}/styles`))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('processJs', function() {
return gulp.src(jsBlob)
.pipe(gulp.dest(`${distDirectory}/scripts/`));
});
gulp.task('build', series(
'cleanDist',
parallel(
'processStyles',
'processHtml',
'processImages',
'processFonts',
'processJs',
)
));
gulp.task('serve', function() {
browserSync.init({
notify: false,
server: {
baseDir: distDirectory,
},
port: 8080,
});
gulp.watch(htmlBlob, series('processHtml'))
.on('change', browserSync.reload);
gulp.watch(imagesBlob, series('processImages'))
.on('change', browserSync.reload);
gulp.watch(fontsBlob, series('processFonts'))
.on('change', browserSync.reload);
gulp.watch(stylesBlob, series('processStyles'));
gulp.watch(jsBlob, series('processJs'))
.on('change', browserSync.reload);
});
gulp.task('default', series('build', 'serve'));