-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
151 lines (137 loc) · 3.69 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
var gulp = require('gulp'),
watch = require('gulp-watch'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
wait = require("gulp-wait"),
cssnano = require('cssnano'),
notify = require("gulp-notify"),
rigger = require('gulp-rigger'),
imagemin = require('gulp-imagemin'),
rimraf = require('rimraf'),
plumber = require('gulp-plumber'),
browserSync = require("browser-sync"),
reload = browserSync.reload;
var path = {
build: {
html: 'build/',
js: 'build/js/',
css: 'build/css/',
img: 'build/img/',
fonts: 'build/fonts/',
libs: 'build/libs/'
},
src: {
html: 'src/*.html',
js: 'src/js/main.js',
style: 'src/style/main.scss',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*',
libs: 'src/libs/**/*.*'
},
watch: {
html: 'src/**/*.html',
js: 'src/js/**/*.js',
style: 'src/style/**/*.scss',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*',
libs: 'src/libs/**/*.*'
},
clean: './build'
};
var config = {
server: {
baseDir: "./build"
},
host: 'localhost',
port: 9000,
open: false,
logPrefix: "KingZ"
};
gulp.task('webserver', function () {
browserSync(config);
});
gulp.task('clean', function (cb) {
rimraf(path.clean, cb);
});
gulp.task('html:build', function () {
gulp.src(path.src.html)
.pipe(rigger())
.pipe(gulp.dest(path.build.html))
.pipe(browserSync.stream());
});
gulp.task('js:build', function () {
gulp.src(path.src.js)
.pipe(plumber())
.pipe(rigger())
.pipe(uglify())
.pipe(gulp.dest(path.build.js))
.pipe(reload({stream: true}));
});
gulp.task('style:build', function () {
var processors = [
autoprefixer({browsers: ['last 40 version']}),
cssnano
];
gulp.src(path.src.style)
.pipe(wait(500))
.pipe(sass().on("error", notify.onError()))
.pipe(postcss(processors))
.pipe(gulp.dest(path.build.css))
.pipe(reload({stream: true}));
});
gulp.task('image:build', function () {
gulp.src(path.src.img)
.pipe(imagemin([
// imagemin.gifsicle({interlaced: true}),
// imagemin.jpegtran({progressive: true}),
// imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(gulp.dest(path.build.img))
.pipe(reload({stream: true}));
});
gulp.task('fonts:build', function() {
gulp.src(path.src.fonts)
.pipe(gulp.dest(path.build.fonts))
});
gulp.task('libs:build', function() {
gulp.src(path.src.libs)
.pipe(gulp.dest(path.build.libs))
});
gulp.task('build', [
'html:build',
'js:build',
'style:build',
'fonts:build',
'libs:build',
'image:build'
]);
gulp.task('watch', function(){
watch([path.watch.html], function(event, cb) {
gulp.start('html:build');
});
watch([path.watch.style], function(event, cb) {
gulp.start('style:build');
});
watch([path.watch.js], function(event, cb) {
gulp.start('js:build');
});
watch([path.watch.img], function(event, cb) {
gulp.start('image:build');
});
watch([path.watch.fonts], function(event, cb) {
gulp.start('fonts:build');
});
watch([path.watch.libs], function(event, cb) {
gulp.start('libs:build');
});
});
gulp.task('default', ['build', 'webserver', 'watch']);