-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·33 lines (29 loc) · 918 Bytes
/
build.js
File metadata and controls
executable file
·33 lines (29 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env node
const browserify = require('browserify');
const crypto = require('crypto')
const fs = require('fs')
const path = require('path')
const splitRequire = require('split-require/plugin')
const to = require('flush-write-stream')
const b = browserify({ debug: true })
b.add('./components/main.js')
b.plugin(splitRequire, {
output: hashOutput
})
b.bundle().pipe(hashOutput('main.js'))
function hashOutput (bundleName) {
const stream = fs.createWriteStream('/tmp/' + bundleName)
const hash = crypto.createHash('sha1')
return to(onwrite, onend)
function onwrite (chunk, enc, cb) {
hash.update(chunk)
stream.write(chunk, cb)
}
function onend (cb) {
stream.end()
const name = bundleName.replace(/\.js$/, '')
+ '_' + hash.digest('hex').slice(0, 10) + '.js'
this.emit('name', name)
fs.rename(path.join('/tmp/' + bundleName), path.join('./bundle', name), cb)
}
}