-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.js
More file actions
21 lines (16 loc) · 700 Bytes
/
Copy pathhash.js
File metadata and controls
21 lines (16 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var path = require('path');
var fs = require('fs');
var md5 = require('md5-file');
var distPath = path.join(__dirname, 'dist');
var stylesPath = path.join(distPath, 'styles.css');
var scriptsPath = path.join(distPath, 'scripts.js');
var indexPath = path.join(distPath, 'index.html');
var stylesMD5 = 'styles.' + md5(stylesPath) + '.css';
var scriptsMD5 = 'scripts.' + md5(scriptsPath) + '.js';
fs.renameSync(stylesPath, path.join(distPath, stylesMD5));
fs.renameSync(scriptsPath, path.join(distPath, scriptsMD5));
var indexFile = fs.readFileSync(indexPath, { encoding: 'utf8' });
fs.writeFileSync(
indexPath,
indexFile.replace('styles.css', stylesMD5).replace('scripts.js', scriptsMD5)
);