├── .gitignore ├── README.md ├── .yarnclean ├── src ├── renderer │ └── index.js └── main │ └── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist/ 3 | node_modules/ 4 | thumbs.db 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # electron-webpack-quick-start 2 | > [`electron-webpack`] + [`electron-builer`]的客户端打包demo 3 | 4 | ### Scripts 5 | 6 | ```bash 7 | # run application in development mode 8 | yarn dev 9 | 10 | # compile source code and create webpack output 11 | yarn compile 12 | 13 | # `yarn compile` & create build ia32 with electron-builder 14 | yarn build 15 | 16 | # `yarn compile` & create unpacked build with electron-builder 17 | yarn build:dir 18 | ``` 19 | -------------------------------------------------------------------------------- /.yarnclean: -------------------------------------------------------------------------------- 1 | # test directories 2 | __tests__ 3 | node_modules/*/test 4 | node_modules/*/tests 5 | powered-test 6 | 7 | # asset directories 8 | docs 9 | doc 10 | website 11 | images 12 | 13 | # examples 14 | example 15 | examples 16 | 17 | # code coverage directories 18 | coverage 19 | .nyc_output 20 | 21 | # build scripts 22 | Makefile 23 | Gulpfile.js 24 | Gruntfile.js 25 | 26 | # configs 27 | .tern-project 28 | .gitattributes 29 | .editorconfig 30 | .*ignore 31 | .eslintrc 32 | .jshintrc 33 | .flowconfig 34 | .documentup.json 35 | .yarn-metadata.json 36 | 37 | # misc 38 | *.gz 39 | *.md 40 | -------------------------------------------------------------------------------- /src/renderer/index.js: -------------------------------------------------------------------------------- 1 | // Initial welcome page. Delete the following line to remove it. 2 | 'use strict';const styles=document.createElement('style');styles.innerText=`@import url(https://unpkg.com/spectre.css/dist/spectre.min.css);.empty{display:flex;flex-direction:column;justify-content:center;height:100vh;position:relative}.footer{bottom:0;font-size:13px;left:50%;opacity:.9;position:absolute;transform:translateX(-50%);width:100%}`;const vueScript=document.createElement('script');vueScript.setAttribute('type','text/javascript'),vueScript.setAttribute('src','https://unpkg.com/vue'),vueScript.onload=init,document.head.appendChild(vueScript),document.head.appendChild(styles);function init(){Vue.config.devtools=false,Vue.config.productionTip=false,new Vue({data:{versions:{electron:process.versions.electron,electronWebpack:require('electron-webpack/package.json').version}},methods:{open(b){require('electron').shell.openExternal(b)}},template:`

Welcome to your new project!

Get started now and take advantage of the great documentation at hand.


`}).$mount('#app')} 3 | -------------------------------------------------------------------------------- /src/main/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | import { app, BrowserWindow } from 'electron' 4 | import * as path from 'path' 5 | import { format as formatUrl } from 'url' 6 | 7 | const isDevelopment = process.env.NODE_ENV !== 'production' 8 | 9 | // global reference to mainWindow (necessary to prevent window from being garbage collected) 10 | let mainWindow 11 | 12 | function createMainWindow() { 13 | const window = new BrowserWindow() 14 | 15 | if (isDevelopment) { 16 | window.webContents.openDevTools() 17 | } 18 | 19 | if (isDevelopment) { 20 | window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`) 21 | } 22 | else { 23 | window.loadURL(formatUrl({ 24 | pathname: path.join(__dirname, 'index.html'), 25 | protocol: 'file', 26 | slashes: true 27 | })) 28 | } 29 | 30 | window.on('closed', () => { 31 | mainWindow = null 32 | }) 33 | 34 | window.webContents.on('devtools-opened', () => { 35 | window.focus() 36 | setImmediate(() => { 37 | window.focus() 38 | }) 39 | }) 40 | 41 | return window 42 | } 43 | 44 | // quit application when all windows are closed 45 | app.on('window-all-closed', () => { 46 | // on macOS it is common for applications to stay open until the user explicitly quits 47 | if (process.platform !== 'darwin') { 48 | app.quit() 49 | } 50 | }) 51 | 52 | app.on('activate', () => { 53 | // on macOS it is common to re-create a window even after all windows have been closed 54 | if (mainWindow === null) { 55 | mainWindow = createMainWindow() 56 | } 57 | }) 58 | 59 | // create main BrowserWindow when electron is ready 60 | app.on('ready', () => { 61 | mainWindow = createMainWindow() 62 | }) 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-builder-start", 3 | "version": "1.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "dev": "electron-webpack dev", 7 | "compile": "electron-webpack", 8 | "build": "yarn compile && electron-builder", 9 | "build:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null" 10 | }, 11 | "dependencies": { 12 | "source-map-support": "^0.5.9" 13 | }, 14 | "build": { 15 | "productName": "electron-builder-start", 16 | "appId": "org.simulatedgreg.electron-builder-start", 17 | "directories": { 18 | "output": "dist" 19 | }, 20 | "files": [ 21 | "dist/electron/**/*", 22 | "node_modules/", 23 | "package.json" 24 | ], 25 | "nsis": { 26 | "oneClick": false, 27 | "allowElevation": true, 28 | "allowToChangeInstallationDirectory": true, 29 | "installerIcon": "build/icons/icon.ico", 30 | "uninstallerIcon": "build/icons/icon.ico", 31 | "installerHeaderIcon": "build/icons/icon.ico", 32 | "createDesktopShortcut": true, 33 | "createStartMenuShortcut": true, 34 | "shortcutName": "electron-builder-start", 35 | "include": "build/script/installer.nsh" 36 | }, 37 | "dmg": { 38 | "contents": [ 39 | { 40 | "x": 410, 41 | "y": 150, 42 | "type": "link", 43 | "path": "/Applications" 44 | }, 45 | { 46 | "x": 130, 47 | "y": 150, 48 | "type": "file" 49 | } 50 | ] 51 | }, 52 | "mac": { 53 | "icon": "build/icons/icon.icns" 54 | }, 55 | "win": { 56 | "icon": "build/icons/icon.ico", 57 | "target": [ 58 | { 59 | "target": "nsis", 60 | "arch": [ 61 | "ia32" 62 | ] 63 | } 64 | ] 65 | }, 66 | "linux": { 67 | "icon": "build/icons" 68 | } 69 | }, 70 | "devDependencies": { 71 | "electron": "2.0.7", 72 | "electron-builder": "^20.28.1", 73 | "electron-webpack": "^2.1.2", 74 | "webpack": "^4.16.5" 75 | }, 76 | "resolutions": { 77 | "upath": "^1.0.5" 78 | } 79 | } 80 | --------------------------------------------------------------------------------