2016-08-18 15 views
2

私が成功したようにしかし、私が原因彼らGNU一般公衆利用許諾契約書にそうしないことをお勧めしてどのように電子内で表現を実行するには?

https://github.com/theallmightyjohnmanning/electron-express

https://github.com/frankhale/electron-with-express

としてリポジトリを経由して電子アプリ内で表現で実行することができました課す。私は収益化する商用アプリを作成しようとしています。したがって、MITのような賢い人はやるかもしれないが、GNUについては不明である。

とにかく、私は彼の手順に従うことをしようとしている:

https://gist.github.com/maximilian-ruppert/a446a7ee87838a62099d

しかし、いくつかの問題に実行されています。 これまでに何をしているのかを知る。その後

# Clone the Quick Start repository 
$ git clone https://github.com/electron/electron-quick-start 

# Go into the repository 
$ cd electron-quick-start 

# Install the dependencies and run 
$ npm install && npm start 

$ express myapp 
$ cd myapp 

$ npm install 
renamed myapp to just app 

を表明し、今私は電子main.jsファイルまたは/を設定する必要がある部分で立ち往生し、特急のアプリにリンクして持っているindex.htmlファイルをレンダリングしています取得するにはその代わりに実行するindex.html

助けていただければ幸いです。

私はあなたが含まれているindex.htmlファイルを作成します。まず

npm install --save electron 

あなたのアプリで電子をインストール電子でExpressアプリケーションに

包装窓10

答えて

2

上で実行しています特急出願

我々私たちの明示的なアプリケーションにロードされるトップレベルのファイルが必要です。 Webpackのようなモジュールバンドラを使用していない場合、あなたのアプリケーションが依存するすべてのhtml、cs、jsファイルをこのindex.htmlファイルにインポートするだけです。

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>QuickMap</title> 
    <link href='public/css/boostrap.min.css' rel='stylesheet'> 
    <link href='public/css/layout.css' rel='stylesheet'> 
    </head> 
    <body> 
    <div id='root' /> 
    <script src='public/js/appBundle.js' type='text/javascript'></script> 
    <script src='public/js/bootstrap.min.js' type='text/javascript'></script> 
    <script src='public/js/jquery-3.1.1.min.js' type='text/javascript'></script> 
    </body> 
</html> 

これのindex.htmlファイルは、あなたが-i.eに必要なすべてのHTML、CSS、JSおよびその他のファイルを実行するためのアプリのために必要なすべてを輸入していることを確認してください。上記の例でロードしたjQueryのような、アプリケーションに必要な外部ファイルを含めてください。

アンさておき - 私達の全体のエクスプレスアプリはindex.htmlをによってロードされるWebPACKのバンドルで表され、この例ではWebPACKの

を使用して電子アプリケーションをパッケージング。

Webpackを使用してElectronでExpressアプリケーションをパッケージする必要はありません。必要なすべてのファイルにindex.htmlがロードされていることを確認すると、エクスプレスアプリケーションが起動します。

Webpackを使用している場合は、このindex.htmlファイルにバンドルをインポートする必要があります。

ここでは、エクスプレスアプリを含むwebpackバンドルをインポートするindex.htmlファイルの例を示します。

は今ここにあなたのエクスプレスアプリ

を含むのindex.htmlをロードし、プロジェクトのルートに電子設定ファイルを作成した電子は、自身を起動するために使用するメインファイルです。 Al電子関連の設定とエクスプレスアプリへのリンク(Webpackバンドルのインポートによる)がここに含まれています。

下記のファイルはルートプロジェクトディレクトリにあり、主にElectronクイックスタートガイドの定型文で構成されていますが、アプリケーション全体をロードするindex.htmlファイルをインポートする上記の行は例外です。

main.js

const {app, BrowserWindow} = require('electron') 
const path = require('path') 
const url = require('url') 

// 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}) 

    // and load the index.html of the app. 
    win.loadURL(url.format({ 
    pathname: path.join(__dirname, 'index.html'), 
    protocol: 'file:', 
    slashes: true 
    })) 

    // 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. 

次の行は、我々のアプリケーションのエントリポイントに私たちの電子インスタンスを指して、我々は以前に作成した私たちのindex.htmlをロードします。

mainWindow.loadURL(`file://${__dirname}/index.html`) 

変更電子

"scripts": { 
    "start": "ENV=development electron .", 
    }, 

を起動するためにあなたのpackage.jsonでの起動スクリプト我々は

npm start 

を実行すると、電子は自動的に探し、main.jsを実行しますプロジェクトのルートにあるファイルです。

関連する問題