Windows that need no html files to run
Electron's BrowserWindow component is a powerful tool for displaying html content. Problem is, it's not always html content which we want to display; sometimes we want to manipulate our DOM solely with javascript, especially using frameworks such as react.
Instead of having to create hosting html files, either through webpack or manually, ElectronScriptWindow can display a pure javascript source, hosted inside its own dom.
Using npm:
$ npm install electron-script-window
Using yarn:
$ yarn add electron-script-window
ScriptWindow(...)- instantiates a BrowserWindow with the passed args.ScriptWindow.loadUrl(...)- works exactly as BrowserWindow.loadUrl works, only here you should use a javascript file instead (relative path works).ScriptWindow.browserWindow- the BrowserWindow instance.
ScriptWindow generates a basically clean DOM environment for your script to run in. The generated HTML body contains a single div element called "root", that is so react apps could hook right into it.
The script itself is being loaded after the body was created, so there's no need to asynchronously wait for it.
In your main script file:
let win = new ScriptWindow({title: 'Script Window!'});
win.browserWindow.maximize();
win.loadURL('./windows/main/index.js');This project is MIT licensed. Do whatever you want with it.