-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
116 lines (96 loc) · 2.4 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
'use strict'
const gulp = require('gulp')
const autoprefixer = require('gulp-autoprefixer')
const csso = require('gulp-csso')
const htmlmin = require('gulp-htmlmin')
const image = require('gulp-image')
const server = require('gulp-server-livereload')
const uglify = require('gulp-uglify-es').default
const sass = require('gulp-sass')
const path = {
main: './src',
build: './dist'
}
const MODE = {
compress: false,
path: './src',
tasks: ['live-reload', 'sass:watch']
}
const config = {
host: 'localhost',
port: 3000
}
const AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
if (MODE.compress) {
MODE.path = path.build
MODE.tasks = [
'views',
'styles',
'scripts',
'images',
'videoCopy',
'live-reload',
'app.js [not compress]'
]
gulp.task('views', function () {
return gulp.src([`${path.main}/*.html`])
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest(`${path.build}`))
})
gulp.task('styles', function () {
return gulp.src(`${path.main}/css/*.css`)
.pipe(autoprefixer({ browsers: AUTOPREFIXER_BROWSERS }))
.pipe(csso())
.pipe(gulp.dest(`${path.build}/css`))
})
gulp.task('scripts', function () {
return gulp.src([`${path.main}/js/*.js`, `!${path.main}/js/app.js`])
.pipe(uglify())
.pipe(gulp.dest(`${path.build}/js`))
})
gulp.task('app.js [not compress]', function () {
return gulp.src(`${path.main}/js/app.js`)
.pipe(gulp.dest(`${path.build}/js`))
})
gulp.task('images', function () {
return gulp.src(`${path.main}/img/**`)
.pipe(image())
.pipe(gulp.dest(`${path.build}/img`))
})
gulp.task('videoCopy', function () {
return gulp.src(`${path.main}/video/**`)
.pipe(gulp.dest(`${path.build}/video`))
})
}
gulp.task('sass', () => {
return gulp.src(`${path.main}/scss/*.scss`)
.pipe(sass().on(`error`, sass.logError))
.pipe(gulp.dest(`${path.main}/css`))
})
gulp.task('sass:watch', () => {
gulp.watch(`${path.main}/scss/*.scss`, [`sass`])
})
gulp.task('live-reload', () => {
gulp.src(MODE.path).pipe(server({
host: config.host,
port: config.port,
livereload: true,
defaultFile: 'index.html',
directoryListing: false,
open: true
}))
})
gulp.task('default', MODE.tasks)