-
Notifications
You must be signed in to change notification settings - Fork 287
/
gulpfile-old.js
114 lines (98 loc) · 2.4 KB
/
gulpfile-old.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
var gulp = require('gulp');
var babel = require('gulp-babel');
var postcss = require('gulp-postcss');
var replace = require('gulp-replace');
var htmlmin = require('gulp-htmlmin');
var terser = require('gulp-terser');
var sync = require('browser-sync');
// HTML
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true
}))
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
});
// Styles
gulp.task('styles', function() {
return gulp.src('src/styles/index.css')
.pipe(postcss([
require('postcss-import'),
require('postcss-media-minmax'),
require('autoprefixer'),
require('postcss-csso')
]))
.pipe(replace(/\.\.\//g, ''))
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
});
// Scripts
gulp.task('scripts', function() {
return gulp.src('src/scripts/index.js')
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(terser())
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
});
// Copy
gulp.task('copy', function() {
return gulp.src([
'src/fonts/**/*',
'src/images/**/*'
], {
base: 'src'
})
.pipe(gulp.dest('dist'))
.pipe(sync.stream({
once: true
}));
});
// Paths
gulp.task('paths', function() {
return gulp.src('dist/*.html')
.pipe(replace(
/(<link rel="stylesheet" href=")styles\/(index.css">)/, '$1$2'
))
.pipe(replace(
/(<script src=")scripts\/(index.js">)/, '$1$2'
))
.pipe(gulp.dest('dist'));
});
// Server
gulp.task('server', function() {
sync.init({
ui: false,
notify: false,
server: {
baseDir: 'dist'
}
});
});
// Watch
gulp.task('watch', function() {
gulp.watch('src/*.html', gulp.series('html', 'paths'));
gulp.watch('src/styles/**/*.css', gulp.series('styles'));
gulp.watch('src/scripts/**/*.js', gulp.series('scripts'));
gulp.watch([
'src/fonts/**/*',
'src/images/**/*'
], gulp.series('copy'));
});
// Default
gulp.task('default', gulp.series(
gulp.parallel(
'html',
'styles',
'scripts',
'copy'
),
'paths',
gulp.parallel(
'watch',
'server'
)
));