electron-reload & electron-reloader 설치
npm install electron-reload --save-dev
npm install electron-reloader --save-dev
main.js 부분에 아래 부분을 추가한다.
// If development environment
if (env === 'development') {
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
hardResetMethod: 'exit'
});
}
package.json 부분의 아래 start script 를 추가한다.
"scripts": {
"start": "set NODE_ENV=development&&electron ."
},
main.js 전체 코드
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
const env = process.env.NODE_ENV || 'development';
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
// If development environment
if (env === 'development') {
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
hardResetMethod: 'exit'
});
}
package.json 전체 코드
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "set NODE_ENV=development&&electron ."
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^13.1.4",
"electron-reload": "^1.5.0",
"electron-reloader": "^1.2.1"
}
}
'dev > 개인 프로젝트' 카테고리의 다른 글
go gin tutorial (0) | 2022.01.16 |
---|---|
golang - gin - backend 개발 (1) (0) | 2022.01.12 |
electron NJS-045 cannot load a node-oracledb binary (작성중) (0) | 2020.03.22 |
Electron Uncaught TypeError: Cannot read property 'fn' of undefined 에러 해결 (0) | 2020.03.01 |
electron-builder 사용하여 데스크톱 앱 배포하기 (0) | 2020.02.17 |