Skip to content

Commit f0c630d

Browse files
committed
docs: mention the need to treat node-llama-cpp as an external module in Electron
1 parent e5bae5e commit f0c630d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/guide/electron.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,27 @@ so that `node-llama-cpp` can find them.
3737
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`.
3838

3939
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.
63+
:::

0 commit comments

Comments
 (0)