-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
176 lines (146 loc) · 5.09 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Global
// $npm install -g gulp
// $npm install gulp-load-plugins
// Install local per project
// $npm install --save-dev (installs all packages in package.json)
// Run process
// $gulp
// Include Gulp
var gulp = require('gulp');
// Include gulp- plugins from package.json
var plugins = require('gulp-load-plugins')();
var del = require('del'),
q = require('q'),
path = require('path'),
fs = require('fs'),
svgmin = require('gulp-svgmin');
// Compile & Minify Theme CSS from LESS files
// =============================================================================
gulp.task('css', function () {
var onError = function (err) {
plugins.notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src('assets/less/style.less')
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(plugins.less({compress: true}))
.pipe(plugins.autoprefixer('last 2 version', 'ie 8', 'ie 9'))
.pipe(plugins.minifyCss({
keepSpecialComments: 0,
keepBreaks: false,
compatibility: '*,' + '-units.pc,' + '-units.pt,' + '-units.in' // until this 'optimisation' is removed
}))
.pipe(plugins.rename({
suffix: '.min'
}))
.pipe(gulp.dest('assets/dist/css'))
.pipe(plugins.notify({
message: 'CSS task complete', onLast: true
}));
});
// Concatenate & Minify Theme JS
// =============================================================================
gulp.task('js', function () {
return gulp.src('assets/js/*.js')
.pipe(plugins.concat('project.js'))
.pipe(plugins.rename({
suffix: '.min'
}))
.pipe(plugins.uglify())
.pipe(gulp.dest('assets/dist/js'))
.pipe(plugins.notify({
message: 'JS task complete'
}));
});
// Concatenate & Minify Bootstrap JS
// bootstrap-popover.js has to be after bootstrap-tooltip.js
// Only use what's needed
// =============================================================================
gulp.task('bootstrapJS', function () {
return gulp.src([
'bower_components/bootstrap-less/js/transition.js',
'bower_components/bootstrap-less/js/alert.js',
'bower_components/bootstrap-less/js/button.js',
'bower_components/bootstrap-less/js/carousel.js',
'bower_components/bootstrap-less/js/collapse.js',
'bower_components/bootstrap-less/js/dropdown.js',
'bower_components/bootstrap-less/js/modal.js',
'bower_components/bootstrap-less/js/tooltip.js',
'bower_components/bootstrap-less/js/popover.js',
'bower_components/bootstrap-less/js/scrollspy.js',
'bower_components/bootstrap-less/js/tab.js',
'bower_components/bootstrap-less/js/affix.js'
])
.pipe(plugins.concat('bootstrap.js'))
.pipe(plugins.rename({
suffix: '.min'
}))
.pipe(plugins.uglify())
.pipe(gulp.dest('assets/dist/js'))
.pipe(plugins.notify({
message: 'Bootstrap JS task complete'
}));
});
// Copy JS libraries to dist folder
// =============================================================================
gulp.task('jsLibs', function () {
return gulp.src('./assets/js/libs/**/*.js')
.pipe(gulp.dest('./assets/dist/js/libs'))
.pipe(plugins.notify({
message: 'JS libraries copied to dist', onLast: true
}));
});
// SVG
// =============================================================================
gulp.task('svg', function() {
return gulp.src('assets/svg/*.svg')
.pipe(plugins.svgmin())
.pipe(gulp.dest('assets/dist/svg'))
.pipe(plugins.notify({
message: 'svg task complete', onLast: true
}));
});
gulp.task('svg2png', ['svg'], function() {
return gulp.src('assets/svg/*.svg')
.pipe(plugins.svg2png())
.pipe(gulp.dest('assets/dist/img'))
.pipe(plugins.notify({
message: 'svg2png task complete', onLast: true
}));
});
// Optimise images (once)
// =============================================================================
gulp.task('images', function() {
return gulp.src('assets/img/**/*.*')
.pipe(plugins.cache(plugins.imagemin({
optimizationLevel: 5,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('assets/dist/img'))
.pipe(plugins.notify({
message: 'Images task complete'
}));
});
// Watch for changes in files
// =============================================================================
gulp.task('watch', function () {
gulp.watch('assets/less/**/*.less', ['css']);
gulp.watch('assets/js/*.js', ['js']);
gulp.watch('assets/svg/*.svg', ['svg2png']);
});
// Clean
// =============================================================================
gulp.task('clean', function(cb) {
del(['assets/dist/'], cb);
});
// Default Task
// =============================================================================
gulp.task('default', ['clean'], function() {
gulp.start('css', 'js', 'jsLibs', 'images', 'svg2png');
});