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

Letting users pick their favourite modules loading method #20

Closed
wants to merge 1 commit into from

Conversation

GiovanniFrigo
Copy link

Removing require.resolve from rendererRequireDirect allows users to load modules in different fashions:

  • webpack-packed modules (ie: ElectronRemote.requireTaskPool(require.resolve('electron-remote/remote-ajax'));)
  • absolute/relative files (ElectronRemote.requireTaskPool('../../../dist/electron/workers/uploadWorker');)
  • possibly other ways that don't come into my mind right now :)

See issue #19

@GiovanniFrigo GiovanniFrigo changed the title Letting users pick their favourite module-loading method Letting users pick their favourite modules loading method Apr 5, 2017
@anaisbetts
Copy link
Contributor

This is a breaking change, I think you should file a bug on webpack to make require.resolve work properly

@Revln9
Copy link

Revln9 commented Apr 16, 2017

Hi @paulcbetts , i think @GiovanniFrigo is right , you should really consider adapting this amazing module for webpack.

you can use https://github.com/chentsulin/electron-react-boilerplate to check since its the most famous boilerplate for electron and react (i use this too) .

And we are all willing to help too , i've just opened an issue at the boilerplate repository , maybe someone dealed with this problem before
electron-react-boilerplate/electron-react-boilerplate#918

@GiovanniFrigo i tried your solution but unfortunately this will bring another error with the message FILE_NOT_FOUND , so in my case , it didn't help.

thank you

@anaisbetts
Copy link
Contributor

I actually think that people shouldn't use Webpack with Electron, because it causes problems like this. Instead, you should use electron-forge with the React template (https://github.com/electron-userland/electron-forge-templates) - with less than 1/10th of the code, you'll still get HMR and a complete build and packaging system

@GiovanniFrigo
Copy link
Author

I hear you, this is a breaking change for people already using it. How about I add a method that allows creating a Task Pool from a raw file?
Eg: ElectronRemote.requireTaskPoolFromRawModule(..) with the same specs as above.
Would you accept a PR of this kind?

This way we wouldn't change anything for existing users, but still allow others (like me or @Revln9) to load modules in other ways.
I'd love to keep using this library, but we can't get rid of webpack as it is crucial to the project in some other parts. I have a fork of it right now, but this way we'd lose any future updates to it..

@Revln9
Copy link

Revln9 commented Apr 18, 2017

@GiovanniFrigo 👍 we should also add documentation for webpack users because i don't think its the only change needed to get this module work with webpack .

If you pack your app in an asar file , the module will fail to find the dummy html used to load scripts at the hidden window. now i don't know if its specific to my config but i'm using a pretty well known boilerplate for electron , so i guess i'm not alone.

@GiovanniFrigo
Copy link
Author

@paulcbetts Thoughts on my latest comment?

@GiovanniFrigo
Copy link
Author

@paulcbetts don't mean to nag you, but could you please just tell me if you'd consider a PR allowing for the raw module loading, as described above? That makes an huge difference for me in whether we can use this library or not :/

Again that would be an alternative method of loading modules, not changing the current one.

@alexcroox
Copy link

+1 for webpack support, it's incredibly popular these days

@eranimo
Copy link

eranimo commented Sep 24, 2017

Is there a fork of electron-remote that works with webpack?

@Revln9
Copy link

Revln9 commented Sep 26, 2017

Got it working somehow after endless trials , but it's not guaranteed that this will work for you ,
here's how ;

replace this

let preloadFile = path.join(__dirname, 'renderer-require-preload.html');
bw.loadURL(`file:///${preloadFile}?module=${encodeURIComponent(fullPath)}`);
await ready;

with this

let preloadFile
   if (process.env.NODE_ENV === 'development') {
    preloadFile = _path2.default.join( __dirname , './renderer-require-preload.html');
   }
   if (process.env.NODE_ENV === 'production') {
   preloadFile = _path2.default.join( __dirname , './node_modules/electron-remote/lib/renderer-require-
   preload.html');
   }

let loadFile = 'file://' + preloadFile  + '?module=' + encodeURIComponent(fullPath)
bw.loadURL(loadFile);
await ready; 

the if statement is an easy fix for the production deployment directory issue (not found).

Hope it helps.

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

Successfully merging this pull request may close these issues.

None yet

5 participants