Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created March 18, 2019 05:26
Show Gist options
  • Select an option

  • Save theKashey/5020f6b7715f02ab0f0d50349b91a24b to your computer and use it in GitHub Desktop.

Select an option

Save theKashey/5020f6b7715f02ab0f0d50349b91a24b to your computer and use it in GitHub Desktop.
Host node.js module resultion
console.log(require.extensions);
// to prevent name resolution races - hoist some extensions to top of the list
const hoistExtensions = (hoistedExtensions) => {
const restExtensions = {};
Object
.keys(require.extensions)
.forEach(name => {
if (hoistedExtensions.indexOf(name) < 0) {
restExtensions[name] = require.extensions[name];
delete require.extensions[name];
}
});
Object.assign(require.extensions, restExtensions);
};
// hoist js (over .less)
hoistExtensions(['.js', '.jsx']);
// host ts (over .js)
hoistExtensions(['.ts', '.tsx']);
console.log(require.extensions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment