Skip to content

Instantly share code, notes, and snippets.

@jdalton
Last active June 7, 2021 22:17
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jdalton/57ea855c036f28be6235884d96f69b8d to your computer and use it in GitHub Desktop.
'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