Open pilotkid opened 2 years ago
Inside your builder configuration add nodeIntegration
, externals
, and your nodeModulesPath
.
nodeIntegration: true,
externals: ['node-webcam'],
nodeModulesPath: ['node_modules'],
Then you can add a hook to onNodeModulesFile
to rewrite app.asar
to app.asar.unpacked
//Apply patch to fix electron-builder issue
onNodeModuleFile(file) {
if (!file.includes('node-webcam')) return;
if (file.includes('\\node-webcam\\src\\webcams\\WindowsWebcam.js')) {
let str = fs.readFileSync(file, 'utf-8');
str = str.replace(
'WindowsWebcam.prototype.generateSh',
`WindowsWebcam.prototype.bin = WindowsWebcam.prototype.bin.includes('.asar.unpacked') ? WindowsWebcam.prototype.bin : WindowsWebcam.prototype.bin.replace('app.asar', 'app.asar.unpacked').replace(/.unpacked.unpacked/g, '.unpacked');\r\nWindowsWebcam.prototype.generateSh`
);
fs.writeFileSync(file, str, 'utf-8');
console.log(
'✔️Applied patch to node-webcam file ""./node_modules/src/webcams/WindowsWebcam.js'
);
}
}
All put together (in my case in vue.config.js
):
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
externals: ['pdf-to-printer', 'node-webcam'],
nodeModulesPath: ['node_modules'],
builderOptions: {
//Apply patch to fix electron-builder issue
onNodeModuleFile(file) {
if (!file.includes('node-webcam')) return;
if (file.includes('\\node-webcam\\src\\webcams\\WindowsWebcam.js')) {
let str = fs.readFileSync(file, 'utf-8');
str = str.replace(
'WindowsWebcam.prototype.generateSh',
`WindowsWebcam.prototype.bin = WindowsWebcam.prototype.bin.includes('.asar.unpacked') ? WindowsWebcam.prototype.bin : WindowsWebcam.prototype.bin.replace('app.asar', 'app.asar.unpacked').replace(/.unpacked.unpacked/g, '.unpacked');\r\nWindowsWebcam.prototype.generateSh`
);
fs.writeFileSync(file, str, 'utf-8');
console.log(
'✔️Applied patch to node-webcam file "./node_modules/src/webcams/WindowsWebcam.js"'
);
}
}
}
}
}
Created in Q/A style incase anyone else runs across this issue
On windows, after packaged with electron builder I get the error