とりあえず Electron で Hello, World! 的なやつを[プログラミング]
(2018-12-28 14:57:30) by shinoda


< ページ移動: 1 2 >

Qiita の「Electronの始め方 on Mac」(@basicactorさん投稿)という記事をもとに、とりあえず動くものを作ってみよう。

まず、テストアプリ用のソースとかを格納するディレクトリを掘る。
それから、Node.js のプロジェクトとして npm で初期化を行う。

$ pwd
/Users/shinoda
$ mkdir electron_proj
$ mkdir electron_proj/testapp1
$ cd electron_proj/testapp1
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (testapp1) 
version: (1.0.0) 
description: Test Program YO!!
entry point: (index.js) 
test command: 
git repository: 
keywords: sample test
author: shinoda
license: (ISC) 
About to write to /Users/shinoda/electron_proj/testapp1/package.json:

{
  "name": "testapp1",
  "version": "1.0.0",
  "description": "Test Program YO!!",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "sample",
    "test"
  ],
  "author": "shinoda",
  "license": "ISC"
}


Is this OK? (yes) <リターンキー>

これで、ここで作られるプログラムを Node.js のパッケージとして管理するための情報が package.json という名前の JSON形式のファイルとして作成される。

直下にできてるね。

$ ls -la
total 8
drwxr-xr-x  3 shinoda  staff   96 12 28 13:01 .
drwxr-xr-x  3 shinoda  staff   96 12 28 11:55 ..
-rw-r--r--  1 shinoda  staff  274 12 28 13:01 package.json
$ cat package.json
{
  "name": "testapp1",
  "version": "1.0.0",
  "description": "Test Program YO!!",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "sample",
    "test"
  ],
  "author": "shinoda",
  "license": "ISC"
}

次に、プログラム本体(といっても、JavaScript と HTML)を作成する。

まず、index.js というファイルに JavaScript を記述する。
(件のページの main.js をパチってます)

< ページ移動: 1 2 >


コメント投稿
次の記事へ >
< 前の記事へ
TOPへ戻る

Powered by
MT4i 3.0.8