neutralinojs / neutralinojs

Portable and lightweight cross-platform desktop application development framework
https://neutralino.js.org
Other
7.28k stars 357 forks source link

Compatibility with SvelteKit #1200

Open jerrygreen opened 3 months ago

jerrygreen commented 3 months ago

Is your feature request related to a problem? Please describe. Is there compatibility with SvelteKit? I found these instructions on Stackoverflow but it seems outdated:

Instructions look cool except they don't work: they seem to be for Svelte not SvelteKit.

Describe the solution you'd like I'd like to have some info in docs how to run Neutralino with the SvelteKit sample app.

Describe alternatives you've considered I tried to figure out how to merge both of them, but it's seems untrivial since I'm new with Neutralino. I happen to make SvelteKit work with Electron but this ain't helping to figure out Neutralino.

jerrygreen commented 3 months ago

After a few hours tinkering, I figured out how to:

  1. Make it work for dev environment where the loading url is vite server like http://localhost:5173/
  2. Make it work for production, bundling everything into statics and accesing it through locally placed index.html

It required a lot of tricks, like most notable one from this comment https://github.com/neutralinojs/neutralinojs/issues/909#issuecomment-1140673876:

import authInfo from '../.tmp/auth_info.json'
if (import.meta.env.DEV) {
  const {accessToken, port} = authInfo
  window.NL_PORT = port
  window.NL_TOKEN = accessToken
  window.NL_ARGS = [
    'bin\\neutralino-win_x64.exe',
    '',
    '--load-dir-res',
    '--path=.',
    '--export-auth-info',
    '--neu-dev-extension',
    '--neu-dev-auto-reload',
    '--window-enable-inspector'
  ]
}
window.Neutralino.init()

Because by some reason, global variables aren't set in use-cases like using SvelteKit.

It kinda works now but I have to figure out how to separate these two things, development environment and production. Of course, I could manually change url inside neutralino.config.json but it's not practical.

neu cli doesn't let me override these settings, though I figured I could use the binaries directly like described here in docs:

But when I try to run neutralino-win_x64.exe (I'm on windows), with --config-file, I'm getting this error:

neutralino-dev.config.json file is missing or corrupted.

But it's not missing nor corrupted. It's an exact copy of neutralino.config.dev – which completely fine and works with neu but when I use the binaries directly, it doesn't work. Issue that seems to be around a few years here, unfortunately:

A little help from maintainers would be appreciated. How to communicate different version of config to neu cli or to neutralino binaries, properly?