MochiuWiki : SUSE, EC, PCB
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
検索
個人用ツール
ログイン
Toggle dark mode
名前空間
ページ
議論
表示
閲覧
ソースを閲覧
履歴を表示
設定 - WebStormとの連携のソースを表示
提供: MochiuWiki : SUSE, EC, PCB
←
設定 - WebStormとの連携
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループのいずれかに属する利用者のみが実行できます:
管理者
、new-group。
このページのソースの閲覧やコピーができます。
== 概要 == WebStormを使用して、Electronを開発するための手順を記載する。<br> <br><br> == 事前準備 == 以下のソフトウェアがインストールされているものとする。<br> * Node.js * WebStorm <br><br> == WebStormの設定 == # WebStormを起動して、[Create New Project]を選択する。 # [New Project]画面左にある[Node.js]を選択して、[Location:]項目にプロジェクト名を入力する。<br>[Node Interpreter:]プルダウンと[Package Manager:]プルダウンには、任意のバージョンのNodeとNPMを選択する。><br><u>※プロジェクト名には、<span style="color:#C00000">大文字のアルファベットは使用できない</span>ので注意すること。</u> # [Create]ボタンを押下して、プロジェクトを生成する。 #: <br> # プロジェクト画面から、[File] - [Settings...]を選択して、設定画面を開く。 # 設定画面左から、[Language & Frameworks] - [Node.js and NPM]を選択する。 # 画面左の下部にある[+]ボタンを押下して、[Available Packages]画面を開く。 # [Available Packages]画面上にある検索欄に"electron"と入力して、一覧に表示された"electron"を選択する。 # [Available Packages]画面下にある[INSTALL PACKAGE]ボタンを押下して、electronをインストールする。 # "Package 'electron' installed successfully"と表示されて、インストールが完了する。 #: <br> # package.jsonファイル内に<code>dependencies</code>が自動的に追記されて、<code>electron</code>という項目が記述される。<br>同様に、node_modulesディレクトリにelectronが追加されていることが確認できる。 <br><br> == package.jsonの設定 == Electronをインストールした場合、package.jsonファイル内には、エントリポイントがindex.jsと記述されているが、<br> Electronの公式Webサイトでは、main.jsが標準のようなので、この記述を編集する。<br> <syntaxhighlight lang="javascript"> # package.jsonファイル # 変更前 "main": "index.js", # 変更後 "main": "main.js", </syntaxhighlight> <br> 次に、package.jsonファイル内の"scripts"項目において、以下の設定を追記する。<br> # Electronをローカルインストールしている場合 "run": "./node_modules/.bin/electron .", # Electronをグローバルインストールしている場合 "run":"electron ." <br><br> == サンプルコード == index.htmlファイルとmain.jsファイルを作成する。<br> <br> Electronの公式Webサイトから、基本となるindex.htmlファイルの内容とmain.jsファイルの内容をコピーする。<br> 以下のサンプルコードは、[https://electronjs.org/docs/tutorial/first-app Writing Your First Electron App]から引用している。<br> <syntaxhighlight lang="javascript"> // main.jsファイル const { app, BrowserWindow } = require('electron') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win function createWindow () { // Create the browser window. win = new BrowserWindow( { width: 800, height: 600, webPreferences: { nodeIntegration: true } }) // and load the index.html of the app. win.loadFile('index.html') // Open the DevTools. //win.webContents.openDevTools() // Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() } }) // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. </syntaxhighlight> <br> <syntaxhighlight lang="html"> index.htmlファイル <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> We are using node <script>document.write(process.versions.node)</script>, Chrome <script>document.write(process.versions.chrome)</script>, and Electron <script>document.write(process.versions.electron)</script>. </body> </html> </syntaxhighlight> <br><br> == デバッグの設定 == # WebStormのプロジェクト画面右上にある[ADD CONFIGURATION...]プルダウンから、[Run/Debug Configurations]を選択する。 # [Run/Debug Configurations]画面左にある[Templates] - [Node.js]を選択する。 #: <br> # 画面右に表示されている以下の項目を設定する。 #* [Node interpreter]項目の右にある[...]を選択する。<br>[Node.js interpreter]画面左下にある[+]ボタンを押下して、[Add Local...]を選択する。<br>プロジェクトディレクトリにあるnode_moduleディレクトリから、electronファイル(Windowsの場合は、electron.cmd)を選択する。 #* [Node parameters]項目に、<code>.</code>を入力する。 #* [Working directory]項目は変更しない。 #* [JavaScript file]項目に、<code>main.js</code>を入力する。 #* [Application parameters]項目に、<code>--remote-debugging-port=9222</code>を入力する。 #* [Environment variables]項目は変更しない。 #: <br> # [OK]ボタンを押下して、[Run/Debug Configurations]画面を閉じる。 <br> プロジェクト画面右上にある虫アイコンを選択して、デバッグを実行する。<br> <br><br> __FORCETOC__ [[カテゴリ:Electron]]
設定 - WebStormとの連携
に戻る。
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
Collapse