-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
151 lines (127 loc) · 2.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
const autoprefixer = require('autoprefixer');
const csso = require('gulp-csso');
const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const postcss = require('gulp-postcss');
const sync = require('browser-sync').create();
const concat = require('gulp-concat');
const replace = require('gulp-html-replace');
const uglify = require('gulp-uglify');
// HTML
gulp.task('html:concat', () => {
return gulp.src('src/*.html')
.pipe(replace({
'css': 'css/style.css',
'js-index': 'js/index.js',
'js-inner': 'js/inner.js'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('html:clean', () => {
return gulp.src('dist/*.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true
}))
.pipe(gulp.dest('dist'));
});
gulp.task('html', gulp.series(
'html:concat', 'html:clean', () => {
return gulp.src('dist/*.html')
.pipe(sync.stream({
once: true
}));
}
));
// CSS
gulp.task('css', () => {
return gulp.src('src/css/*.css')
.pipe(postcss([autoprefixer]))
.pipe(csso())
.pipe(concat('style.css'))
.pipe(gulp.dest('dist/css'))
.pipe(sync.stream());
});
gulp.task('js:index', () => {
return gulp.src('src/js/index.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// JavaScript
gulp.task('js:inner', () => {
return gulp.src([
'src/js/jquery.js',
'src/js/inner.js'
])
.pipe(uglify())
.pipe(concat('inner.js'))
.pipe(gulp.dest('dist/js'))
});
gulp.task('js', gulp.series(
gulp.parallel(
'js:index', 'js:inner'
)
));
// Copy
gulp.task('copy', () => {
return gulp.src([
'src/fonts/*',
'src/images/*',
'src/pictures/*'
], {
base: 'src',
encoding: false
})
.pipe(gulp.dest('dist'))
.pipe(sync.stream({
once: true
}));
});
// Server
gulp.task('server', () => {
sync.init({
ui: false,
notify: false,
server: {
baseDir: 'dist'
}
});
});
// Watch
gulp.task('watch:html', () => {
return gulp.watch('src/*.html', gulp.series('html'));
});
gulp.task('watch:css', () => {
return gulp.watch('src/css/*.css', gulp.series('css'));
});
gulp.task('watch:js', () => {
return gulp.watch('src/js/*.js', gulp.series('js'));
});
gulp.task('watch:copy', () => {
return gulp.watch([
'src/fonts/*',
'src/images/*',
'src/pictures/*'
], gulp.series('copy'));
});
gulp.task('watch', gulp.parallel(
'watch:html',
'watch:css',
'watch:js',
'watch:copy'
));
// Build
gulp.task('build', gulp.parallel(
'html',
'css',
'js',
'copy'
));
// Default
gulp.task('default', gulp.series(
'build',
gulp.parallel(
'watch',
'server'
)
));