Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running pex in Electron #7

Open
1 task
vorg opened this issue Jun 3, 2015 · 4 comments
Open
1 task

Running pex in Electron #7

vorg opened this issue Jun 3, 2015 · 4 comments

Comments

@vorg
Copy link
Member

vorg commented Jun 3, 2015

With pex-gl/pex-sys@c1f0fb5 and pex-gl/pex-gui@9b3eb04 it's now possible to run pex apps in Electron without browserify, pure node!

screen shot 2015-06-03 at 16 46 48

All you need to do is to update your package.json and add index.html and app.js as below and run this in the project folder:

npm install electron-prebuilt --save-dev

./node_modules/.bin/electron .

package.json:

...
"main": "app.js",
...

index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="main.js"></script>
    </head>
    <body>
</html>

app.js:

var app = require('app');
var BrowserWindow = require('browser-window');
var mainWindow = null;

app.on('window-all-closed', function() {
  app.quit();
});

app.on('ready', function() {
  mainWindow = new BrowserWindow({width: 1280, height: 720});

  mainWindow.loadUrl('file://' + __dirname + '/index.html');
  mainWindow.on('closed', function() {
    mainWindow = null;
  });
});

Issues

  • pex-sys/IO is broken as it thinks it's a browser but Electron blocks AJAX to local files.
@vorg
Copy link
Member Author

vorg commented Jun 3, 2015

You can also package it as a native app with electron-packager

npm install electron-packager --save-dev

./node_modules/.bin/electron-packager . ../Proton --platform=darwin --arch=x64 --version=0.27.2

But watch out. Remove browserify, browser-sync and other stuff. Still your app will be 100MB because ``Electron.framework** is 96MB :/ It compresses pretty well though to 37MB..

screen shot 2015-06-03 at 17 03 28

Issues

  • FIXED: you will get duplicated modules in require.cache (causing e.g. Context.currentContext to be null) if you build your app in the same folder as node_modules. Just build it one level above e.g. ../Proton

@szymonkaliski
Copy link

wohoo! 👍

@szymonkaliski
Copy link

It would be cool if we could just require(main.js) in index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script>
          require('main.js');
        </script>
    </head>
    <body>
</html>

Or is it working like that already? (can't check right now)

@vorg
Copy link
Member Author

vorg commented Jun 3, 2015

@szymon, you can require it or just do <script src="main.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants