Created
January 19, 2022 11:14
-
-
Save TCalkhoven/232b0514f40f36182a88d7d18073e970 to your computer and use it in GitHub Desktop.
Utility function to include Typescript from Javascript using ts-node
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
function loadFromTypescript(path) { | |
const interopRequireDefault = obj => | |
obj && obj.__esModule ? obj : { default: obj }; | |
const registerer = require("ts-node").register({ | |
project: "./tsconfig.json", | |
transpileOnly: true, | |
"compilerOptions": { | |
"module": "commonjs" | |
} | |
}); | |
registerer.enabled(true); | |
return interopRequireDefault(require(path)).default || {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment