-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
75 lines (66 loc) · 2.12 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
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
meta = require('./package.json');
var argv = require('minimist')(process.argv.slice(2));
var jsDir = 'src/js/',
sassDir = 'src/sass/',
fontsDir = 'src/fonts/',
distDir = 'build',
banner = [
'/*!',
' * =============================================================',
' * <%= name %> v<%= version %> - <%= description %>',
' * <%= homepage %>',
' *',
' * (c) 2017 - <%= author %>',
' * =============================================================',
' */\n\n'
].join('\n'),
umdDeps = {
dependencies: function() {
return [
{
name: '$',
amd: 'jquery',
cjs: 'jquery',
global: 'jQuery',
param: '$'
}
];
}
};
var onError = function (err) {
$.util.beep();
console.log(err.toString());
this.emit('end');
};
gulp.task('fonts', function() {
return gulp.src(fontsDir + '**/*')
.pipe(gulp.dest(distDir + "/fonts"));
});
gulp.task('sass', function() {
return gulp.src(sassDir + '*.scss')
.pipe($.plumber({ errorHandler: onError }))
.pipe($.sass())
.pipe($.autoprefixer())
.pipe($.header(banner, meta))
.pipe($.if(!argv.dev, $.minifyCss()))
.pipe($.if(!argv.dev, $.rename(meta.name + '.min.css')))
.pipe($.if(!argv.dev, gulp.dest(distDir + "/css")));
});
gulp.task('scripts', function() {
return gulp.src([jsDir + '*.js'])
.pipe($.plumber({ errorHandler: onError }))
.pipe($.umd(umdDeps))
.pipe($.header(banner, meta))
.pipe($.rename(meta.name + '.js'))
.pipe($.if(!argv.dev, $.uglify()))
.pipe($.if(!argv.dev, $.header(banner, meta)))
.pipe($.if(!argv.dev, $.rename(meta.name + '.min.js')))
.pipe($.if(!argv.dev, gulp.dest(distDir + "/js")));
});
gulp.task('default', ['sass', 'scripts', 'fonts'], function() {
gulp.watch(jsDir + '**/*.js', ['scripts']);
gulp.watch(sassDir + '**/*.scss', ['sass']);
});
gulp.task('build', ['sass', 'scripts', 'fonts']);