Build
FAQ
Build with native module
- Sharp
- FFMpeg
Add to External
ts
export default defineNuxtConfig({
electron: {
build: [
{
// Main-Process entry file of the Electron App.
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
// external it for native
// and we should make dist-electron locate in asar root
external: ['sharp'],
},
},
resolve: {
alias: {
'~/': `${path.resolve(__dirname)}/`,
// @see https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/573
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
},
},
},
},
],
renderer: {
resolve: {
// needed
// esm 路径读取有问题
sharp: { type: 'cjs' },
},
},
}
})Sharp
Turns out there was some conflict between sharp and libvips version from brew (macOS). What worked for me was forcing sharp to re-install with the bundled libvips.
bash
brew uninstall vipsuuid v4
Use node:crypto, crypto.randomUUID instead of uuid.
LRU constructor is not a constructor (spritesmith)
semver in spritesmith is too old. lru-cache in semver is too old.
Patch it in ~/electron/lib/spritesmith.
pnpm
- 添加
extraResourcesfromnode_modules/pnpmtonode_modules/pnpm - 添加
singleArchFilesandx64ArchFilestomacconfig- 解决 pnpm
*.node打包问题
- 解决 pnpm
json
/**
* @see https://www.electron.build/configuration/configuration
*/
{
// ...
"extraResources": [
{
"from": "../node_modules/pnpm",
"to": "../node_modules/pnpm"
}
],
"mac": {
"artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
"target": {
"target": "default",
"arch": "universal"
},
"singleArchFiles": "**/*.node",
"x64ArchFiles": "**/*.node",
"mergeASARs": false
}
}