-
Notifications
You must be signed in to change notification settings - Fork 5
/
add-cache-busting.js
38 lines (33 loc) · 1.05 KB
/
add-cache-busting.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
'use strict';
const filter = require('gulp-filter');
const lazypipe = require('lazypipe');
const rev = require('gulp-rev');
const revReplace = require('gulp-rev-replace');
const size = require('gulp-size');
const elementsFilter = filter(['elements/*'], { restore: true });
const indexFilter = filter(['index.html', 'elements/*'], { restore: true });
/**
* The elements.js file is imported from elements.html in the same directly.
* The path prefix must therefore be removed.
*/
function removePathFromJSfile(filename) {
if (filename.endsWith('js')) {
return filename.replace('elements/', '');
}
return filename;
}
/**
* Adds cache busting to the element/elements.html file
*/
module.exports = lazypipe()
.pipe(() => elementsFilter)
.pipe(rev)
.pipe(() => size({title: 'add-cache-busting'}))
.pipe(() => elementsFilter.restore)
.pipe(() => indexFilter)
.pipe(() => revReplace({
modifyUnreved: removePathFromJSfile,
modifyReved: removePathFromJSfile,
}))
.pipe(() => size({title: 'add-cache-busting (replace)'}))
.pipe(() => indexFilter.restore);