You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/electron.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,3 +37,27 @@ so that `node-llama-cpp` can find them.
37
37
Cross packaging from one platform to another is not supported, since binaries for other platforms are not downloaded to you machine when your run `npm install`.
38
38
39
39
Packaging an `arm64` app on an `x64` machine is supported, but packaging an `x64` app on an `arm64` machine is not.
40
+
41
+
## Bundling
42
+
When bundling your code for Electron using [Electron Vite](https://electron-vite.org) or Webpack,
43
+
ensure that `node-llama-cpp` is not bundled, and is instead treated as an external module.
44
+
45
+
Marking `node-llama-cpp` as an external module will prevent its code from being bundled with your application code,
46
+
and instead, it'll be loaded from the `node_modules` directory at runtime (which should be packed into a `.asar` archive).
47
+
48
+
The file structure of `node-llama-cpp` is crucial for it to function correctly,
49
+
so bundling it will break its functionality.
50
+
Moreover, since `node-llama-cpp` includes prebuilt binaries (and also local builds from source),
51
+
those files must be retained in their original structure for it to work.
52
+
53
+
Electron has [its own bundling solution called ASAR](https://www.electronjs.org/docs/latest/tutorial/asar-archives) that is designed to work with node modules.
54
+
ASAR retains the original file structure of node modules by packing all the files into a single `.asar` archive file that Electron will read from at runtime like it would from the file system.
55
+
This method ensures node modules work as intended in Electron applications, even though they are bundled into a single file.
56
+
57
+
Using ASAR is the recommended way to bundle `node-llama-cpp` in your Electron app.
58
+
59
+
If you're using the scaffolded Electron app, this is already taken care of.
60
+
61
+
::: tip NOTE
62
+
We recommend using [Electron Vite](https://electron-vite.org) over Webpack for your Electron app due to to Vite's speed and Webpack's lack of proper ESM support in the output bundle, which complicates the bundling process.
0 commit comments