Dax89/electron-sveltekit

Update to latest SvelteKit

DogFoxX opened this issue · 6 comments

Anyway we can get updated code to use the latest SvelteKit?

Dax89 commented

Yep, I will check this week

Dax89 commented

I have tried to migrate to the new folder based routing system, there are some issues when I use the adapter-static: basically it doesn't navigate to page1, page2 and page3.

There are no errors, it just display the homepage again and again. It works fine with the adapter-node.

I will investigate more

PS:
If I replace in this file href="/pageN" with goto("/pageN") it works fine.

It's working for me. I started a brand new skeleton sveltekit project and used some of your code to implement it into electron using adapter-static. When I'm done I will upload my repo and you can have a look.
The first issue I fount was to change the electron script in package.json to electron . instead of electron src/electron.cjs.
My scripts:

"scripts": {
  "dev": "cross-env NODE_ENV=dev npm run dev:all",
  "dev:all": "concurrently -p \"[{time}] [{name}]\" -t \"HH:mm:ss\" -n svelte,electron -c #FD6937,#07B6D5 -s all \"npm run dev:svelte\" \"electron .\"",
  "dev:svelte": "vite dev --host --port 3000",
  "build": "cross-env NODE_ENV=production npm run build:svelte && npm run build:electron",
  "build:svelte": "vite build",
  "build:electron": "electron-builder build --win --publish never",
  "postinstall": "svelte-kit sync"
},

Just start with npm run dev.
I don't recall if this was the only thing, but folder based routing is working for me in development and after building.

Dax89 commented

Yep it works with npm run dev.
The issue is when the application is packaged with npm run package and I try the bundled electron one

Try my scripts and see if it'll work. Like I said, mine works in development and packaged.

Create a file called electron-builder.json in the root of your project and add this:

{
  "appId": "com.example.app",
  "icon": "./resources/icon.ico",
  "nsis": {
    "artifactName": "${name}-setup-${version}.${ext}",
    "createStartMenuShortcut": "true",
    "deleteAppDataOnUninstall": "true",
    "uninstallDisplayName": "${productName}"
  },
  "directories": {
    "output": "dist"
  },
  "files": [
    "electron/electron.cjs",
    "electron/preload.cjs",
      {
        "from": "build",
	"to": ""
      }
  ],
  "publish": {
    "provider": "github",
    "token": "<token>"
  }
}

Note that I put my electron.cjs and preload.cjs in a folder called electron in the root of my project. Just point to correct path in files.

and edit your scripts in package.json:

"scripts": {
  "dev": "cross-env NODE_ENV=dev npm run dev:all",
  "dev:all": "concurrently -p \"[{time}] [{name}]\" -t \"HH:mm:ss\" -n svelte,electron -c #FD6937,#07B6D5 -s all \"npm run dev:svelte\" \"electron .\"",
  "dev:svelte": "vite dev --host --port 3000",
  "build": "cross-env NODE_ENV=production npm run build:svelte && npm run build:electron",
  "build:svelte": "vite build",
  "build:electron": "electron-builder build --win --publish never",
  "postinstall": "svelte-kit sync"
},

If you're not going to deploy your app and not make use of electron-updater, you can remove the publish section in electron-builder.json and remove --publish never flag from the build:electron script

I uploaded my project here:
https://github.com/DogFoxX/electron-sveltekit-tailwind

Still need to refine the Reame lol