This repository has been archived by the owner on Apr 12, 2020. It is now read-only.
/
gulpfile.js
123 lines (113 loc) 路 3.39 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
'use strict';
// include gulp
var gulp = require('gulp');
// include plug-ins
var changed = require('gulp-changed');
var minifyHTML = require('gulp-minify-html');
var concat = require('gulp-concat');
var autoprefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var del = require('del');
var babel = require('gulp-babel');
var merge2 = require('merge2');
var argv = require('minimist')(process.argv.slice(2));
var paths = {
dist: {
root: './dist'
},
html: {
src: './src/partials/*.html',
dest: './dist/partials',
index: './src/index.html'
},
css: {
src: [
'./node_modules/bootswatch/yeti/bootstrap.css',
'./node_modules/font-awesome/css/font-awesome.css',
'./node_modules/angular-ui-bootstrap/dist/ui-bootstrap-csp.css',
'./src/css/*.css'
],
dest: './dist/css'
},
fonts: {
src: [
'./node_modules/font-awesome/fonts/fontawesome-webfont.*',
'./node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.*'
],
dest: './dist/fonts'
},
js: {
src: ['./src/js/*.js'],
thirdPartySrc: [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/angular/angular.js',
'./node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
'./node_modules/angulartics/dist/angulartics.min.js',
'./node_modules/angulartics/dist/angulartics-ga.min.js',
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/angular-route/angular-route.js',
'./node_modules/bootstrap/dist/js/bootstrap.js'
],
dest: './dist/js'
}
};
// minify new or changed HTML pages
gulp.task('minify-html', function() {
var opts = {
empty: true,
quotes: true
};
return gulp
.src(paths.html.src)
.pipe(changed(paths.html.dest))
.pipe(minifyHTML(opts))
.pipe(gulp.dest(paths.html.dest));
});
// CSS concat, auto prefix, minify, then rename output file
gulp.task('minify-css', function() {
return gulp
.src(paths.css.src)
.pipe(concat('styles.css'))
.pipe(autoprefix('last 2 versions'))
.pipe(minifyCSS({ processImport: false }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.css.dest));
});
gulp.task('copy-static', function() {
return gulp.src(paths.html.index).pipe(gulp.dest(paths.dist.root));
});
gulp.task('copy-fonts', function() {
return gulp.src(paths.fonts.src).pipe(gulp.dest(paths.fonts.dest));
});
// JS concat, strip debugging code and minify
gulp.task('bundle-scripts', function() {
return merge2(
gulp.src(paths.js.thirdPartySrc),
gulp.src(paths.js.src).pipe(
babel({
presets: ['es2015']
})
)
)
.pipe(concat('spotlistr.js'))
.pipe(gulpif(!!argv['release'], stripDebug()))
.pipe(gulpif(!!argv['release'], uglify({ mangle: false })))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.js.dest));
});
gulp.task('clean', function(cb) {
del(['./dist'], cb);
});
// default gulp task
gulp.task('default', ['minify-html', 'copy-fonts', 'bundle-scripts', 'minify-css', 'copy-static'], function() {
// watch for HTML changes
gulp.watch(paths.html.src, ['minify-html']);
// watch for JS changes
gulp.watch(paths.js.src, ['bundle-scripts']);
// watch for CSS changes
gulp.watch(paths.css.src, ['minify-css']);
});