-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
99 lines (87 loc) · 2.52 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
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
// set env via $ gulp --type production
const environment = $.util.env.type || 'development';
const isProduction = environment === 'production';
const webpackConfig = require('./webpack.config.js').getConfigByType(environment);
const webpack = require('webpack-stream');
const browserSync = require('browser-sync');
const reload = browserSync.reload;
const app = 'app/';
const dist = 'dist/';
const autoprefixerBrowsers = [
'ie >= 9',
'ie_mob >= 10',
'ff >= 25',
'chrome >= 34',
'safari >= 6',
'opera >= 23',
'ios >= 6',
'android >= 4.4',
'bb >= 10'
];
const scriptsTask = function() {
return gulp.src(webpackConfig.entry)
.pipe(webpack(webpackConfig))
.pipe($.size({ title : 'js' }))
.pipe(gulp.dest(dist + 'js/'))
.pipe(reload({ stream:true }));
};
const htmlTask = function() {
return gulp.src(app + 'index.html')
.pipe(gulp.dest(dist))
.pipe($.size({ title : 'html' }))
.pipe(reload({ stream:true }));
};
const stylusTask = function() {
// convert stylus to css
return gulp.src(app + 'stylus/main.styl')
.pipe($.stylus({
// only compress if we are in production
compress: isProduction,
// include 'normal' css into main.css
'include css' : true
}))
.pipe($.autoprefixer({browsers: autoprefixerBrowsers}))
.pipe(gulp.dest(dist + 'css/'))
.pipe($.size({ title : 'css' }))
.pipe(reload({ stream:true }));
};
const serveTask = function() {
browserSync({
server: {
baseDir: dist
}
});
};
const imagesTask = function(){
return gulp.src(app + 'images/**/*.{png,jpg,jpeg,gif,svg}')
.pipe($.size({ title : 'images' }))
.pipe(gulp.dest(dist + 'images/'));
};
const watchTask = function(){
gulp.watch(app + 'stylus/*.styl', ['styles']);
gulp.watch(app + 'index.html', ['html']);
gulp.watch(app + 'scripts/**/*.js', ['scripts']);
};
gulp.task('scripts', scriptsTask);
gulp.task('html', htmlTask);
gulp.task('styles', stylusTask);
gulp.task('serve', serveTask);
gulp.task('images', imagesTask);
gulp.task('watch', watchTask);
// remove bundels
gulp.task('clean', function(cb) {
return del([dist], cb);
});
// by default build project and then watch files in order to trigger livereload
gulp.task('default', ['build', 'serve', 'watch']);
// waits until clean is finished then builds the project
gulp.task('build', ['clean'], function(){
imagesTask();
htmlTask();
scriptsTask();
stylusTask();
return true;
});