-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathgulpfile-cjs.js
128 lines (105 loc) · 2.48 KB
/
gulpfile-cjs.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
const gulp = require('gulp');
const babel = require('gulp-babel');
const postcss = require('gulp-postcss');
const replace = require('gulp-replace');
const htmlmin = require('gulp-htmlmin');
const terser = require('gulp-terser');
const sync = require('browser-sync');
// HTML
const html = () => {
return gulp.src('src/*.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
}))
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
};
exports.html = html;
// Styles
const styles = () => {
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());
};
exports.styles = styles;
// Scripts
const scripts = () => {
return gulp.src('src/scripts/index.js')
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(terser())
.pipe(gulp.dest('dist'))
.pipe(sync.stream());
};
exports.scripts = scripts;
// Copy
const copy = () => {
return gulp.src([
'src/fonts/**/*',
'src/images/**/*',
], {
base: 'src'
})
.pipe(gulp.dest('dist'))
.pipe(sync.stream({
once: true
}));
};
exports.copy = copy;
// Paths
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'));
};
exports.paths = paths;
// Server
const server = () => {
sync.init({
ui: false,
notify: false,
server: {
baseDir: 'dist'
}
});
};
exports.server = server;
// Watch
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));
};
exports.watch = watch;
// Default
exports.default = gulp.series(
gulp.parallel(
html,
styles,
scripts,
copy,
),
paths,
gulp.parallel(
watch,
server,
),
);