Skip to content

Commit 0d946df

Browse files
authored
Merge pull request #85 from ilearnio/doc/libraries
2 parents 7aada2c + 23403db commit 0d946df

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require('my_private_module');
2727
import module from 'my_private_module'
2828
```
2929

30-
**WARNING:** This module should not be used in other npm modules since it modifies the default `require` behavior! It is designed to be used for development of final projects i.e. web-sites, applications etc.
30+
**WARNING:** If you are going to use this package within another NPM package, please read [Using within another NPM package](#using-within-another-npm-package) first to be aware of potential caveats.
3131

3232
## Install
3333

@@ -160,6 +160,16 @@ Unfortunately, `module-alias` itself would not work from Jest due to a custom be
160160

161161
More details on the [official documentation](https://jestjs.io/docs/en/configuration#modulenamemapper-objectstring-string--arraystring).
162162

163+
## Using within another NPM package
164+
165+
You can use `module-alias` within another NPM package, however there are a few things to take into consideration.
166+
167+
1. As the aliases are global, you should make sure your aliases are unique, to avoid conflicts with end-user code, or with other libraries using module-alias. For example, you could prefix your aliases with '@my-lib/', and then use require('@my-lib/deep').
168+
2. The internal "register" mechanism may not work, you should not rely on `require('module-alias/register')` for automatic detection of `package.json` location (where you defined your aliases), as it tries to find package.json in either the current working directory of your node process, or two levels down from node_modules/module-alias. It is extremely likely that this is end-user code. So, instead, your should either register aliases manually with `moduleAlias.addAlias`, or using something like `require('module-alias')(__dirname)`.
169+
170+
Here is an [example project](https://github.com/Kehrlann/module-alias-library).
171+
172+
163173
## Known incompatibilities
164174

165175
This module does not play well with:

0 commit comments

Comments
 (0)