Skip to content

Instantly share code, notes, and snippets.

@jdalton jdalton/gz.js
Last active Jun 7, 2017

Embed
What would you like to do?
'use strict'
const fs = require('fs')
const path = require('path')
const zlib = require('zlib')
require.extensions['.gz'] =
require.extensions['.js.gz'] = (module, filename) => {
if (path.extname(filename.slice(0, -3)) === '.js') {
let content = zlib.unzipSync(fs.readFileSync(filename)).toString()
content = content.charCodeAt(0) === 0xFEFF ? content.slice(1) : content
module._compile(content, filename)
}
}
require.extensions['.js'] = ((func) => (module, filename) => {
const gz = filename + '.gz'
return fs.existsSync(gz) ? require.extensions['.gz'](module, gz) : func(module, filename)
})(require.extensions['.js'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.