Browse Source

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

SimulatedGREG 7 years ago
parent
commit
3a5914f703
5 changed files with 23 additions and 33 deletions
  1. 0 1
      .gitignore
  2. 0 1
      package.json
  3. 0 27
      src/index.ejs
  4. 13 0
      src/main/index.js
  5. 10 4
      src/renderer/index.js

+ 0 - 1
.gitignore

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

+ 0 - 1
package.json

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

+ 0 - 27
src/index.ejs

@@ -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>

+ 13 - 0
src/main/index.js

@@ -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()
 })

+ 10 - 4
src/renderer/index.js

@@ -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>
+`)