electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 97 forks source link

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

Closed ttraenkler closed 7 years ago

ttraenkler commented 7 years ago

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!

MarshallOfSound commented 7 years ago

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 commented 7 years ago

Thanks for the hint!

karlitos commented 5 years ago

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 ?