ilearnio / module-alias

Register aliases of directories and custom module paths in Node
MIT License
1.76k stars 69 forks source link

Create "resolveAlias" method #95

Open Vasile-Peste opened 4 years ago

Vasile-Peste commented 4 years ago

I see that for advanced usage I can require the module and use methods like addAlias for adding new aliases.

I would like to be able also to resolve an alias. Use case:


const moduleAlias = require('module-alias');
const fs = require('fs');

fs.readFileSync(moduleAlias.resolveAlias("#root/my-file.txt");
Kehrlann commented 4 years ago

Would require.resolve("#root/your-module") solve your problem ?

Note, it's for resolving modules rather than files, see this discussion for more info: https://github.com/ilearnio/module-alias/issues/71

ghost commented 4 years ago

@Kehrlann, in commonjs looks good, but how about ES6 import? I'm using Typescript, so in the compilation is src/ and in the runtime is dist/. For example.

Kehrlann commented 4 years ago

@lvfxbr I highly looking into tsconfig-paths for TypeScript code ; rather than have to fiddle around with module-alias