Created
March 18, 2019 05:26
-
-
Save theKashey/5020f6b7715f02ab0f0d50349b91a24b to your computer and use it in GitHub Desktop.
Host node.js module resultion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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