Node.jsインストール完了後に実行すること
作業フォルダの作成
コマンドプロンプト起動 Win+Rで「cmd」
デスクトップにelectron_appフォルダを作成し、移動
cd desktop
mkdir electron_app
cd electron_app
Electronパッケージをダウンロード
npm install --save-dev electron
アプリの設定ファイルを作成
npm init -y
package.json修正
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
↓
"scripts": {
"start": "electron ."
},
アプリに必要なファイル
Electronのアプリは最低でも1つのHTMLファイルと1つのJavaScriptファイル(デフォルトではindex.js)が必要
index.jsのサンプル
const { app, BrowserWindow } = require('electron')
function createWindow(){
const w = new BrowserWindow({
width: 500,
height: 250,
webPreferences: {
nodeIntergration: false
}
})
w.loadFile('index.html')
}
app.whenReady().then(createWindow)
アプリの実行
Electronの作業フォルダで
npm run start


コメント