-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
102 lines (91 loc) · 2.16 KB
/
gulpfile.mjs
File metadata and controls
102 lines (91 loc) · 2.16 KB
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
import { src, dest, series, parallel, watch } from 'gulp';
import * as dartSass from 'sass';
import gulpSass from 'gulp-sass';
import cssnano from 'gulp-cssnano';
import autoprefixer from 'gulp-autoprefixer';
import rename from 'gulp-rename';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
import imagemin from 'gulp-imagemin';
import sourcemaps from 'gulp-sourcemaps';
import clean from 'gulp-clean';
import kit from 'gulp-kit';
import browserSyncImport from 'browser-sync';
const sass = gulpSass(dartSass);
const browserSync = browserSyncImport.create();
const reload = browserSync.reload;
const paths = {
html: './html/**/*.kit',
sass: './src/sass/**/*.scss',
js: './src/js/**/*.js',
img: './src/img/*',
dist: './dist',
sassDest: './dist/css',
jsDest: './dist/js',
imgDest: './dist/img',
};
function sassCompiler() {
return src(paths.sass)
.pipe(sourcemaps.init())
.pipe(sass.sync().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cssnano())
.pipe(
rename({
suffix: '.min',
})
)
.pipe(sourcemaps.write())
.pipe(dest(paths.sassDest));
}
function javaScript() {
return src(paths.js)
.pipe(sourcemaps.init())
.pipe(
babel({
presets: ['@babel/env'],
})
)
.pipe(uglify())
.pipe(
rename({
suffix: '.min',
})
)
.pipe(sourcemaps.write())
.pipe(dest(paths.jsDest));
}
function convertImages() {
return src(paths.img, { encoding: false })
.pipe(imagemin())
.pipe(dest(paths.imgDest));
}
function handleKits() {
return src(paths.html).pipe(kit()).pipe(dest('./'));
}
function startBrowserSync() {
browserSync.init({
server: {
baseDir: './',
},
browser: 'Firefox Developer Edition',
});
}
function watchForChanges() {
watch('./*.html').on('change', reload);
watch(
[paths.html, paths.sass, paths.js],
parallel(handleKits, sassCompiler, javaScript)
).on('change', reload);
watch(paths.img, convertImages).on('change', reload);
}
const mainFunctions = series(
handleKits,
sassCompiler,
javaScript,
convertImages
);
export function cleanStuff() {
return src(paths.dist, { read: false }).pipe(clean());
}
export default parallel(mainFunctions, startBrowserSync, watchForChanges);