aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/utils/filename-hash.js
blob: e0d8a6dec7a768ca41b9393d85427087c8069a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const crypto = require("crypto");

module.exports.getFileNameHash = (fileName, prefix, justHash = false) => {
	let hash = crypto
		.createHash("md5")
		.update(`${prefix}-${fileName}`)
		.digest("hex");

	if (production) {
		return hash;
	} else {
		hash = hash.substring(16);
		if (justHash) {
			return hash;
		} else {
			return `${fileName}-${hash}`;
		}
	}
};