-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (63 loc) · 1.53 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
const del = require('del');
const gulp = require('gulp');
const babel = require('gulp-babel');
const csso = require('gulp-csso');
const htmlMinifier = require('gulp-html-minifier');
const inlineSource = require('gulp-inline-source');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const sassInlineImages = require('sass-inline-image');
const named = require('vinyl-named');
const pump = require('pump');
const webpack = require('webpack-stream');
const sourceDir = './src';
const destDir = './dist';
function clean() {
return del([`${destDir}/**`]);
}
function copy() {
return pump(
gulp.src(`${sourceDir}/**`),
gulp.dest(destDir),
);
}
function scripts() {
return pump(
gulp.src(`${destDir}/js/*.js`),
named(),
webpack({ mode: 'production' }),
babel({ presets: ['@babel/preset-env'] }),
uglify(),
gulp.dest(`${destDir}/js`),
);
}
function styles() {
return pump(
gulp.src(`${destDir}/scss/*.scss`),
sass({
functions: sassInlineImages({ base: destDir }),
}).on('error', sass.logError),
csso(),
gulp.dest(`${destDir}/css`),
);
}
function html() {
return pump(
gulp.src(`${destDir}/**/*.html`),
inlineSource({ compress: false }),
htmlMinifier({ collapseWhitespace: true }),
gulp.dest(destDir),
);
}
function cleanAfterBuild() {
return del([`${destDir}/{css,js,scss,spinner.gif}`]);
}
const build = gulp.series(
clean,
copy,
gulp.parallel(scripts, styles),
html,
cleanAfterBuild,
);
exports.clean = clean;
exports.default = build;