How to use remote/ipc when using gulp and ES6 modules


#1

i am using ES6 js files that are then compiled by gulp (browserify/babel), example of a ES6 file is:

I have a normal App.js that is used to set up the main window etc… Then the html pages will use a main.min.js file that is basically made up with all my ES6 classes compiled into one file:

loader.es6 file

import Main from  './pages/Main.es6'

new Main()

Main.es6 file


import Vue from 'vue';

export default class Main extends Vue{
  constructor() {...}
  .....
}

When compiled and run this all works fine and all is good… But as i thought if i want to implement the ‘IPC’, ‘Remote’ modules, i am having issues with compiling as they cannot find those modules, either through the require() or import..methods within my classes.

so doing the folliwing fails:

 import Remote from 'remote'
 import Main from  './pages/Main.es6'

new Main()

or

 var Remote = require('remote')
 import Main from  './pages/Main.es6'

 new Main()

Is this possible to do or achieve, or nope needs more thought and going back to normal js please.

My repo of it so far can be view here

Any ideas / advice would be great thanks


#2

I managed to look into this and through some tests, have sorted a way me thinks, the solution can be viewed HERE but will also add below:

Well been playing and I have managed to get this to work in a way:

Basically i set the remote and ipc modules within the html page, then pass in those, into my class for that page.

main.html

     <script>
       var remote = require('remote');
       var ipc = require('ipc');
       new Main(ipc);
     </script>

Main.js - Class File

     export default class Main extends Vue{
      constructor(ipc) {
       ....
       ipc.send('listener here','message here');
  
       .....

The files can be viewed within this Branch: