-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (90 loc) · 2.29 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
/*
Dependencies
----------------------------------- */
var autoprefixer = require('autoprefixer'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
csswring = require('csswring'),
del = require('del'),
gulp = require('gulp'),
perfectionist = require('perfectionist'),
plumber = require('gulp-plumber'),
postcss = require('gulp-postcss'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
source = require('vinyl-source-stream');
uglify = require('gulp-uglify');
/*
Shared options
----------------------------------- */
var options = {
sass: {
style: 'compressed',
errLogToConsole: true
},
autoprefixer: {
browsers: ['> 5%', 'IE >= 7', 'iOS >= 5.1'],
remove: true
},
perfectionist: {
cascade: false
}
};
/*
Clean output directory
----------------------------------- */
gulp.task('clean', function(callback) {
return del(['./dist/assets/js/*', './dist/assets/css/*'], callback);
});
/*
Copy other assets (e.g. jQuery)
----------------------------------- */
gulp.task('copy', function(callback) {
gulp.src('./src/js/*.js')
.pipe(gulp.dest('./dist/assets/js'));
});
/*
Sass to CSS
----------------------------------- */
gulp.task('sass', ['clean'], function() {
gulp.src('./src/scss/*.scss')
// Convert to CSS
.pipe(sass(options.sass).on('error', sass.logError))
// Process PostCSS
.pipe(postcss([
autoprefixer(options.autoprefixer),
csswring(options.csswring),
perfectionist(options.perfectionist)
]))
// Rename, write to files
.pipe(gulp.dest('./dist/assets/css'))
});
/*
Resolve dependencies, bundle
----------------------------------- */
gulp.task('bundle', ['clean'], function() {
// Configure browserify
var b = browserify({
debug: true,
entries: './src/js/touch-slider.js',
standalone: 'TouchSlider'
});
return b.bundle()
.pipe(plumber())
// Load files
.pipe(source('./src/js/touch-slider.js'))
.pipe(buffer())
// Uglify and switch to build location
.pipe(uglify())
.pipe(rename({
dirname: './dist/assets/js/',
suffix: '-bundle.min'
}))
// Write to files
.pipe(gulp.dest('.'));
});
/*
Define tasks
----------------------------------- */
// Default
gulp.task('default', ['copy', 'sass', 'bundle']);