-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
executable file
·143 lines (129 loc) · 3.91 KB
/
Gulpfile.js
File metadata and controls
executable file
·143 lines (129 loc) · 3.91 KB
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
var gulp = require('gulp'),
minifyCSS = require('gulp-minify-css'),
sass = require('gulp-sass'),
postcss = require('gulp-postcss'),
browserify = require('gulp-browserify'),
browserSync = require('browser-sync'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
notify = require('gulp-notify'),
replace = require('gulp-replace'),
inject = require('gulp-inject'),
svgstore = require('gulp-svgstore'),
svgmin = require('gulp-svgmin'),
plumber = require('gulp-plumber'),
eslint = require('gulp-eslint'),
jsonlint = require('gulp-jsonlint'),
beep = require('beepbeep'),
colors = require('colors'),
path = require('path'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('autoprefixer'),
merge = require('merge-stream');;
// error handling convenience wrapper
gulp.plumbedSrc = function(){
return gulp.src.apply(gulp, arguments)
.pipe(plumber({
errorHandler: function(err) {
beep();
console.log('ERROR:'.bold.red);
console.log(JSON.stringify(err, null, 2).bold.red);
this.emit('end');
}
}));
};
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: './'
},
host: 'localhost',
port: 8000,
open: false
});
});
gulp.task('sass', function () {
return gulp.plumbedSrc('./sass/**/*.scss')
.pipe(sass())
.pipe(minifyCSS())
.pipe(sourcemaps.init())
.pipe(postcss([autoprefixer({
browsers: ['last 2 versions']
}
)]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build/css/'))
.pipe(notify({ message: 'CSS complete' }));
});
gulp.task('svgstore', function () {
var svgSprite = gulp.plumbedSrc('./svg/*.svg')
.pipe(svgmin(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
return {
plugins: [{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
}))
.pipe(rename({prefix: 'svg-'}))
.pipe(svgstore({inlineSvg: true}))
.pipe(rename("social-icons.svg"))
.pipe(gulp.dest('./build/img'));
return gulp.plumbedSrc('./index.html')
.pipe(inject(svgSprite, {
transform: function(filePath, file) {
return file.contents.toString();
}
}))
.pipe(gulp.dest('./'));
});
gulp.task('scripts', function() {
var mainJS = gulp.plumbedSrc('./js/main.js')
.pipe(browserify())
.pipe(gulp.dest('./build/js/'))
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(replace('./build/js/*.min.js'))
.pipe(gulp.dest('./build/js'))
.pipe(notify({ message: 'JS files complete' }));
var quoteJS = gulp.plumbedSrc('./js/quote.js')
.pipe(browserify())
.pipe(gulp.dest('./build/js/'))
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(replace('./build/js/*.min.js'))
.pipe(gulp.dest('./build/js'))
.pipe(notify({ message: 'JS files complete' }));
return merge(mainJS, quoteJS);
});
gulp.task('scripts-watch', ['scripts'], function() {
browserSync.reload();
});
gulp.task('sass-watch', ['sass'], function() {
browserSync.reload();
});
gulp.task('eslint', function() {
return gulp.plumbedSrc('./js/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(notify({ message: 'ESLint complete' }));
});
gulp.task('jsonlint', function() {
return gulp.plumbedSrc('./json/**/*.json')
.pipe(jsonlint())
.pipe(jsonlint.failAfterError())
.pipe(notify({ message: 'JSONLint complete' }));
});
gulp.task('watch', ['browser-sync'], function() {
gulp.watch('./sass/**/*.scss', ['sass-watch']);
gulp.watch('./js/*.js', ['eslint', 'scripts-watch']);
});
gulp.task('default', ['watch']);