Unable to load preload script even I follow the manual,I think it's a bug but not pretty sure · Issue #1588 · nklayman/vue-cli-plugin-electron-builder
Format: markdownScore: 0Link: https://github.com
Unable to load preload script even I followed the manual:https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#preload-files ,
I also tried many way I searched from github issuess to resovle the problem . none of them works and I don't have any other way now . I think it maybe a bug but not pretty sure
I upload all the code to repo for the convenience of regenerate the problem.
https://github.com/codeh2o/electronVuePreloadIssue
Here is some snapshot:
// vue.config.js
module.exports = {
transpileDependencies: ['vuetify'],
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
builderOptions: {
// Add also your database location
extraResources: ['src', 'src/res/'],
preload: 'src/preload.js',
},
// This line: add knex and sqlite3
externals: ['knex', 'sqlite3'],
},
},
};
//background.js
async function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname,'preload.js'),
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION
},
});
win.maximize();
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol('app');
// Load the index.html when not in development
win.loadURL('app://./index.html');
}
}