forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
executable file
·40 lines (35 loc) · 1.28 KB
/
bundle.js
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
34
35
36
37
38
39
40
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict' // eslint-disable-line node/shebang
const fs = require('fs')
const path = require('path')
const browserify = require('browserify')
const commonShake = require('common-shakeify')
const packFlat = require('browser-pack-flat')
const exorcist = require('exorcist')
const {minify} = require('uglify-js')
const dist = path.join(__dirname, 'packages/client/dist')
browserify(path.join(__dirname, 'packages/client/'), {debug: true, standalone: 'XMPP'})
.transform('babelify', {global: true})
.plugin(commonShake)
.plugin(packFlat)
// .on('dep', dep => {
// console.log(dep.file)
// })
.bundle()
.pipe(exorcist(path.join(dist, 'xmpp.js.map')))
.pipe(fs.createWriteStream(path.join(dist, 'xmpp.js')))
.on('finish', () => {
const bundled = fs.readFileSync(path.join(dist, 'xmpp.js')).toString()
const sourceMap = fs.readFileSync(path.join(dist, 'xmpp.js.map')).toString()
const {code, map, error} = minify(bundled, {
sourceMap: {
content: sourceMap,
url: 'xmpp.min.js.map',
filename: 'xmpp.min.js',
},
})
if (error) return console.error(error)
fs.writeFileSync(path.join(dist, 'xmpp.min.js'), code)
fs.writeFileSync(path.join(dist, 'xmpp.min.js.map'), map)
})