-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
121 lines (101 loc) · 2.77 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
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('app/styles/**.scss')
.pipe($.rubySass({
style: 'expanded',
precision: 10,
sourcemap: true
}))
.pipe(gulp.dest('.tmp/styles'))
.pipe($.size());
});
gulp.task('html', ['styles'], function () {
return gulp.src('app/*.html')
.pipe($.useref.assets({searchPath: '{.tmp,app}'}))
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
gulp.task('extras', function () {
return gulp.src(['app/*.*', '!app/*.html'], { dot: true })
.pipe(gulp.dest('dist'));
});
gulp.task('uncss', function () {
return gulp.src('dist/styles/main.css')
.pipe($.uncss({
html: ['dist/index.html']
}))
.pipe(gulp.dest('dist/styles'));
});
gulp.task('premailer', function() {
return gulp.src('dist/*.html')
.pipe($.premailer())
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function () {
var del = require('del');
del(['.tmp', 'dist'], function (msg) {
console.log('Deleted files.');
});
});
gulp.task('build', ['clean', 'html', 'images', 'extras'], function () {
gulp.start('uncss');
});
gulp.task('default', ['build'], function () {
gulp.start('premailer');
});
gulp.task('connect', function () {
var connect = require('connect');
var app = connect()
.use(require('connect-livereload')({ port: 35729 }))
.use(connect.static('app'))
.use(connect.static('.tmp'))
.use(connect.directory('app'));
require('http').createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
});
gulp.task('serve', ['connect', 'styles'], function () {
require('opn')('http://localhost:9000');
});
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/styles/*.scss')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app/styles'));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app'));
});
gulp.task('watch', ['connect', 'serve'], function () {
var server = $.livereload();
gulp.watch([
'app/*.html',
'.tmp/styles/**/*.css',
'app/images/**/*'
]).on('change', function (file) {
server.changed(file.path);
});
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('bower.json', ['wiredep']);
});