Created
July 8, 2020 16:05
-
-
Save marcosbozzani/1a45b92119f20a03640f0bf7e68b3c7a to your computer and use it in GitHub Desktop.
Node root relative require "~/"
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
| const Path = require("path"); | |
| const Module = require("module"); | |
| const original = Module.prototype.require; | |
| Module.prototype.require = function() { | |
| if (arguments[0][0] === "~") { | |
| arguments[0] = Path.join(__dirname, arguments[0].slice(1)); | |
| } | |
| return original.apply(this, arguments); | |
| }; | |
| // jsconfig.json | |
| // { | |
| // "compilerOptions": { | |
| // "module": "commonjs", | |
| // "baseUrl": ".", | |
| // "paths": { "~/*": ["./*"] } | |
| // } | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment