webpack-theme-color-replacer
Version:
A webpack plugin designed to dynamicly change the theme colors at runtime. 实现运行时快速动态替换主题色的webpack插件.
20 lines (17 loc) • 528 B
JavaScript
var crypto = require('crypto')
module.exports = function replaceFileName(outFile, code) {
var p1 = outFile.indexOf('contenthash:')
if (p1 > -1) {
p1 += 12
var p2 = outFile.indexOf(']', p1)
if (p2 > p1) {
var len = outFile.substr(p1, p2 - p1)
outFile = outFile.replace('[contenthash:' + len + ']', getHash(code).slice(0, len))
}
}
return outFile;
}
function getHash(str) {
var md = crypto.createHash('md5');
return md.update(str).digest('hex');
}