electron-compile
electron-compile copied to clipboard
using electron-compile and a forked child node process, passing parameters to compiled js
I have a system that works perfectly with "compiled" javascript code, as done by electron-forge. It does exactly what I need.
Then I needed to fork a new process. This means I can't just point it to the javascript file that I want to run, because that's compiled and in the .cache directory. I can't just re-launch es6-shim.js, because that is hardcoded to launch the application in package.json. I've resorted to copying in the raw js files, which kinda defeats the purpose of pre-compiling
How can I accomplish this? I've launching the child process with script:
const electronCompile = require('electron-compile');
const c = electronCompile.init(__dirname, 'child.js');
but c is undefined and I can't use it as I would a require-d object. I can't figure out how to pass parameters into the newly minted process and call a js file that has been pre-compiled.
Any ideas?
Seems to me like it's as easy as changing
require.main.require(mainModule);
to
return require.main.require(mainModule);
in init()
Also, for the sake of the internet, you can work around this by putting a pointer into the main module from within child.js:
require.main.server = exports;
Then in the script which calls electronCompile.init(), just use require.main.server to pass in parameters to the compiled object.