-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
167 lines (147 loc) · 3.86 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var gulp = require("gulp"),
plumber = require('gulp-plumber'),
pug = require('gulp-pug'),
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'),
concat = require('gulp-concat'),
webpackStream = require('webpack-stream'),
webpack = require('webpack');
var path = ["node_modules/jquery/dist/jquery.min.js"];
gulp.task('pug', function () {
gulp.src('app/_jade/*.pug')
.pipe(plumber())
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('dist/'));
});
gulp.task('sass', function () {
gulp.src('app/_sass/*.scss')
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('dist/css'));
});
gulp.task('server',function(){
browserSync({
port: 9000,
server: {
baseDir: 'dist'
}
})
});
gulp.task('autoprefix', function () {
return gulp.src('app/css/main.css')
.pipe(plumber())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('dist/css/'));
});
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: "../../dist/pictures/sprite.svg",
render: {
scss: {
dest:'../_sass/common/_spriteSvg.scss',
template: "app/_sass/templates/_sprite_template.scss"
}
}
}
}
}))
.pipe(gulp.dest('app'));
});
gulp.task('jsLibs', function() {
return gulp.src(path)
.pipe(concat('foundation.js'))
.pipe(gulp.dest('dist/js/'))
});
gulp.task('jsBuild', () => {
return gulp.src('app/js/main.js')
.pipe(webpackStream({
watch: true,
output: {
filename: 'main.js',
library: 'app'
},
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}
]
}/*,
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
unsafe: true
}
})
]*/
},webpack))
.on('error', function handleError() {
this.emit('end'); // Recover from errors
})
.pipe(gulp.dest('dist/js/'));
});
gulp.task('imgCopy', () => {
gulp.src('app/img/*')
.pipe(gulp.dest('dist/img/'));
gulp.src('app/pictures/*')
.pipe(gulp.dest('dist/pictures/'));
});
gulp.task('watch', function(){
gulp.watch([
'dist/*.html',
'dist/js/*.js',
'dist/css/*.css'
]).on('change', browserSync.reload);
gulp.watch('app/_sass/**/*',['sass','autoprefix']);
gulp.watch('app/_jade/**/*',['pug']);
gulp.watch('dist/pictures/sprite//*',['spritePng']);
gulp.watch('app/pictures/svgIcons/*',['svgSpriteBuild']);
});
gulp.task('default',['server','watch','jsLibs','imgCopy', 'jsBuild']);