-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
65 lines (58 loc) · 1.76 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
const { src, dest, series } = require('gulp')
const postcss = require("gulp-postcss");
const replace = require("gulp-replace");
const fs = require("fs");
const babel = require("gulp-babel");
const uglify = require("gulp-uglify");
const del = require("del");
function compressStyles() {
return src('dist/styles/**/*.css')
.pipe(postcss([
require('postcss-import'),
require('autoprefixer'),
require('cssnano')
]))
.pipe(dest('dist/styles/'));
}
function inlineStyles() {
return src('dist/**/*.html')
.pipe(replace(
/<link rel="stylesheet" href="([^"]+)"([^>]*)>/g,
(match, fileName, restAttributes) => {
const styles = fs.readFileSync(`dist${fileName}`);
return restAttributes
? `<style${restAttributes}>${styles}</style>`
: `<style>${styles}</style>`;
}
))
.pipe(dest('dist'));
}
function compressScripts() {
return src('dist/scripts/**/*.js')
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(uglify())
.pipe(dest('dist/scripts/'));
}
function inlineScripts() {
return src('dist/**/*.html')
.pipe(replace(
/<script src="([^"]+)"><\/script>/g,
(match, fileName) => {
const script = fs.readFileSync(`dist${fileName}`);
return `<script>${script}</script>`;
}
))
.pipe(dest('dist'));
}
function clean() {
return del([
'dist/styles',
'dist/scripts',
])
}
const styles = series(compressStyles, inlineStyles)
const scripts = series(compressScripts, inlineScripts)
const pack = series(styles, scripts, clean)
exports.default = pack;