-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.babel.js
127 lines (108 loc) · 2.69 KB
/
gulpfile.babel.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
126
127
import gulp from 'gulp';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import gulpLoadPlugins from 'gulp-load-plugins';
import syntax from 'postcss-scss';
import deleteEmpty from 'delete-empty';
import PLUGINS from './config/postcss.config';
import COPY_FILES from './config/copy-files.config';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
const debug = require('postcss-debug').createDebugger();
require('gulp-stats')(gulp);
gulp.task('pug', () => {
return gulp.src([
'src/pages/*.pug'
])
.pipe($.pugLinter())
.pipe($.pugLinter.reporter('fail').on('error', $.notify.onError()))
.pipe($.pug({
pretty: '\t'
}))
.pipe(gulp.dest('dist/'))
});
gulp.task('styles', () => {
return gulp.src([
'src/styles/main.scss'
])
.pipe($.newer('dist/css/'))
.pipe($.sourcemaps.init())
.pipe($.sass.sync(
{outputStyle: 'expanded'})
)
.pipe($.postcss(debug(PLUGINS), {parser: syntax}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/css/'))
.pipe($.size({title: 'styles'}))
});
gulp.task('lint:css', () => {
return gulp.src(['src/styles/**/*.scss','src/components/**/*.scss'])
.pipe($.stylelint({
reporters: [
{formatter: 'verbose', console: true}
],
failAfterError: false
}))
});
gulp.task('css-debug', ['styles'], () => {
debug.inspect()
})
gulp.task('images', () => {
return gulp.src('src/images/**/*')
.pipe($.newer('dist/images/'))
.pipe($.cache($.imagemin({
progressive: true,
interlaced: true
}))
)
.pipe(gulp.dest('dist/images/'))
.pipe($.size({title: 'images'}))
})
gulp.task('scripts', () => {
return gulp.src('src/**/*.js')
.pipe($.newer('dist/**/*.js'))
.pipe($.babel())
.pipe($.uglify())
.pipe(gulp.dest('dist/'))
.pipe($.size({title: 'scripts'}))
});
gulp.task('clean', () => del(['dist'], {dot: true}));
gulp.task('delete-empty', () => {
deleteEmpty.sync('dist/');
});
gulp.task('copy', () => {
return gulp.src(
COPY_FILES,
{
base: 'src'
})
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'copy'}))
});
gulp.task('serve', ['clean'], cb => {
runSequence(
['pug', 'styles', 'scripts', 'images'],
'copy',
'delete-empty',
cb
)
browserSync({
notify: false,
server: ['dist', 'src'],
port: 3000
});
gulp.watch(['src/**/**/*.pug'], ['pug', reload])
gulp.watch(['src/**/**/*.scss'], ['lint:css', 'styles', reload])
gulp.watch(['src/**/*.js'], ['scripts', reload])
});
gulp.task('default', ['clean'], cb => {
runSequence(
'styles',
'scripts',
['pug', 'copy'],
'images',
'delete-empty',
cb
)
});