module-alias
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "module-alias", | ||
"description": "Simple module for registering aliases of directories and custom module paths", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": { | ||
"name": "Nikita Gavrilov" | ||
"name": "Nikita Gavrilov", | ||
"email": "artnikpro@gmail.com" | ||
}, | ||
@@ -8,0 +9,0 @@ "scripts": { |
@@ -7,3 +7,3 @@ # module-alias | ||
This package is highly inspired by [app-module-path](https://www.npmjs.com/package/app-module-path) package and it's totally backwards compatible with it. The main difference is that this package also allows you to create aliases of directories for further usage with `require`/`import` | ||
This package is highly inspired by [app-module-path](https://www.npmjs.com/package/app-module-path) package and it's totally backwards compatible with it. The main difference is that this package also allows creating aliases of directories for further usage with `require`/`import` | ||
@@ -39,5 +39,5 @@ ## Install | ||
import 'something' | ||
import foo from '@foo' | ||
import deepModule from '@bar/my-module' | ||
import module from 'some-module' // module from `node_modules_custom` directory | ||
import module from '@root/some-module' | ||
import veryDeepModule from '@bar/my-module' | ||
import myModule from '@my_module' // module from `node_modules_custom` directory | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
// | ||
moduleAlias.addAlias('@server', __dirname + '/src/server') | ||
moduleAlias.addAlias('@client', __dirname + '/src/client') | ||
@@ -59,3 +59,3 @@ // Or multiple aliases | ||
'@root' : __dirname, | ||
'@server': __dirname + '/src/server', | ||
'@client': __dirname + '/src/client', | ||
... | ||
@@ -99,2 +99,9 @@ }) | ||
## How it works? | ||
In order to register a custom modules path (`addPath`) it modifies the internal `Module._nodeModulePaths` method so that the directory then acts like it's the `node_modules` directory. | ||
In order to register an alias it modifies the internal `Module._resolveFilename` method so that when you fire `require` or `import` it first checks whether the given string starts with one of the registered aliases, if so, it then replaces the alias in the string with the target path of the alias | ||
### Tags | ||
@@ -101,0 +108,0 @@ Require alias, node import alias, node custom module directory, node local require paths, register module directory in nodejs |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7953
109