From e434aea6ac21b992334501cd494f0594d91c46b5 Mon Sep 17 00:00:00 2001 From: Oliver Akins Date: Mon, 7 Mar 2022 22:21:30 -0600 Subject: [PATCH] Add an import alias for shorter filepath imports --- server/package.json | 5 ++++- server/src/main.ts | 3 +++ server/tsconfig.json | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/package.json b/server/package.json index 8bae4ec..d12c91b 100644 --- a/server/package.json +++ b/server/package.json @@ -7,7 +7,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "tsc", "start": "node dist/main.js" - }, + }, "author": "Oliver Akins", "license": "UNLICENSED", "dependencies": { @@ -21,5 +21,8 @@ "devDependencies": { "@types/glob": "^7.2.0", "@types/uuid": "^8.3.4" + }, + "_moduleAliases": { + "@": "./dist" } } diff --git a/server/src/main.ts b/server/src/main.ts index 30d1b3c..f01321c 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -1,3 +1,6 @@ +// Filepath alias resolution +import "module-alias/register"; + import startWebsocketServer from "./websocket"; import { Logger } from "tslog"; import toml from "toml"; diff --git a/server/tsconfig.json b/server/tsconfig.json index b844c9f..02632ec 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -46,7 +46,9 @@ /* Module Resolution Options */ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + "paths": { + "@/*": ["./src/*"] + }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */