I've been working on a Svelte 3 + Electron 12.0.5 project. I am using the svelte-spa-router package for hash routing. My project structure looks like this:
node_modules/
public/
build/
bundle.css
bundle.js
index.html
src/
Components/
Pages/
Home.svelte
Settings.svelte
...
Sidebar.svelte
Titlebar.svelte
App.js
App.svelte
...
index.js // <-- Electron entry point
rollup|svelte|tailwind // <-- config files
Since I was using a router, electron's window.loadFile() was not working; To solve this, I used the sirv-cli along with concurrently. Now my start script looks like this:
"start": "concurrently \"sirv public --no-clear --port=40072\" \"electron .\""
Now I used window.loadURL("https://localhost:40072") to get this working. .svelte files, inside the <script> tags, I tried to do import * as electron from "electron"; but that resulted in a error saying fs is not defined. So for now, I created an express server inside index.js and am using using fetch to make POST request to the server and do the stuffs which I could've easily done using ipcMain and ipcRenderer...I don't know if I am doing anything wrong (nodeIntegration is already set to true). I'm kinda new to Svelte so do anyone know of any other way to use electron methods inside the script tags?