This repository has been archived by the owner on Feb 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
/
gulpfile.js
139 lines (117 loc) · 3.64 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
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var sync = $.sync(gulp).sync;
var del = require('del');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var sass = require('gulp-sass');
var bundler = {
w: null,
init: function() {
this.w = watchify(browserify({
entries: ['./app/scripts/app.js'],
insertGlobals: true,
cache: {},
packageCache: {}
}));
},
bundle: function() {
return this.w && this.w.bundle()
.on('error', $.util.log.bind($.util, 'Browserify Error'))
.pipe(source('app.js'))
.pipe(gulp.dest('dist/scripts'));
},
watch: function() {
this.w && this.w.on('update', this.bundle.bind(this));
},
stop: function() {
this.w && this.w.close();
}
};
gulp.task('styles', function() {
return gulp.src('app/styles/main.scss')
.pipe(sass({})
.on('error', sass.logError))
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('dist/styles'))
.pipe($.size());
});
gulp.task('scripts', function() {
bundler.init();
return bundler.bundle();
});
gulp.task('html', function() {
var assets = $.useref.assets();
return gulp.src('app/*.html')
.pipe(assets)
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('images', function() {
return gulp.src('app/images/**/*')
.pipe(($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images/'))
.pipe($.size());
});
gulp.task('fonts', function() {
return gulp.src(['app/fonts/**/*', 'app/bower_components/bootstrap-sass-official/assets/fonts/**/*'])
.pipe(gulp.dest('dist/fonts'))
.pipe($.size());
});
gulp.task('extras', function() {
return gulp.src(['app/*.txt', 'app/*.ico'])
.pipe(gulp.dest('dist/'))
.pipe($.size());
});
gulp.task('serve', function() {
gulp.src('dist')
.pipe($.webserver({
livereload: true,
port: 9000,
open: true
}));
});
gulp.task('set-production', function() {
process.env.NODE_ENV = 'production';
});
gulp.task('minify:js', function() {
return gulp.src('dist/scripts/**/*.js')
.pipe($.uglify())
.pipe(gulp.dest('dist/scripts/'))
.pipe($.size());
});
gulp.task('minify:css', function() {
return gulp.src('dist/styles/**/*.css')
.pipe($.minifyCss())
.pipe(gulp.dest('dist/styles'))
.pipe($.size());
});
gulp.task('copy-docs', function() {
return gulp.src('dist/**/*')
.pipe(gulp.dest('docs/'))
.pipe($.size());
});
gulp.task('minify', ['minify:js', 'minify:css']);
gulp.task('clean', del.bind(null, ['dist', 'docs']));
gulp.task('bundle', ['html', 'styles', 'scripts', 'images', 'fonts', 'extras']);
gulp.task('clean-bundle', sync(['clean', 'bundle']));
gulp.task('build', ['clean-bundle'], bundler.stop.bind(bundler));
gulp.task('build:production', sync(['set-production', 'build', 'minify', 'copy-docs']));
gulp.task('serve:production', sync(['build:production', 'serve']));
gulp.task('default', ['build']);
gulp.task('watch', sync(['clean-bundle', 'serve']), function() {
bundler.watch();
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/*.html', ['html']);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('app/fonts/**/*', ['fonts']);
});