上で実行しています特急出願
我々私たちの明示的なアプリケーションにロードされるトップレベルのファイルが必要です。 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を実行しますプロジェクトのルートにあるファイルです。