I am trying to start my new project with react and electronjs. I've already installed react-app with babel and web pack which works fine but now I am struggling to launch it with electron but without any luck :/. I looked at many articles about react and electron but there was no suggestions and real examples how to connect (react, web pack, babel, and electron) together.
electron-starter.js looks like that:
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
const isDev = require('electron-is-dev');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({width: 900, height: 680});
mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`);
mainWindow.on('closed', () => mainWindow = null);
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
and package.json:
{
"name": "hostelpro-app-2",
"version": "0.1.0",
"private": true,
"homepage": "./",
"main": "./electron-starter.js",
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "webpack-dev-server --open --mode development",
"build": "webpack --mode production",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"electron": "electron .",
"electron-dev": "concurrently \"BROWSER=none npm start\" \"wait-on http://localhost:3000 && electron .\""
},
"babel": {
"presets": [
"env"
]
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"css-loader": "^1.0.0",
"electron": "^2.0.6",
"foreman": "^3.0.1",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.9.2",
"prop-types": "^15.6.2",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
}
}
right now the error message is: "'concurrently' is not recognized as an internal or external command", but if I delete 'concurrently' word from package.json then it "'BROWSER' is not recognized as an internal or external command" error occurs.
any suggestions will be helpful. Thank you! :)