@ministryofjustice/module-alias
v1.1.1
Published
Module aliases (based on work by Nick Gavrilov [email protected])
Downloads
2,896
Readme
@ministryofjustice/module-alias
Module Alias creates aliases to the location of any package on your file system from configuration in package.json
.
Not:
require('../../../../some/very/deep/module')
But:
const module = require('@deep/module')
Or you can register directories that will behave like node_modules
.
Install
npm i -P @ministryofjustice/module-alias
Usage
Add configuration to package.json
:
Aliases
{
"_moduleAliases": {
"@root" : ".",
"@deep" : "src/some/very/deep/directory/or/file",
"@my_module" : "lib/some-file.js",
"something" : "src/foo"
}
}
Directories
{
"_moduleDirectories": [
"src/node_modules_custom"
]
}
Module Alias will resolve the location of package.json
and register any aliases contained in it before applying the alias to require
during execution.
Registering from an entry point
Include this line at the top of your entry point JS file:
require('@ministryofjustice/module-alias/register')
The path to package.json
is determined from the location of the process current working directory. (Ordinarily, this is root directory of the application.)
Registering from a module
Include this line at the top of any JS file:
require('@ministryofjustice/module-alias/register-module')(module)
The path to package.json
is derived from the location of the module. (This is useful when the path to package.json
cannot be determined from the location of the process current working directory.)
About this package
@ministryofjustice/module-alias
is a fork of module-alias
with an improved mechanism for resolving the location of package.json
and the removal of some features we do not use.