forked from students-org/spectral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
95 lines (83 loc) · 2.51 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
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const stylus = require('gulp-stylus');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const gulpIf = require('gulp-if');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const del = require('del');
const gutil = require('gulp-util');
const pug = require('gulp-pug');
const isDevelopment = process.env.NODE_ENV !== 'production';
gulp.task('views', function buildHTML() {
return gulp.src('./src/index.pug')
.pipe(pug())
.on('error', function(error) {
gutil.log(gutil.colors.red('Error: ' + error.message));
this.emit('end');
})
.pipe(gulp.dest('./dist'));
});
gulp.task('styles', function () {
return gulp.src('./src/app.styl')
.pipe(gulpIf(isDevelopment, sourcemaps.init()))
.pipe(stylus({
'include css': true
})
.on('error', function(error) {
gutil.log(gutil.colors.red('Error: ' + error.message));
this.emit('end');
}))
.pipe(gulpIf(!isDevelopment, postcss([
autoprefixer({
browsers: ['> 5%', 'ff > 14']
})
])))
.pipe(gulpIf(isDevelopment, sourcemaps.write()))
.pipe(gulpIf(!isDevelopment, cleanCSS()))
.pipe(rename('style.css'))
.pipe(gulp.dest('./dist/css'))
});
gulp.task('copy:fonts', function () {
return gulp.src([
'./node_modules/font-awesome/fonts/**/*.*'
])
.pipe(gulp.dest('./dist/fonts'));
});
gulp.task('copy:images', function () {
return gulp.src('./src/**/*.{png,jpg,jpeg,gif,svg}')
.pipe(rename(function (path) {
path.dirname = '';
}))
.pipe(gulp.dest('./dist/images'));
});
gulp.task('watch', function () {
gulp.watch('./src/**/*.pug', gulp.series('views'));
gulp.watch('./src/**/*.styl', gulp.series('styles'));
});
gulp.task('serve', function () {
browserSync.init({
server: './dist',
port: 8080
});
browserSync.watch('./dist/**/*.*').on('change', browserSync.reload);
});
gulp.task('clean', function () {
return del('./dist')
});
gulp.task('build', gulp.series(
'clean',
gulp.parallel(
'views',
'styles',
'copy:fonts',
'copy:images'
)));
gulp.task('default', gulp.series(
'build',
gulp.parallel(
'watch',
'serve'
)));