-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (65 loc) · 1.9 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
const {src,dest,parallel,series,watch}= require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const autoprefixer=require('gulp-autoprefixer');
const cleanCSS=require('gulp-clean-css');
const imagemin= require('gulp-imagemin');
const notify= require('gulp-notify');
const del = require('del');
function serverTask() {
browserSync.init({
server: {
baseDir: "./src"
},
notify:false
});}
function sassTask () {
return src('src/sass/**/*.sass')
.pipe(sass().on("error",notify.onError()))
.pipe(sass())
.pipe(autoprefixer(['last 15 version']))
.pipe(cleanCSS({compatibility:'ie8'}))
.pipe(dest('src/css'))
.pipe(browserSync.reload({stream:true}))
}
function imagesTask(){
return src('src/img/**/*')
.pipe(imagemin([imagemin.optipng({optimizationLevel:5})]))
.pipe(dest('dist/img'))
}
function watchTask(){
watch('src/sass/**/*.sass',parallel(sassTask));
watch('src/img/**/*',browserSync.reload);
watch('src/js/**/*.js',parallel(scriptsTask));
watch('src/**/*.html',browserSync.reload);
}
function scriptsTask() {
return src(['src/js/scripts.js'])
.pipe(concat('script.min.js'))
.pipe(uglify())
.pipe(dest('src/js'))
.pipe(browserSync.reload({
stream: true
}))
}
function delTask (){
return del(['dist']);
}
function buildTask() {
return src([
'src/**/*.html',
'src/**/*.min.js',
'src/**/*css'
])
.pipe(dest('dist'))
}
exports.del=delTask;
exports.scripts=scriptsTask;
exports.sass=sassTask;
exports.images=imagesTask;
exports.watch=watchTask;
exports.server=serverTask;
exports.build=series(delTask,sassTask,imagesTask,buildTask);
exports.default=parallel(serverTask,watchTask);