https://github.com/sooniter/alias-register
set `resolve.alias` for node.js runtime
https://github.com/sooniter/alias-register
nodejs register resolve
Last synced: 7 months ago
JSON representation
set `resolve.alias` for node.js runtime
- Host: GitHub
- URL: https://github.com/sooniter/alias-register
- Owner: SoonIter
- License: mit
- Created: 2024-03-14T07:15:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-14T08:13:36.000Z (almost 2 years ago)
- Last Synced: 2025-06-16T21:52:09.273Z (7 months ago)
- Topics: nodejs, register, resolve
- Language: TypeScript
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alias-register
## Get Started
say bye to webpack multi-instances ~
```js
// alias.config.cjs
const path = require('path');
const config = {
resolve: {
alias: {
lib: path.join(__dirname, 'lib'),
},
},
};
module.exports = config;
```
```sh
node --loader alias-register ./main.js
# or
NODE_OPTIONS="--loader alias-register" node ./main.js
# if Node.js v20.6.0 and above
node --import alias-register ./main.js
NODE_OPTIONS="--import alias-register" node ./main.js
```
### Other Usages
#### ESM only loader
If you only need to add TypeScript support in a Module context, you can use the ESM loader:
##### Node.js v20.6.0 and above
```sh
node --import alias-register/esm ./main.js
```
##### Node.js v20.5.1 and below
```sh
node --loader alias-register/esm ./main.js
```
#### CommonJS only loader
If you only need to add TypeScript & ESM support in a CommonJS context, you can use the CJS loader:
```sh
node --require alias-register/cjs ./main.js
```