Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

How to create an alias for a NPM package? #205

Closed
ttraenkler opened this issue Mar 14, 2017 · 3 comments
Closed

How to create an alias for a NPM package? #205

ttraenkler opened this issue Mar 14, 2017 · 3 comments

Comments

@ttraenkler
Copy link

ttraenkler commented Mar 14, 2017

For my project, I need to create an alias called react-native that resolves to react-native-web. This is usually done in the webpack configuration - how is this possible with electron-compile?

Thanks for your efforts put into electron-compile!

@ttraenkler ttraenkler changed the title How do I create an alias for a NPM package with electron-compile? How to create an alias for a NPM package? Mar 14, 2017
@MarshallOfSound
Copy link
Member

This is not something that electron-compile should be doing.

You can do this in many ways in a node environment.

There is a module to do it for you: https://www.npmjs.com/package/module-alias

Or you can set it up as part of your babel config in your .compilerc: https://www.npmjs.com/package/babel-plugin-module-alias

@ttraenkler
Copy link
Author

Thanks for the hint!

@karlitos
Copy link

Hi, I do not want to open extra ticket, but I think, that the proposed solution will not work in case I need to create an alias of npm package A to npm package B for the development environment.

Background: I am trying to get the react-dom - hot-loader edition working, but I am still facing the infamous warning message.

Basically I need to alias "react-dom" to "@hot-loader/react-dom", so I updated my .compilerc as follows:

{
  "env": {
    "development": {
      "application/javascript": {
        "presets": [
          ["env", { "targets": { "electron": "1.6.0" } }],
          "react"
        ],
        "plugins": ["transform-async-to-generator", "transform-es2015-classes", "react-hot-loader/babel",
        ["module-resolver", {
              "alias": {
                 "react-dom": "@hot-loader/react-dom"
              }
            }]
        ],
...

Sadly this did not help. Then I found following issue stating:

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?

Might this be a reason, the alias is not working as expected ? What can I do about this ?

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

No branches or pull requests

3 participants