Electron으로 Hello World를 출력해보자.

박선우·2022년 11월 9일
0

Node.js

목록 보기
2/3

D:\node.js\ELECTRON\helloworld>npm install -g electron

package.json 파일 생성

{
    "name" : "hello-world",
    "version" : "1.0.0",
    "main" : "main.js",
    "scripts" : {
        "start" : "electron ."
    }
}

main.js 생성

const {app, BrowserWindow} = require('electron');

function createWindow(){
    let win = new BrowserWindow({
        width : 800,
        height : 600,
        webPreference : {
            NodeIntegration : true
        }
    })
        
    win.loadFile('./index.html');
}

app.on('ready', createWindow);

index.html 작성

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello Electron</title>
    <style>
        body{
            background-image: linear-gradient(45deg, #EAD790 0%, #EF8C53 100%);
            text-align: center;
        }
        button{
            background: rgba(0,0,0,0.40);
            box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.5);
            border-radius: 8px;
            color: lime;
            padding: 1em 2em;
            border: none;
            font-family: 'Roboto', sans-serif;
            font-weight: 300;
            font-size: 20pt;
            position: relative;
            top: 40%;
            cursor: pointer;
            outline: none;
        }
        button:hover{
            background: rgba(0,0,0,0.3);
        }        
    </style>
    <link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet" type="text/css"/>
</head>
<body>
    <script>
        function sayHello(){
            alert("hello Electron");
        }
    </script>
    <button onclick="sayHello()">sayHello</button>
</body>
</html>

D:\node.js\ELECTRON\helloworld>npm start

profile
한 줄, 한 줄

0개의 댓글