electron-sveltekit icon indicating copy to clipboard operation
electron-sveltekit copied to clipboard

How to run with adapter-node?

Open mattpilott opened this issue 3 years ago • 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!

mattpilott avatar Nov 08 '21 00:11 mattpilott

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!

Dax89 avatar Nov 08 '21 21:11 Dax89

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"
}

mattpilott avatar Nov 09 '21 15:11 mattpilott

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

Dax89 avatar Nov 13 '21 14:11 Dax89

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)

mattpilott avatar Nov 23 '21 21:11 mattpilott

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.

vishalbalaji avatar Dec 04 '22 17:12 vishalbalaji