Skip to content

Electron support #140

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ module.exports = {
root: nodeModulesPath,
moduleTemplates: ['*-loader']
},
target: 'electron-main',

node: {
__dirname: false,
__filename: false
},
module: {
preLoaders: [
{
Expand Down
6 changes: 6 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ module.exports = {
root: nodeModulesPath,
moduleTemplates: ['*-loader']
},
target: 'electron-main',

node: {
__dirname: false,
__filename: false
},
module: {
preLoaders: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-scripts",
"name": "electron-react-scripts",
"version": "0.1.0",
"description": "Configuration and scripts for Create React App.",
"repository": "facebookincubator/create-react-app",
Expand Down
4 changes: 2 additions & 2 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(hostPath, appName, verbose) {

// Copy over some of the devDependencies
hostPackage.dependencies = hostPackage.dependencies || {};
['react', 'react-dom'].forEach(function (key) {
['react', 'react-dom', 'electron-prebuilt'].forEach(function (key) {
hostPackage.dependencies[key] = selfPackage.devDependencies[key];
});

Expand All @@ -42,7 +42,7 @@ module.exports = function(hostPath, appName, verbose) {
fs.move(path.join(hostPath, 'gitignore'), path.join(hostPath, '.gitignore'), []);

// Run another npm install for react and react-dom
console.log('Installing react and react-dom from npm...');
console.log('Installing react, react-dom, and electron-prebuilt from npm...');
// TODO: having to do two npm installs is bad, can we avoid it?
var args = [
'install',
Expand Down
45 changes: 0 additions & 45 deletions scripts/openChrome.applescript

This file was deleted.

25 changes: 7 additions & 18 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var chalk = require('chalk');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('../config/webpack.config.dev');
var execSync = require('child_process').execSync;
var exec = require('child_process').exec;
var opn = require('opn');

// TODO: hide this behind a flag and eliminate dead code on eject.
Expand Down Expand Up @@ -122,24 +122,13 @@ compiler.plugin('done', function (stats) {
});

function openBrowser() {
if (process.platform === 'darwin') {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"');
execSync(
'osascript ' +
path.resolve(__dirname, './openChrome.applescript') +
' http://localhost:3000/'
);
return;
} catch (err) {
// Ignore errors.
}
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
exec('electron .');
} catch (err) {
// Ignore errors.
}
// Fallback to opn
// (It will always open new tab)
opn('http://localhost:3000/');
}

new WebpackDevServer(compiler, {
Expand Down