update .gitignore, remove index.ejs, add code comments to main process

This commit is contained in:
SimulatedGREG 2017-08-27 14:50:22 -05:00
parent 4f2531e10c
commit 3a5914f703
5 changed files with 23 additions and 33 deletions

1
.gitignore vendored
View file

@ -2,4 +2,3 @@
dist/
node_modules/
thumbs.db
!.gitkeep

View file

@ -1,7 +1,6 @@
{
"name": "electron-webpack-quick-start",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",

View file

@ -1,27 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
<!-- Set `__static` path to static files in production -->
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>
</head>
<body>
<h1>Hello World!</h1>
<p>
You are using Node.js <span id="node"></span>,
Chromium <span id="chrome"></span>,
Electron <span id="electron"></span>,
and <code>electron-webpack</code> <span id="electron-webpack"></span>.
</p>
<!-- webpack builds are automatically injected -->
</body>
</html>

View file

@ -4,10 +4,17 @@ import { app, BrowserWindow } from 'electron'
const isDevelopment = process.env.NODE_ENV !== 'production'
// Global reference to mainWindow
// Neccessary to prevent win from being garbage collected
let mainWindow
function createMainWindow () {
// Construct new BrowserWindow
let win = new BrowserWindow()
// Set url for `win`
// points to `webpack-dev-server` in development
// points to `index.html` in production
let url = isDevelopment
? 'http://localhost:9080'
: `file://${__dirname}/index.html`
@ -23,14 +30,20 @@ function createMainWindow () {
return win
}
// Quit application when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications to stay open
// until the user explicitly quits
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', () => {
// On macOS it is common to re-create a window
// even after all windows have been closed
if (mainWindow === null) mainWindow = createMainWindow()
})
// Create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow()
})

View file

@ -1,4 +1,10 @@
document.getElementById('node').innerText = process.versions.node
document.getElementById('chrome').innerText = process.versions.chrome
document.getElementById('electron').innerText = process.versions.electron
document.getElementById('electron-webpack').innerText = require('electron-webpack/package.json').version
// Initial landing page
document.write(`
<h1>Hello world!</h1>
<p>
You are using Node.js ${process.versions.node},
Chromium ${process.versions.chrome},
Electron ${process.versions.electron},
and <code>electron-webpack</code> ${require('electron-webpack/package.json').version}.
</p>
`)