-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
163 lines (133 loc) · 3.66 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict';
// Requires
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
del = require('del'),
runSequence = require('run-sequence'),
browserSync = require('browser-sync'),
beep = require('beepbeep'),
reload = browserSync.reload;
// Lint JavaScript
// gulp.task('lint', function () {
// return gulp.src([
// 'app/js/**/*.js',
// '!app/js/queue.v1.min.js'
// ])
// .pipe(reload({stream: true, once: true}))
// .pipe($.jshint())
// .pipe($.jshint.reporter('jshint-stylish'));
// });
// Optimize images
gulp.task('images', function() {
gulp.src('app/images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [
{removeViewBox: false},
{cleanupIDs: false}
],
}))
.pipe(gulp.dest('dist/images'));
});
// Compile and automatically prefix stylesheets
gulp.task('styles', function () {
var AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
return gulp.src([
'app/styles/**/*.sass',
'app/styles/**/*.scss',
'app/styles/**/*.css'
])
.pipe($.newer('.tmp/css'))
.pipe($.sourcemaps.init())
.pipe($.plumber(function() {
beep();
}))
.pipe($.sass({
precision: 10
}).on('error', $.sass.logError))
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('.tmp/styles'));
});
// Scan the HTML for assets and optimize them
gulp.task('html', function() {
return gulp.src(['app/*.html', '.tmp/*.html'])
.pipe($.useref({searchPath: ['.tmp', 'app']}))
.pipe($.if('*.css', $.cssnano()))
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.html', $.htmlmin({
collapseWhitespace: true,
removeEmptyAttributes: true,
preserveLineBreaks: false
})))
.pipe(gulp.dest('dist'));
});
// Clean output directory
gulp.task('clean', function() {
return del(['.tmp/*', 'dist/*']);
});
// Copy web fonts to dist
gulp.task('fonts', function () {
return gulp.src(['app/fonts/**'])
.pipe(gulp.dest('dist/fonts'));
});
//Copy data to dist
gulp.task('data', function() {
return gulp.src(['app/data/**'])
.pipe(gulp.dest('dist/data'));
});
//Copy json to dist
gulp.task('json', function() {
return gulp.src(['app/json/**'])
.pipe(gulp.dest('dist/json'));
});
//Copy static to dist
gulp.task('static', function() {
return gulp.src(['app/static/**'])
.pipe(gulp.dest('dist/static'));
});
//Copy bower to dist
gulp.task('bower', function() {
return gulp.src(['app/bower_components/**'])
.pipe(gulp.dest('dist/bower_components'));
});
// Watch files for changes & reload
gulp.task('serve', ['clean'], function() {
runSequence('styles');
browserSync({
notify: false,
logPrefix: 'WSK',
server: ['.tmp', 'app']
});
gulp.watch(['app/**/*.html'], reload);
gulp.watch(['app/sass/**/*.{sass,scss,css}'], ['styles', reload]);
gulp.watch(['app/js/**/*.js'], reload);
gulp.watch(['app/images/**/*'], reload);
});
// Build and serve the output from the dist build
gulp.task('serve:dist', ['default'], function () {
browserSync({
notify: false,
logPrefix: 'WSK',
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: 'dist'
});
});
// Default task - Build production files
gulp.task('default', function (cb) {
runSequence('clean', 'styles', ['images', 'fonts', 'data', 'json', 'static', 'bower', 'html'], cb);
});