Skip to content

Instantly share code, notes, and snippets.

@hallettj
Last active September 22, 2015 00:48
Show Gist options
  • Save hallettj/e482606b53344e71d2bc to your computer and use it in GitHub Desktop.
Save hallettj/e482606b53344e71d2bc to your computer and use it in GitHub Desktop.
Changes required to adapt a React app to run in Electron
diff --git a/examples/todomvc/electron-main.js b/examples/todomvc/electron-main.js
new file mode 100644
index 0000000..6b46773
--- /dev/null
+++ b/examples/todomvc/electron-main.js
@@ -0,0 +1,24 @@
+var app = require('app')
+var BrowserWindow = require('browser-window')
+
+require('crash-reporter').start()
+
+// Keep a global reference of the window object, if you don't, the window will
+// be closed automatically when the JavaScript object is GCed.
+var mainWindow = null
+
+app.on('window-all-closed', function() {
+ // On OS X 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('ready', function() {
+ mainWindow = new BrowserWindow({ width: 800, height: 600 })
+ mainWindow.loadUrl('file:///'+ __dirname +'/index.html')
+ mainWindow.on('closed', function() {
+ mainWindow = null
+ })
+})
diff --git a/examples/todomvc/index.html b/examples/todomvc/index.html
index d956cdb..cf47b21 100644
--- a/examples/todomvc/index.html
+++ b/examples/todomvc/index.html
@@ -6,6 +6,8 @@
<body>
<div class="todoapp" id="root">
</div>
- <script src="/static/bundle.js"></script>
+ <script>
+ require('./dist/bundle')
+ </script>
</body>
</html>
diff --git a/examples/todomvc/package.json b/examples/todomvc/package.json
index b893d98..5dfd8b9 100644
--- a/examples/todomvc/package.json
+++ b/examples/todomvc/package.json
@@ -5,7 +5,8 @@
"scripts": {
"start": "node server.js",
"test": "NODE_ENV=test mocha --recursive --compilers js:babel-core/register",
- "test:watch": "npm test -- --watch"
+ "test:watch": "npm test -- --watch",
+ "electron": "node_modules/.bin/electron electron-main.js"
},
"repository": {
"type": "git",
@@ -18,6 +19,7 @@
"homepage": "http://rackt.github.io/redux",
"dependencies": {
"classnames": "^2.1.2",
+ "electron-prebuilt": "^0.33.0",
"react": "^0.13.3",
"react-redux": "^2.1.2",
"redux": "^3.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment