-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathgulpfile-esm.js
118 lines (102 loc) · 2.41 KB
/
gulpfile-esm.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
import gulp from 'gulp';
import babel from 'gulp-babel';
import postcss from 'gulp-postcss';
import replace from 'gulp-replace';
import htmlmin from 'gulp-htmlmin';
import terser from 'gulp-terser';
import pimport from 'postcss-import';
import minmax from 'postcss-media-minmax';
import autoprefixer from 'autoprefixer';
import csso from 'postcss-csso';
import sync from 'browser-sync';
// HTML
export const html = () => {
return gulp.src('src/*.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
}))
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
};
// Styles
export const styles = () => {
return gulp.src('src/styles/index.css')
.pipe(postcss([
pimport,
minmax,
autoprefixer,
csso,
]))
.pipe(replace(/\.\.\//g, ''))
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
};
// Scripts
export const scripts = () => {
return gulp.src('src/scripts/index.js')
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(terser())
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
};
// Copy
export const copy = () => {
return gulp.src([
'src/fonts/**/*',
'src/images/**/*',
], {
base: 'src'
})
.pipe(gulp.dest('dist'))
.pipe(sync.stream({
once: true
}));
};
// Paths
export const paths = () => {
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
export const server = () => {
sync.init({
ui: false,
notify: false,
server: {
baseDir: 'dist'
}
});
};
// Watch
export const watch = () => {
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
export default gulp.series(
gulp.parallel(
html,
styles,
scripts,
copy,
),
paths,
gulp.parallel(
watch,
server,
),
);