I'm trying to integrate Neutralinojs with Vite to improve my dev workflow and use HMR. How should I configure the setup for HMR to function properly? I've tried both in macOS and Windows without luck.
I’ve followed the Neutralinojs docs. I've succeeded to use assets written to disk by using Vite's watch mode (vite build --watch). However, this causes a full refresh of the application.
I start the development servers in two separate terminals with the following commands:
vitenpx @neutralinojs/neu run -- --frontend-lib-dev --window-enable-inspector
Below are my configuration files.
vite.config.js
export default defineConfig({
build: {
outDir: "dist",
emptyOutDir: false
},
server: {
port: 3000
}
});
neutralino.config.json
{
"applicationId": "js.neutralino.zero",
"version": "1.0.0",
"defaultMode": "window",
"port": 0,
"documentRoot": "/dist/",
"url": "/",
"enableServer": true,
"enableNativeAPI": true,
"exportAuthInfo": true,
"nativeAllowList": [
"app.*"
],
"modes": {
"window": {
"title": "neu-vite",
"width": 800,
"height": 500,
"minWidth": 400,
"minHeight": 200,
"icon": "/public/appIcon.png"
}
},
"cli": {
"binaryName": "neu-vite",
"resourcesPath": "/dist/",
"extensionsPath": "/extensions/",
"clientLibrary": "/public/neutralino.js",
"binaryVersion": "4.12.0",
"clientVersion": "3.10.0",
"frontendLibrary": {
"patchFile": "/index.html",
"devUrl": "http://localhost:3000"
}
}
}

Since
@neutralinojs/neuversion 10 it is possible to definde commands to start a dev server and to build the frontend app which are executed beforeneu runandneu build.First, set a fixed port to your dev server in your vite config:
In the
clisection of yourneutralino.config.json, make sure there is noclientLibrary. You shouldn't needextensionsPatheither.Make sure there is a section
frontendLibrarythat points to yourindex.htmland the URL of your dev server.Then you just need to run
npx @neutralinojs/neu run, wich starts both, vite live server and neutralino.However, there are some pitfalls:
The vue dev server is started first. When your defaultMode is "browser", this opens your browser but the neutralino dev lib is not provided at this time. You might have to refresh the page after neutralino is started.
Also, building the app with
neu buildand having theindex.htmlpatched will prevent vue from loading in a production build. Just make sureindex.htmlis not patched before build.