Skip to content

Instantly share code, notes, and snippets.

@pyrsmk
Created July 23, 2019 14:02
Show Gist options
  • Save pyrsmk/bd057fc3933a0b941087fb977ee0e7f5 to your computer and use it in GitHub Desktop.
Save pyrsmk/bd057fc3933a0b941087fb977ee0e7f5 to your computer and use it in GitHub Desktop.
Uglify task for Just
const uglify = require('uglify-js')
const fs = require('fs')
module.exports = async options => {
const params = {}
if ('sourcemap' in options && 'filename' in options) {
params.sourceMap = {
filename: options.filename,
url: 'inline',
}
}
await new Promise((resolve, reject) => {
fs.readFile(options.from, 'utf8', (readError, data) => {
if (readError) reject(readError)
fs.writeFile(options.to, uglify.minify(data, params).code, writeError => {
if (writeError) reject(writeError)
resolve()
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment