path-alias is a drop in replacement for module-alias.
In addition to module-alias features, you're able to resolve a path from a string, ex: for fs or path operations.
Like module-alias, you can make aliases for directories and files, and define custom module paths.
This package isn't guaranteed to work nicely, and depends on github repos I have, instead of npm.
npm install https://github.com/int3nse-git/path-alias
See module-alias for most of the usage.
The differences are as follows:
_pathAliases
is a new name for_moduleAliases
in your package.json, but both workpath-alias/register
returns the module too nowaddAlias
can accept an object of aliases, simmilar to package.jsonpathContainsAlias
is a new name forisPathMatchesAlias
, but both workaddAlias
is a new name foraddAliases
, but both work
const pathAlias = require('path-alias/register');
const myModule = require('$modules/myModule.js');
console.log(pathAlias.resolve('$root/foo/bar.js')); // -> yourProjectDirectory/foo/bar.js
const pathAlias = require('path-alias');
console.log(pathAlias.resolve('$root/foo/bar.js')); // -> yourProjectDirectory/foo/bar.js