Skip to content

How can I create aliases for npm modules? #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
siddharthkp opened this issue Jun 5, 2017 · 6 comments
Closed

How can I create aliases for npm modules? #191

siddharthkp opened this issue Jun 5, 2017 · 6 comments

Comments

@siddharthkp
Copy link

I tried to do this, but failed.

Something like this:

  plugins: [
    ['module-resolver', { alias: { react: 'preact-compat' } }]
  ]

Any npm module (not just my code) that uses react, should get preact-compat.

Is this something that is possible?

@fatfisz
Copy link
Contributor

fatfisz commented Jun 5, 2017

Hi @siddharthkp, this would be possible (although not without problems) if you applied the transform to the files inside node_modules. Usually node_modules are ignored.

Maybe you could manually add a "react" package to node_modules that would export preact-compat?

@siddharthkp
Copy link
Author

if you applied the transform to the files inside node_modules

How can I do that?

Maybe you could manually add a "react" package to node_modules that would export preact-compat?

This will work, probably my last option, if nothing else works

@fatfisz
Copy link
Contributor

fatfisz commented Jun 5, 2017

How can I do that?

It depends on the tool that you use to apply babel transforms. For example, in Webpack and Rollup just don't add node_modules to the "exclude" config.

@siddharthkp
Copy link
Author

I am using babel-register

@siddharthkp
Copy link
Author

Thanks! This is helpful 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants