#How can I prevent the react application from launching in the browser?
18 messages · Page 1 of 1 (latest)
I currently launch my application like this:
const { app, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
const path = require('path');
let mainWindow;
let loadingWindow;
function createLoadingWindow() {
loadingWindow = new BrowserWindow({
width: 400,
height: 300,
frame: false,
transparent: true,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
},
show: false, // Masquer la fenêtre de chargement au départ
});
loadingWindow.loadFile('loading.html'); // Créez un fichier HTML pour la fenêtre de chargement
}
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
show: false, // Masquer la fenêtre principale au départ
});
mainWindow.loadURL(
isDev
? 'http://localhost:3000' // URL de développement
: `file://${path.join(__dirname, '../build/index.html')}` // URL de production
);
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.on('ready', () => {
createLoadingWindow();
// Une fois que la fenêtre de chargement est prête, affichez-la
loadingWindow.once('ready-to-show', () => {
loadingWindow.show();
// Ensuite, chargez la fenêtre principale
createWindow();
// Écoutez l'événement 'ready-to-show' de la fenêtre principale
mainWindow.once('ready-to-show', () => {
mainWindow.show(); // Affichez la fenêtre principale lorsque tout est prêt
loadingWindow.hide(); // Cachez la fenêtre de chargement
});
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
And package.json:
"scripts": {
"start": "react-scripts start",
"electron": "electron main.js",
"dev": "npm-run-all -p electron start",
"build": "react-scripts build",
"eject": "react-scripts eject"
},
This ?
"dev": "BROWSER=false npm-run-all -p electron start",
might not work on Windows
Yes indeed it doesn't understand BROWSER
I'll give it a try, thanks for the information!
otherwise you can use a .env file
Can you recommend a .env pu cross-env?
what?
Would you recommend a .env or cross-env?