「Electron/インストール」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→インストール) |
(→インストール) |
||
| 行18: | 行18: | ||
<pre> | <pre> | ||
touch index.js | touch index.js | ||
| + | </pre> | ||
| + | |||
| + | ==サンプル== | ||
| + | index.js | ||
| + | <pre> | ||
| + | const { app, BrowserWindow } = require('electron') | ||
| + | |||
| + | const createWindow = () => { | ||
| + | const win = new BrowserWindow({ | ||
| + | width: 800, | ||
| + | height: 600 | ||
| + | }) | ||
| + | |||
| + | win.loadFile('index.html') | ||
| + | } | ||
| + | app.whenReady().then(() => { | ||
| + | createWindow() | ||
| + | }) | ||
| + | </pre> | ||
| + | index.html | ||
| + | <pre> | ||
| + | <!DOCTYPE html> | ||
| + | <html> | ||
| + | <head> | ||
| + | <meta charset="UTF-8"> | ||
| + | <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | ||
| + | <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | ||
| + | <title>Hello World!</title> | ||
| + | </head> | ||
| + | <body> | ||
| + | <h1>Hello World!</h1> | ||
| + | We are using Node.js <span id="node-version"></span>, | ||
| + | Chromium <span id="chrome-version"></span>, | ||
| + | and Electron <span id="electron-version"></span>. | ||
| + | </body> | ||
| + | </html> | ||
</pre> | </pre> | ||
2023年12月21日 (木) 12:15時点における版
インストール
公式:https://www.electronjs.org/ja/docs/latest/tutorial/quick-start
mkdir my-electron-app && cd my-electron-app npm init npm install --save-dev electron
package.json に"start": "electron ." を追加
{
"scripts": {
"start": "electron ."
}
}
空のindex.jsを追加
touch index.js
サンプル
index.js
const { app, BrowserWindow } = require('electron')
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600
})
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
})
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
</body>
</html>
