-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·119 lines (106 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
109
110
111
112
113
114
115
116
117
118
119
'use strict'
const babel = require('gulp-babel')
const browserSync = require('browser-sync').create()
const concat = require('gulp-concat')
const del = require('del')
const gulp = require('gulp')
const htmlmin = require('gulp-htmlmin')
const postcss = require('gulp-postcss')
const pump = require('pump')
const rename = require('gulp-rename')
const standard = require('gulp-standard')
const uglify = require('gulp-uglify')
gulp.task('build', ['minify-html', 'build-css', 'build-js', 'copy-assets', 'copy-cname'])
gulp.task('build-css', ['clean-css'], cb => {
pump([
gulp.src([
'src/css/styles.css'
]),
postcss([
require('postcss-import'),
require('autoprefixer')({
browsers: ['last 2 versions']
}),
require('cssnano')({
discardComments: {
removeAll: true
},
safe: true
})
]),
rename('main.css'),
gulp.dest('dist/css'),
browserSync.stream()
], cb)
})
gulp.task('build-js', ['clean-js', 'lint-js'], cb => {
pump([
gulp.src([
'src/js/app.js'
]),
concat('main.js', {
newLine: ';'
}),
babel({
presets: ['es2015']
}),
uglify(),
gulp.dest('dist/js'),
browserSync.stream()
], cb)
})
gulp.task('clean-assets', () => del('dist/assets/**/*.*'))
gulp.task('clean-css', () => del('dist/css/*.css'))
gulp.task('clean-js', () => del('dist/js/*.js'))
gulp.task('copy-assets', ['clean-assets'], cb => {
pump([
gulp.src([
'src/assets/**/*.*'
]),
gulp.dest('dist/assets')
], cb)
})
gulp.task('copy-cname', cb => {
pump([
gulp.src([
'CNAME'
]),
gulp.dest('dist')
], cb)
})
gulp.task('lint-js', cb => {
pump([
gulp.src([
'gulpfile.js',
'src/js/app.js'
]),
standard(),
standard.reporter('default', {
breakOnError: true,
breakOnWarning: true
})
], cb)
})
gulp.task('minify-html', cb => {
pump([
gulp.src('src/*.html'),
htmlmin({
collapseWhitespace: true,
removeComments: true
}),
gulp.dest('./dist'),
browserSync.stream()
], cb)
})
gulp.task('default', ['build'], () => {
browserSync.init({
open: false,
port: 6590,
reloadOnRestart: true,
server: './dist',
ui: false
})
gulp.watch('src/*.html', ['minify-html'])
gulp.watch('src/css/*.css', ['build-css'])
gulp.watch('src/js/*.js', ['build-js'])
})