-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
55 lines (52 loc) · 1.58 KB
/
gulpfile.js
File metadata and controls
55 lines (52 loc) · 1.58 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
const { series, src, dest } = require('gulp');
const cleanCSS = require('gulp-clean-css');
const hash = require('gulp-hash');
const del = require('del');
const htmlreplace = require('gulp-html-replace');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const distPath = 'dist';
function cleanDist() {
return del(`${distPath}/**`);
}
let hashedCSSFilename = "";
function minifyCSS() {
const prefixConfig = {
browsers: ['last 2 version']
};
const prefixPlugins = [
autoprefixer(prefixConfig)
];
return src('css/*.css')
.pipe(postcss(prefixPlugins))
.pipe(hash())
.pipe(cleanCSS({compatibility: 'ie8'}, (details) => {
hashedCSSFilename = details.name;
console.log(`Emitted file: ${hashedCSSFilename}`);
}))
.pipe(dest(distPath));
}
function emitImgs() {
return src('assets/*')
.pipe(dest(distPath));
}
function emitHTML(cb) {
return src('html/*.html')
.pipe(htmlreplace({
css: hashedCSSFilename,
ghImg: {
src: 'github-green.png',
tpl: '<img src="%s" alt="My Github" />'
},
liImg: {
src: 'linkedin-green.png',
tpl: '<img src="%s" alt="My LinkedIn" />'
},
me: {
src: 'me-1.jpg',
tpl: '<img class="hide-lte-749" style="align-self:center;" src="%s" alt="Me" />'
}
}))
.pipe(dest(distPath));
}
exports.default = series(cleanDist, minifyCSS, emitImgs, emitHTML);