vue-cli-plugin-electron-builder
vue-cli-plugin-electron-builder copied to clipboard
load dynamic image file from public folder after build
I am using this plugin for a long time.. currently i facing issue for loading dynamic image file from public path after build.
try to use this
files in public
folder, use src='local-media://test.png'
// in background.js
function registerLocalMediaProtocol() {
protocol.registerFileProtocol('local-media', (request, callback) => {
const url = request.url.replace(/^local-media:\/\//, '')
// Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
const decodedUrl = decodeURI(url) // Needed in case URL contains spaces
try {
return callback(path.join(__static, decodedUrl))
} catch (error) {
console.error(
'ERROR: registerLocalMediaProtocol: Could not get file path:',
error
)
}
})
}
app.on('ready', async () => {
// ...
registerLocalMediaProtocol()
// ...
}