在使用 vue-cli-plugin-electron-builder
打包後發現應用程式沒有執行preload.js檔案于是查找原因
根據查閱的資料打包後的源檔案放在
\dist_electron\win-unpacked\resources\app.asar
, app.asar
是一個壓縮檔案需要解壓才能看到裡面的内容 npm install -g asar
/**
cd到app.asar所在的目錄,将檔案解壓到file檔案夾
**/
asar extract ./app.asar ./file
沒有發現
preload.js
解決方案
在
vue.config.js
中如下配置
module.exports = {
pluginOptions:{
electronBuilder:{
preload:'src/preload.js'
}
}
}
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webviewTag: true,
preload: path.join(__dirname, '/preload.js')
},
resizable: false,
frame: false
});