Demonstrates using tsconfig-paths/register
with vanilla node
.
yarn install --dev
yarn build
yarn test
This works by using three configuration settings.
-
In
tsconfig.json
, we set"baseUrl": "./src"
.This setting ensures that
tsc
build paths don't includesrc
-
In
tsconfig.json
, we definepaths
to include the mapping"~/*": ["./*"]
This setting allows imports of
~/foo
to resolve to a relative path tobaseUrl
. -
In
package.json
, we invokenode
with theTS_NODE_BASEURL=./dist
environemtn variable.This setting tells
node
to use./dist
as thebaseUrl
(instead of./src
).