This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
89 lines (72 loc) · 2.18 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
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var autoprefix = require('gulp-autoprefixer');
var notify = require('gulp-notify');
var Path = require('path');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
// Super thanks: http://truongtx.me/2014/08/06/using-watchify-with-gulp-for-fast-browserify-build/
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var config = {
sassPath: './src/ui/sass',
uiEntryPoint: './src/ui/main.js',
bowerPath: './bower_components',
deployPath: './public'
};
// Main Tasks
gulp.task('default', ['icons', 'css', 'js']);
gulp.task('js', browserifyShare.bind(null, false));
gulp.task('css', css);
gulp.task('watch', ['icons', 'watch-js', 'watch-sass']);
gulp.task('watch-js', browserifyShare.bind(null, true));
gulp.task('watch-sass', ['css'], watchSass);
gulp.task('icons', function() {
return gulp.src([
config.bowerPath + '/bootstrap-sass-official/assets/fonts/bootstrap/**.*',
config.bowerPath + '/fontawesome/fonts/**.*'
])
.pipe(gulp.dest(Path.join(config.deployPath, 'css/fonts')));
});
function watchSass() {
gulp.watch(config.sassPath + '/**/*.sass', ['css']);
}
function css() {
return sass(Path.join(config.sassPath, 'main.sass'), {
style: 'compressed',
loadPath: [
config.sassPath,
Path.join(config.bowerPath, 'bootstrap-sass-official/assets/stylesheets'),
Path.join(config.bowerPath, 'fontawesome/scss')
],
'sourcemap=none': true
})
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
}))
.pipe(autoprefix('last 2 version'))
.pipe(gulp.dest(Path.join(config.deployPath, 'css')));
}
function browserifyShare(watch) {
var b = browserify({
cache: {},
packageCache: {},
fullPaths: true
});
if (watch) {
b = watchify(b);
b.on('update', function() {
bundleShare(b);
});
}
b.add(config.uiEntryPoint);
bundleShare(b);
function bundleShare(b) {
b = b.bundle().pipe(source('bundle.js'));
if (!watch) {
b.pipe(streamify(uglify()));
}
b.pipe(gulp.dest(Path.join(config.deployPath, 'js')));
}
}