Dax89/electron-sveltekit

How to run with adapter-node?

mattpilott opened this issue · 5 comments

Hey, I added your electron setup to an app im working on and whilst it all works in dev it doesnt work when built.

Is there anything i need to change to get it working with adapter-node?

Thanks!

Dax89 commented

SvelteKit now asks to execute npm run preview command which was missing in package.json, I have added it and now looks fine on my side.

Let me know if it works!

Thanks for that Dax seem to have same/similar issue. Here's what i'm seeing:
Screenshot 2021-11-09 at 3 20 37 pm

Here's my package.json

{
  "name": "matter",
  "version": "0.0.1",
  "main": "src/electron.cjs",
  "scripts": {
    "dev": "svelte-kit dev",
    "build": "svelte-kit build",
    "preview": "svelte-kit preview",
    "start": "svelte-kit start",
    "electron": "concurrently --kill-others \"svelte-kit dev\" \"electron src/electron.cjs\"",
    "dev:package": "npm run build && electron-builder --config electron-builder.config.json --dir",
    "package": "npm run build && electron-builder --config electron-builder.config.json"
  },
  "dependencies": {
    "@neuekit/utils": "^2.0.0-alpha.16",
    "electron-serve": "^1.1.0",
    "electron-window-state": "^5.0.3"
  },
  "devDependencies": {
    "@neuekit/reboot": "^1.10.2",
    "@sveltejs/adapter-node": "^1.0.0-next.55",
    "@sveltejs/kit": "next",
    "concurrently": "^6.3.0",
    "electron": "^15.3.1",
    "electron-builder": "^22.13.1",
    "electron-reloader": "^1.2.1",
    "sass": "^1.43.4",
    "svelte": "^3.42.6",
    "svelte-preprocess": "^4.9.8",
    "twitter-api-v2": "^1.6.5"
  },
  "type": "module"
}
Dax89 commented

Did you have tried without custom packages? Just to make sure that electron and svelte works without issues

Ok fixed that issue but adapter-node does not work when you use npm run dev:package or npm run package even tried on this repo without any changes (apart from swapping the adapter in svelte config of course)

I know that this is an old issue, but I was also searching for such a solution and I came upon this.

I made a minimal configuration based on this repo, but with adapter-node. Basically, the built node app is bundled with the application and is started before the window is created. Instead of loading built static files, the electron app loads a URL. This is only a workaround and one caveat of it is that it starts the node app on localhost, which is also accessible through your browser, rather than being scoped to the Electron app. This is the behaviour I was hoping to achieve, but the same may not apply for you.

You can check it out here.