-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (90 loc) · 2.85 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 sass = require('gulp-sass')(require('sass'));
var gulp = require('gulp'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
cssnano = require('cssnano'),
cleanCSS = require('gulp-clean-css'),
concat = require('gulp-concat'), // Gulp file concatenation plugin
connect = require('gulp-connect'), // Gulp web server runner plugin
del = require('del');
const sourcemaps = require("gulp-sourcemaps");
var configuration = {
paths: {
src: {
html: './src/*.html',
styles: {
main: './src/scss/main.scss',
all: [
'./src/scss/**/*.scss'
]
},
images: [
'./src/images/**/*.{gif,jpg,png,svg,webp}'
],
assets: './static-assets/**/*'
},
dist: './output'
},
localServer: {
port: 3000,
url: 'http://localhost:3000/'
}
};
// Process HTML
gulp.task('html', function() {
return gulp.src(configuration.paths.src.html)
.pipe(gulp.dest(configuration.paths.dist))
.pipe(connect.reload());
});
// Process styles
gulp.task('styles', function () {
var processors = [
autoprefixer(),
cssnano()
];
return gulp.src(configuration.paths.src.styles.main)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss(processors))
.pipe(cleanCSS())
.pipe(sourcemaps.write('maps/'))
.pipe(gulp.dest(configuration.paths.dist + '/css'))
.pipe(connect.reload());
});
// Copy images
gulp.task('images', function () {
return gulp.src(configuration.paths.src.images, { encoding: false })
.pipe(gulp.dest(configuration.paths.dist + '/img'))
.pipe(connect.reload());
});
// Copy ancillary assets
gulp.task('assets', function () {
return gulp.src(configuration.paths.src.assets)
.pipe(gulp.dest(configuration.paths.dist + '/assets'));
});
// Create a web server
gulp.task('connect', async function () {
return connect.server({
root: configuration.paths.dist,
port: configuration.localServer.port,
livereload: true
});
});
// Watch the filesystem and reload the website automatically
gulp.task('watch', async function () {
gulp.watch(configuration.paths.src.html, gulp.series('html'));
gulp.watch(configuration.paths.src.styles.all, gulp.series('styles'));
gulp.watch(configuration.paths.src.images, gulp.series('images'));
});
// Clean ouput directory
gulp.task('clean', function() {
return del([configuration.paths.dist + '/**', '!'+ configuration.paths.dist]);
});
// Build tasks
gulp.task('build', gulp.parallel('html', 'styles', 'images', 'assets'));
// Distribute/production build task
gulp.task('release', gulp.series('clean', 'build'));
// Serve & watch with hot reload
gulp.task('serve', gulp.parallel('connect', 'watch'));
// Default development tasks
gulp.task('default', gulp.series('build', 'serve'));