-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
88 lines (74 loc) · 2.26 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
(function() {
'use strict'
const gulp = require('gulp')
const watch = require('gulp-watch')
const webpack = require('webpack-stream')
const sass = require('gulp-sass')
const browserSync = require('browser-sync').create()
const imagemin = require('gulp-imagemin')
const pug = require('gulp-pug')
const config = {
src: {
js: './src/js/**/*.js',
sass: './src/scss/**/*.scss',
html: './src/pug/**/*.pug',
image: './src/images/**/*.*'
},
dest: {
js: './dest/js',
sass: './dest/css/',
html: './dest/',
image: './dest/images'
}
}
const minifyJS = function() {
return gulp.src(config.src.js).pipe(webpack(require('./webpack.config.js'))).pipe(gulp.dest(config.dest.js)).pipe(browserSync.reload({stream: true, once: true}))
}
const minifySASS = function() {
return gulp.src(config.src.sass).pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)).pipe(gulp.dest(config.dest.sass)).pipe(browserSync.stream())
}
const minifyHTML = function() {
return gulp.src(config.src.html).pipe(pug().on('error', function(err){console.log(err)})).pipe(gulp.dest(config.dest.html)).pipe(browserSync.stream())
}
const imageMin = function() {
return gulp.src(config.src.image).pipe(imagemin({progressive: true})).pipe(gulp.dest(config.dest.image)).pipe(browserSync.stream())
}
gulp.task('minifyjs', function() {
minifyJS()
})
gulp.task('minifysass', function() {
minifySASS()
})
gulp.task('minifyHTML', function() {
minifyHTML()
})
gulp.task('imagemin', function() {
imageMin()
})
gulp.task('minify', ['minifyjs', 'minifysass', 'minifyHTML', 'imagemin'])
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './dest'
}
})
})
gulp.task('watch', ['browser-sync'], function() {
watch([
config.src.js, config.src.sass, config.src.html, config.src.image
], {
verbose: true
}, function(event) {
if (/\.js$/i.test(event.path)) {
minifyJS()
} else if (/\.scss$/i.test(event.path)) {
minifySASS()
} else if (/\.pug$/i.test(event.path)) {
minifyHTML()
} else {
imageMin()
}
})
})
gulp.task('default', ['minify', 'watch'])
})()