Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created December 13, 2024 16:36
Show Gist options
  • Save gabrielschulhof/ea87a65fdc0dab22385415e03060a88c to your computer and use it in GitHub Desktop.
Save gabrielschulhof/ea87a65fdc0dab22385415e03060a88c to your computer and use it in GitHub Desktop.
const Module = require('node:module')
const path = require('node:path')
const load = Module._load
const aliases = [['myawesomemodule', path.dirname(require.resolve('./myawesomemodule/'))]]
Module._load = function (request, parent) {
const alias = aliases.find(([module]) => request.startsWith(module))
return alias
? require(request.replace(new RegExp(`^${alias[0]}`), alias[1]))
: load.apply(this, arguments)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment