forked from slavanga/pusha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (95 loc) · 2.58 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
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const log = require('fancy-log');
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const config = {
'src': '',
'dest': 'dist/',
'minify': true
};
// HTML
function html() {
return gulp.src(config.src + '*.html')
.pipe(browserSync.stream());
}
// Compile and autoprefix stylesheets
function styles() {
return gulp.src(config.src + 'scss/*.scss')
.pipe($.sass({
precision: 8,
outputStyle: 'expanded'
}).on('error', $.sass.logError))
.pipe($.postcss([
autoprefixer()
]))
.pipe(gulp.dest(config.dest + 'css'))
.pipe(browserSync.stream())
.pipe($.if(config.minify, $.cleanCss()))
.pipe($.if(config.minify, $.rename({suffix: '.min'})))
.pipe($.if(config.minify, gulp.dest(config.dest + 'css')))
.pipe(browserSync.stream());
}
// Lint stylesheets
function stylelint() {
return gulp.src(config.src + 'scss/**/*.scss')
.pipe($.postcss([
require('stylelint')({fix: true})
], {
syntax: require('postcss-scss')
}))
.pipe(gulp.dest(config.src + 'scss'));
}
// Compile javascript
function scripts() {
return gulp.src(config.src + 'js/*.js')
.pipe(gulp.dest(config.dest + 'js'))
.pipe(browserSync.stream())
.pipe($.if(config.minify, $.uglify({output: {comments: /^!/i}}).on('error', function(error) {
log.error(error.message);
this.emit('end');
})))
.pipe($.if(config.minify, $.rename({suffix: '.min'})))
.pipe($.if(config.minify, gulp.dest(config.dest + 'js')))
.pipe(browserSync.stream());
}
// Lint javascript
function eslint() {
return gulp.src(config.src + 'js/**/*.js')
.pipe($.eslint({fix: true}))
.pipe($.eslint.format())
.pipe(gulp.dest(config.src + 'js'));
}
// Serve compiled files
function serve(done) {
browserSync.init({
server: true,
notify: false,
snippetOptions: {
rule: {
match: /<\/body>/i
}
}
/*
proxy: 'example.com',
files: config.dest,
serveStatic: [{
route: '', // remote path
dir: config.dest // local path
}],
*/
});
done();
}
// Watch files for changes
function watch(done) {
gulp.watch(config.src + '*.html', html);
gulp.watch(config.src + 'scss/**/*.scss', styles);
gulp.watch(config.src + 'js/**/*.js', scripts);
done();
}
const build = gulp.parallel(html, styles, scripts);
gulp.task('build', build);
gulp.task('watch', watch);
gulp.task('lint', gulp.parallel(stylelint, eslint));
gulp.task('default', gulp.series(build, gulp.parallel(serve, watch)));