1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/lib/built-asset-urls.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

24 lines
590 B
JavaScript

import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
// Get an MD4 Digest Hex content hash, loosely based on Webpack `[contenthash]`
function getContentHash(absFilePath) {
const buffer = fs.readFileSync(absFilePath)
const hash = crypto.createHash('md4')
hash.update(buffer)
return hash.digest('hex')
}
function getUrl(relFilePath) {
const absFilePath = path.join(process.cwd(), relFilePath)
return `/${relFilePath}?hash=${getContentHash(absFilePath)}`
}
export default {
main: {
js: getUrl('dist/index.js'),
css: getUrl('dist/index.css'),
},
}