node js でwindowsやMacのアプリケーションを制作することができる electron をインストールする

● electronとは?

electonとは html や css や javascript などといった web 制作の技術を使ってデスクトップ上のアプリケーションを制作しようというものです。 ( まず node js が必要になりますので node js のインストールを完了させておいてください )

● electron をインストールする

 npm install -g  electron
 npm install -g  electron-packager 

● Helloworldプログラムに必要な3つのファイルを用意する

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello Electron!</title>
</head>
<body>
<h1>Hello Electron!</h1>
Node version: <script>document.write(process.versions.node)</script>,
Chrome version: <script>document.write(process.versions.chrome)</script>,
Electron version: <script>document.write(process.versions.electron)</script>.
</body>
</html>

main.js

const { app, BrowserWindow } = require('electron');
let win;
function createWindow() {
    win = new BrowserWindow({ width: 800, height: 600 });
    win.loadURL(`file://${__dirname}/index.html`);
    win.on('closed', () => {
        win = null;
    });
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});
app.on('activate', () => {
    if (win === null) {
        createWindow();
    }
});

package.json

{
  "name": "myapp",
  "version": "0.0.1",
  "main": "main.js"
}

● プログラムを実行する

electron .

● アプリを作成する(ビルド)

  1. electonのバージョンを調べる
    electron -v
    

    (例 : v1.6.2)

  1. electron-packagerアプリケーションを作成する
    electron-packager <ディレクトリ>  <アプリ名(拡張子は除く)>  --platform=darwin,win32  --arch=x64  --version=<バージョン>  --overwrite
    

● electron 関連リンク

https://qiita.com/tags/electron
https://teratail.com/questions/search?q=electron&search_type=and
http://bit.ly/2nYCc4d
http://bit.ly/2n8dA47

● 実際にelectronを使って制作されたプログラム

※ iCultus(常駐型カレンダー)

https://github.com/djyde/iCultus

※ comma-chameleon(CSVエディタ)

https://github.com/theodi/comma-chameleon

※ lightgallery

http://sachinchoolur.github.io/lightgallery-desktop/

● MacからWindowsビルド用パッケージのインストール

nodebrew を使って以下のパッケージをインストールします

brew cask install xquartz(途中で管理者パスワードの入力を求められます)
brew install wine
No.1110
12/31 11:42

edit