ilearnio / module-alias

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

Using it with babel #2

Closed Devric closed 8 years ago

Devric commented 8 years ago

Any chance this works with babel-cli?

i basically converts to es5 from babel-cli than run normal node server on the compiled code.

ilearnio commented 8 years ago

Have you tried to set up module-alias programmatically, or you just use package.json as a place to store aliases? I'm not sure whether babel-cli uses some custom way to require modules but if not then the setup should be pretty much the same

Devric commented 8 years ago

tried both aint working, babel seems to have resolve config similar to webpack. i'll see if it shares similar mechanism

ilearnio commented 8 years ago

I guess it shoud be fixed now. Is there any way you could check it again?

ilearnio commented 8 years ago

I'm closing this since no response

ndabAP commented 6 years ago

I still got the issue. When I transpile it with babel into another directory the require statement aims to my untranspiled code.

src/index.js (original)

import a from '@b'

This resolves to src/ instead of dist/src:

dist/src/index (transpiled)

var a = require('@b')
ilearnio commented 6 years ago

@ndabAP You need to configure your aliases relative to the directory, like moduleAlias.addAlias('@b', __dirname + '/b') so it will look deeper in the current directory only