1 | var crypto = require('crypto')
|
2 | var path = require('path')
|
3 | var cwd = process.cwd()
|
4 |
|
5 | module.exports = (code, fileName, compiledDir) => {
|
6 | var hash = crypto
|
7 | .createHash('sha256')
|
8 | .update(fileName + code, 'utf8')
|
9 | .digest('hex')
|
10 | fileName = path.relative(cwd, fileName)
|
11 | var hashed = fileName.replace(/[^\w]/g, '_') + '_' + hash + '.js'
|
12 | return path.join(compiledDir, hashed)
|
13 | }
|