-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
90 lines (82 loc) · 2.34 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
// Gulp
const gulp = require('gulp');
// Debug plugins
const plumber = require("gulp-plumber");
// Other plugins
const concat = require('gulp-concat');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const iconfont = require('gulp-iconfont');
const consolidate = require('gulp-consolidate');
const babel = require('gulp-babel');
// Paths
const source = 'assets/';
const dest = 'public/';
// Prod
gulp.task('default', ['icons', 'css', 'js']);
// Watch (dev)
gulp.task('watch', function () {
gulp.watch(source + 'css/**/*.scss', ['css']);
gulp.watch(source + 'js/main.js', ['js']);
gulp.watch(source + 'icons/!*', ['icons']);
});
// CSS
gulp.task('css', function() {
return gulp.src([
source + 'css/main.scss'
])
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions', '> 1%', 'Explorer 7', 'Android >= 2', 'Safari > 3'],
}))
.pipe(cssnano())
.pipe(concat('app.css'))
.pipe(gulp.dest(dest));
});
// JS
gulp.task('js', function() {
return gulp.src([
source + 'js/main.js'
])
.pipe(plumber())
.pipe(concat('app.js'))
.pipe(babel({
presets: ['env']
}))
.pipe(uglify({
mangle: false
}))
.pipe(gulp.dest(dest));
});
// Icons
var runTimestamp = Math.round(Date.now()/1000);
gulp.task('icons', function(){
return gulp.src(source +'/icons/*.svg')
.pipe(plumber())
.pipe(iconfont({
fontName: 'icons',
prependUnicode: true,
formats: ['ttf', 'eot', 'woff', 'svg', 'woff2'],
timestamp: runTimestamp,
normalize: true
}))
.on('glyphs', function(glyphs, options) {
gulp.src(source +'/icons/icons.template')
.pipe(consolidate('lodash', {
glyphs: glyphs,
fontName: 'icons',
fontPath: 'fonts/',
className: 'icon'
}))
.pipe(rename({
prefix: '_',
extname: '.scss'
}))
.pipe(gulp.dest(source + 'css/base/'));
})
.pipe(gulp.dest(dest +'fonts/'));
});