-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
65 lines (56 loc) · 1.93 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
'use strict';
const gulp = require('gulp');
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('./gulpfile.config.json'));
const browserify = require('browserify');
const tap = require('gulp-tap');
const babelify = require('babelify');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
// Compile scripts
gulp.task('scripts', function () {
return gulp.src(config.scripts.sourceFiles, {read: false}) // no need of reading file because browserify does.
.pipe(tap(function (file) {
file.contents = browserify(file.path, {debug: true}).transform(babelify).bundle();
}))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(config.scripts.targetFolder));
});
// Compile styles
gulp.task('styles', function () {
return gulp.src(config.styles.sourceFiles)
.pipe(sass())
.pipe(postcss([autoprefixer({browsers: ['> 5%']})]))
.pipe(cleanCSS(config.styles.cleanCss))
.pipe(gulp.dest(config.styles.targetFolder))
});
// Run image optimization
gulp.task('images', function () {
gulp.src(config.images.sourceFiles)
.pipe(imagemin([
imagemin.gifsicle(),
imagemin.jpegtran(),
imagemin.optipng(),
imagemin.svgo(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
// Ensure the ID attributes in SVG files are unique
return {
plugins: [{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
})
]))
.pipe(gulp.dest(config.images.targetFolder))
});
// Build by default
gulp.task('default', ['images', 'scripts', 'styles']);