-
-
Save Paradoxia/0c75ddd826469f0f615660d1e20f37d4 to your computer and use it in GitHub Desktop.
This file contains 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 {resolve} = require('path'); | |
var hjson = require('hjson'); // Allow us to use comments in json files | |
var fs = require('fs'); | |
const TSModuleAlias = require("@momothepug/tsmodule-alias"); | |
function resolveTsconfigPathsToAlias({tsconfigPath = './tsconfig.json', rootConfigBasePath: rootConfigBasePath = './'} = {}) { | |
const rawJson = fs.readFileSync(tsconfigPath, 'UTF-8'); | |
const commentsStrippedJson = hjson.parse(rawJson); | |
const {paths, outDir} = commentsStrippedJson.compilerOptions; | |
const aliases = {}; | |
Object.keys(paths).forEach((item) => { | |
const key = item.replace('/*', ''); | |
// @ts-ignore | |
aliases[key] = resolve(rootConfigBasePath, outDir + "/" + paths[item][0].replace('/*', '')) ; | |
}); | |
return aliases | |
} | |
const aliases = resolveTsconfigPathsToAlias(); | |
TSModuleAlias.use(aliases); |
This file contains 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
require("./aliasResolver.js"); // Call this to set the aliases base on "outDir" setting | |
import express, {Application, Request, Response} from "express"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment