-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
112 lines (97 loc) · 2.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
var gulp = require("gulp"),
plumber = require('gulp-plumber'),
jade = require('gulp-jade'),
sass = require('gulp-sass'),
browserSync = require("browser-sync"),
spritesmith = require('gulp.spritesmith'),
autoprefixer = require('gulp-autoprefixer'),
svgSprite = require('gulp-svg-sprite'),
svgmin = require('gulp-svgmin'),
cheerio = require('gulp-cheerio'),
replace = require('gulp-replace');
gulp.task('jade',function () {
gulp.src('app/_jade/*.jade')
.pipe(plumber())
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest('app/'));
});
gulp.task('sass', function () {
gulp.src('app/_sass/*.scss')
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('app/css'));
});
gulp.task('server',function(){
browserSync({
port: 9000,
server: {
baseDir: 'app'
}
})
});
gulp.task('autoprefix', function () {
return gulp.src('app/css/main.css')
.pipe(plumber())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('app/css/'));
});
gulp.task('watch', function(){
gulp.watch([
'app/index.html',
'app/js/**/*.js',
'app/css/*.css'
]).on('change', browserSync.reload);
gulp.watch('app/_sass/**/*',['sass','autoprefix']);
gulp.watch('app/_jade/**/*',['jade']);
gulp.watch('app/pictures/sprite//*',['spritePng']);
gulp.watch('app/pictures/svgIcons/*',['svgSpriteBuild']);
});
gulp.task('spritePng', function () {
var spriteData = gulp.src('app/pictures/sprite/*.png').pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.scss',
padding: 20
}));
var imgStream = spriteData.img
.pipe(buffer())
.pipe(imagemin())
.pipe(gulp.dest('app/pictures/'));
var cssStream = spriteData.css
.pipe(gulp.dest('app/_sass/common/'));
return merge(imgStream, cssStream);
});
gulp.task('svgSpriteBuild', function () {
return gulp.src('app/pictures/svgIcons/*.svg')
// remove all fill, style and stroke declarations in out shapes
.pipe(cheerio({
run: function ($) {
$('[fill]').removeAttr('fill');
$('[stroke]').removeAttr('stroke');
$('[style]').removeAttr('style');
},
parserOptions: {xmlMode: true}
}))
// cheerio plugin create unnecessary string '>', so replace it.
.pipe(replace('>', '>'))
// build svg sprite
.pipe(svgSprite({
mode: {
symbol: {
sprite: "../pictures/sprite.svg",
render: {
scss: {
dest:'../_sass/common/_spriteSvg.scss',
template: "app/_sass/templates/_sprite_template.scss"
}
}
}
}
}))
.pipe(gulp.dest('app'));
});
gulp.task('default',['server','watch']);