-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (98 loc) · 2.36 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
'use strict';
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jshintStylish = require('jshint-stylish');
var jshintConfig = require('./package').jshintConfig;
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var prefix = require('gulp-autoprefixer');
var htmlhint = require('gulp-htmlhint');
var cleanCSS = require('gulp-clean-css');
var htmlMin = require('gulp-htmlmin');
var htmlreplace = require('gulp-html-replace');
var bytediff = require('gulp-bytediff');
var del = require('del');
// Prevent looking up default files
jshintConfig.lookup = false;
// Build
gulp.task('default', [
'styles',
'scripts',
'html',
'index'
]);
// JavaScript Jshint
gulp.task('lint', function() {
return gulp.src([
'public/app/**/*.js',
'server/**/*.js',
'spec/**/*.js',
'*.js'
])
.pipe(jshint(jshintConfig))
.pipe(jshint.reporter('jshint-stylish'))
});
// Minify JavaScript
gulp.task('scripts', ['lint'], function() {
return gulp.src([
'public/app/app.module.js',
'public/app/**/*module.js',
'public/app/**/*.js'
])
.pipe(concat('app.min.js'))
.pipe(bytediff.start())
.pipe(uglify())
.pipe(bytediff.stop())
.pipe(gulp.dest('dist'));
});
// Minify CSS
gulp.task('styles', function() {
return gulp.src([
'pubic/app/assets/css/index.css',
'public/app/assets/**/*.css'
])
.pipe(prefix('last 2 versions'))
.pipe(concat('app.min.css'))
.pipe(bytediff.start())
.pipe(cleanCSS({
level: 2
}))
.pipe(bytediff.stop())
.pipe(gulp.dest('dist'));
});
// htmlhint
gulp.task('htmlhint', function() {
return gulp.src('public/app/**/*.html')
.pipe(htmlhint('.htmlhintrc'))
.pipe(htmlhint.reporter());
});
// Minify HTML
gulp.task('html', ['htmlhint'], function() {
return gulp.src('public/app/views/**/*.html')
.pipe(bytediff.start())
.pipe(htmlMin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(bytediff.stop())
.pipe(gulp.dest('dist/views'));
});
// Minify and rewrite index.html
gulp.task('index', function() {
return gulp.src('public/app/index.html')
.pipe(bytediff.start())
.pipe(htmlreplace({
'js': 'app.min.js',
'css': 'app.min.css'
}))
.pipe(htmlMin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(bytediff.stop())
.pipe(gulp.dest('dist'));
});
// Clean build
gulp.task('clean', function() {
return del('dist/**');
});