├── .gitignore ├── README.md ├── babel.config.js ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── background.js ├── components │ └── HelloWorld.vue ├── main.js └── subpage │ └── main.js ├── vue.config.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | 23 | #Electron-builder output 24 | /dist_electron -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Electron Multipage Example 2 | 3 | > A demo repository for adding multiple pages and windows to your [Vue CLI Plugin Electron Builder](https://nklayman.github.io/vue-cli-plugin-electron-builder/) App 4 | 5 | [Instructions on Vue CLI Plugin Electron Builder Docs](https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#multiple-pages) 6 | 7 | ## Project setup 8 | 9 | ``` 10 | yarn install 11 | ``` 12 | 13 | ### Start Electron development server 14 | 15 | ``` 16 | yarn electron:serve 17 | ``` 18 | 19 | ### Build Electron app for distribution 20 | 21 | ``` 22 | yarn electron:build 23 | ``` 24 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-multipage-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "electron:build": "vue-cli-service electron:build", 10 | "electron:serve": "vue-cli-service electron:serve", 11 | "postinstall": "electron-builder install-app-deps", 12 | "postuninstall": "electron-builder install-app-deps" 13 | }, 14 | "dependencies": { 15 | "vue": "^2.6.6" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^4.4.0", 19 | "@vue/cli-plugin-eslint": "^4.4.0", 20 | "@vue/cli-service": "^4.4.0", 21 | "babel-eslint": "^10.0.1", 22 | "electron": "^9.0.0", 23 | "electron-devtools-installer": "^3.1.1", 24 | "eslint": "^7.1.0", 25 | "eslint-plugin-vue": "^6.0.0", 26 | "vue-cli-plugin-electron-builder": "^2.0.0-rc.1", 27 | "vue-template-compiler": "^2.5.21" 28 | }, 29 | "eslintConfig": { 30 | "root": true, 31 | "env": { 32 | "node": true 33 | }, 34 | "extends": [ 35 | "plugin:vue/essential", 36 | "eslint:recommended" 37 | ], 38 | "rules": {}, 39 | "parserOptions": { 40 | "parser": "babel-eslint" 41 | } 42 | }, 43 | "postcss": { 44 | "plugins": { 45 | "autoprefixer": {} 46 | } 47 | }, 48 | "browserslist": [ 49 | "> 1%", 50 | "last 2 versions", 51 | "not ie <= 8" 52 | ], 53 | "main": "background.js" 54 | } 55 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nklayman/electron-multipage-example/2f80ceafbdca5ff0a5490b83a9217c41a1012ebc/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Electron Multipage Example 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | 29 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nklayman/electron-multipage-example/2f80ceafbdca5ff0a5490b83a9217c41a1012ebc/src/assets/logo.png -------------------------------------------------------------------------------- /src/background.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | import { app, protocol, BrowserWindow } from 'electron' 4 | import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' 5 | import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer' 6 | const isDevelopment = process.env.NODE_ENV !== 'production' 7 | 8 | let win 9 | let secondWin 10 | // Standard scheme must be registered before the app is ready 11 | protocol.registerSchemesAsPrivileged([ 12 | { scheme: 'app', privileges: { secure: true, standard: true } } 13 | ]) 14 | function createWindow(devPath, prodPath) { 15 | // Create the browser window. 16 | const window = new BrowserWindow({ 17 | width: 800, 18 | height: 600, 19 | webPreferences: { 20 | // Use pluginOptions.nodeIntegration, leave this alone 21 | // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info 22 | nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION 23 | } 24 | }) 25 | 26 | if (process.env.WEBPACK_DEV_SERVER_URL) { 27 | // Load the url of the dev server if in development mode 28 | window.loadURL(process.env.WEBPACK_DEV_SERVER_URL + devPath) 29 | if (!process.env.IS_TEST) window.webContents.openDevTools() 30 | } else { 31 | // Load the index.html when not in development 32 | window.loadURL(`app://./${prodPath}`) 33 | } 34 | 35 | return window 36 | } 37 | 38 | // Quit when all windows are closed. 39 | app.on('window-all-closed', () => { 40 | // On macOS it is common for applications and their menu bar 41 | // to stay active until the user quits explicitly with Cmd + Q 42 | if (process.platform !== 'darwin') { 43 | app.quit() 44 | } 45 | }) 46 | 47 | app.on('activate', () => { 48 | // On macOS it's common to re-create a window in the app when the 49 | // dock icon is clicked and there are no other windows open. 50 | if (win.isDestroyed()) { 51 | win = createWindow('', 'index.html') 52 | } 53 | if (secondWin.isDestroyed()) { 54 | secondWin = createWindow('subpage', 'subpage.html') 55 | } 56 | }) 57 | 58 | // This method will be called when Electron has finished 59 | // initialization and is ready to create browser windows. 60 | // Some APIs can only be used after this event occurs. 61 | app.on('ready', async () => { 62 | if (isDevelopment && !process.env.IS_TEST) { 63 | // Install Vue Devtools 64 | try { 65 | await installExtension(VUEJS_DEVTOOLS) 66 | } catch (e) { 67 | console.error('Vue Devtools failed to install:', e.toString()) 68 | } 69 | } 70 | if (!process.env.WEBPACK_DEV_SERVER_URL) { 71 | createProtocol('app') 72 | } 73 | win = createWindow('', 'index.html') 74 | secondWin = createWindow('subpage', 'subpage.html') 75 | }) 76 | 77 | // Exit cleanly on request from parent process in development mode. 78 | if (isDevelopment) { 79 | if (process.platform === 'win32') { 80 | process.on('message', (data) => { 81 | if (data === 'graceful-exit') { 82 | app.quit() 83 | } 84 | }) 85 | } else { 86 | process.on('SIGTERM', () => { 87 | app.quit() 88 | }) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 41 | 42 | 43 | 59 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /src/subpage/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | Vue.config.productionTip = false 3 | 4 | new Vue({ 5 | render: h => h('div', 'Welcome to the second page!') 6 | }).$mount('#app') 7 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | pages: { 3 | index: 'src/main.js', 4 | subpage: 'src/subpage/main.js' 5 | } 6 | } 7 | --------------------------------------------------------------------------------