-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
81 lines (81 loc) · 2.18 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
const { src, dest, series, parallel, watch } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const cssnano = require('gulp-cssnano');
const autoprefixer = require('gulp-autoprefixer');
const rename = require('gulp-rename');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const clean = require('gulp-clean');
const kit = require('gulp-kit');
const paths = {
dist: './dist',
html: './html/**/*.kit',
sass: './src/sass/**/*.scss',
sassDest: './dist/css',
js: './src/js/**/*.js',
jsDest: './dist/js',
img: './src/img/*',
imgDest: './dist/img',
};
function buildStyles(done) {
src(paths.sass)
.pipe(sourcemaps.init())
// .pipe(sourcemaps.identityMap())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
// .pipe(rename({ extname: '.css.map' }))
.pipe(dest(paths.sassDest));
done();
}
function buildScripts(done) {
src(paths.js)
.pipe(sourcemaps.init())
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(dest(paths.jsDest));
done();
}
function convertImages(done) {
src(paths.img).pipe(imagemin()).pipe(dest(paths.imgDest));
done();
}
function handleKits(done) {
src(paths.html).pipe(kit()).pipe(dest('./'));
done();
}
function cleanStuff(done) {
src(paths.dist, { read: false }).pipe(clean());
done();
}
function startBroweserSync(done) {
browserSync.init({
server: {
baseDir: './',
},
});
done();
}
function watchForChanges(done) {
watch('./*.html').on('change', reload);
watch(paths.html, handleKits);
watch(paths.sass, buildStyles).on('change', reload);
watch(paths.js, buildScripts).on('change', reload);
watch(paths.img, convertImages).on('change', reload);
done();
}
const main = series(
parallel(handleKits, buildStyles, buildScripts, convertImages),
startBroweserSync,
watchForChanges,
);
exports.default = main;
exports.clean = cleanStuff;