-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
99 lines (85 loc) · 2.44 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
'use strict';
require('dotenv').config();
const debug = require('debug')('app-build');
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
// preload all plugins
const plugins = gulpLoadPlugins();
// if production
const isProduction = process.env.NODE_ENV !== 'development';
// will clean dest directory on event => reload
gulp.task('clean', () => {
return gulp
.src('./dest/**/*', { read: false })
.pipe(plugins.clean())
});
// up the version
gulp.task('bump', function(){
return gulp
.src('./package.json')
.pipe(plugins.bump())
.pipe(gulp.dest('./'));
});
// will copy all html views
gulp.task('views', () => {
delete require.cache[require.resolve('./package.json')]
return gulp
.src('./src/*.html')
.pipe(plugins.versionAppend(['html', 'js', 'css']))
.pipe(isProduction ? plugins.htmlmin({collapseWhitespace: true}) : plugins.noop())
.pipe(gulp.dest('./dest/'))
});
// will compile js-file and push to dir.es5
gulp.task('scripts', () => {
return gulp
.src('./src/scripts/**/*.js')
.pipe(plugins.babel({
presets: ['env']
}))
.pipe(plugins.concat('app.js'))
.pipe(plugins.uglyfly({
output: { beautify: isProduction ? false : true }
}))
.pipe(gulp.dest('./dest/scripts'));
});
// will compile sass to css with autoprefixer call sass:lint;
gulp.task('styles', () => {
return gulp
.src('./src/styles/**/*.s+(a|c)ss')
.pipe(plugins.sass({
outputStyle: isProduction ? 'compressed' : 'expanded'
}).on('error', plugins.sass.logError))
.pipe(plugins.autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(plugins.concat('app.css'))
.pipe(gulp.dest('./dest/styles/'))
});
// will copy images without opt. and sprites
gulp.task('images', () => {
return gulp
.src('./src/images/*.png')
.pipe(gulp.dest('./dest/images/'))
});
// server
gulp.task('server', () => {
return gulp
.src('./dest')
.pipe(plugins.webserver({
port: process.env.HTTP_PORT || 8080,
livereload: isProduction ? false : true,
directoryListing: false,
open: false
}));
});
// watch & reload server
gulp.task('watch', () => {
return gulp.watch('src/**/*', ['build']);
});
// build app
gulp.task('build', done => {
return plugins.sequence('clean', 'bump', ['views', 'styles', 'scripts', 'images'])(done)
});
// default task
gulp.task('default', plugins.sequence(['build'], ['server', 'watch']));