Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 20, 2024
1 parent 76a7411 commit 0604ac4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})

0 comments on commit 0604ac4

Please sign in to comment.