Skip to content

Instantly share code, notes, and snippets.

@jdalton
Last active July 3, 2024 02:00
Show Gist options
  • Save jdalton/57ea855c036f28be6235884d96f69b8d to your computer and use it in GitHub Desktop.
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