-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (80 loc) · 2.83 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
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
var indexFile = "src/index.html";
var cssOutFile = "css/all.min.css";
var jsOutFile = "js/all.min.js";
var vendorJs = [
'node_modules/angular/angular.min.js',
'node_modules/angular-route/angular-route.min.js',
'node_modules/angular-animate/angular-animate.min.js'
];
var vendorCss = [
'node_modules/bootstrap/dist/css/bootstrap.min.css'
];
var vendorFonts = [
'node_modules/bootstrap/dist/fonts/*'
];
// Error handler
function handleError(error) {
console.log(error.toString());
this.emit('end');
}
// Process and minify HTML files and copy to build/
gulp.task('html', function() {
var indexFilter = plugins.filter('index.html', { restore: true });
return gulp.src('src/**/*.html')
.pipe(indexFilter)
.pipe(plugins.injectString.replace('<!--INJECTCSS-->', '<link rel="stylesheet" href="' + cssOutFile + '">'))
.pipe(plugins.injectString.replace('<!--INJECTJS-->', '<script src="' + jsOutFile + '"></script>'))
.pipe(indexFilter.restore)
.pipe(plugins.htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('build'));
});
// Concatenate, uglify, and copy JS to build/
gulp.task('scripts', function() {
return gulp.src('src/**/*.js')
.pipe(plugins.ngAnnotate()).on('error', handleError)
.pipe(plugins.angularFilesort())
.pipe(plugins.addSrc.prepend(vendorJs)) // Add vendor scripts to beginning of stream
.pipe(plugins.concat(jsOutFile))
.pipe(plugins.uglify({ preserveComments: 'license' })).on('error', handleError)
.pipe(gulp.dest('build'));
});
// Concatenate, compile SASS, and copy CSS to build/
gulp.task('styles', function() {
var src = vendorCss.concat(['src/**/*.+(css|scss)']);
var sassFilter = plugins.filter('**/*.scss', { restore: true });
return gulp.src(src)
.pipe(sassFilter)
.pipe(plugins.sass())
.pipe(sassFilter.restore)
.pipe(plugins.concat(cssOutFile))
.pipe(plugins.cssnano())
.pipe(gulp.dest('build'));
});
// Copy images relatively from src/ to build/
gulp.task('images', function() {
return gulp.src('src/**/*.+(ico|jpg)')
.pipe(gulp.dest('build'));
});
// Copy fonts to build/
gulp.task('fonts', function() {
return gulp.src(vendorFonts)
.pipe(gulp.dest('build/fonts'));
});
// Clean the build/ directory
gulp.task('clean', function() {
return del([
'build/*'
]);
});
// Watch files for changes and update build
gulp.task('watch', function() {
gulp.watch('src/**/*.html', ['html']);
gulp.watch('src/**/*.js', ['scripts']);
gulp.watch('src/**/*.+(css|scss)', ['styles']);
gulp.watch('src/**/*.+(ico|jpg)', ['images']);
});
gulp.task('default', ['html','scripts', 'styles', 'images', 'fonts']);