This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
guida_operativa_per_creare_applicazioni_npm [2026/04/02 11:03] team |
guida_operativa_per_creare_applicazioni_npm [2026/04/02 11:10] (current) team |
||
|---|---|---|---|
| Line 164: | Line 164: | ||
| ``` | ``` | ||
| </code> | </code> | ||
| + | |||
| + | **Osservazione importante** | ||
| + | |||
| + | Nel caso di LibrePM, la cartella `desktop/` vive dentro un progetto più grande e la build desktop pesca il backend da: | ||
| + | |||
| + | <code> | ||
| + | ```json | ||
| + | "from": "../build/libs" | ||
| + | ``` | ||
| + | </code> | ||
| + | |||
| + | Questa è una soluzione ottima per applicazioni ibride in cui il pacchetto desktop deve incorporare un backend compilato altrove. | ||
| + | |||
| + | ===== 7. Dipendenze principali e loro ruolo ===== | ||
| + | |||
| + | **Dipendenze runtime** | ||
| + | |||
| + | Nel progetto di partenza sono presenti React, i18n, Bootstrap, charting, drag and drop, datepicker, gantt e altri componenti di UI | ||
| + | |||
| + | Per nuove app non devi copiarle tutte: devi selezionare solo ciò che serve. | ||
| + | |||
| + | **Dev dependencies essenziali per replicare la pipeline** | ||
| + | |||
| + | <code> | ||
| + | ```bash | ||
| + | npm install -D electron electron-builder vite @vitejs/plugin-react concurrently wait-on | ||
| + | npm install react react-dom | ||
| + | ``` | ||
| + | </code> | ||
| + | |||
| + | Aggiungi poi solo i pacchetti necessari per la tua UI. | ||
| + | |||
| + | ===== 8. File minimi per partire ===== | ||
| + | |||
| + | ==== 8.1 `electron/main.cjs` ==== | ||
| + | |||
| + | <code> | ||
| + | ```js | ||
| + | const { app, BrowserWindow } = require('electron') | ||
| + | const path = require('path') | ||
| + | |||
| + | const isDev = !app.isPackaged | ||
| + | |||
| + | function createWindow() { | ||
| + | const win = new BrowserWindow({ | ||
| + | width: 1400, | ||
| + | height: 900, | ||
| + | webPreferences: { | ||
| + | preload: path.join(__dirname, 'preload.cjs'), | ||
| + | contextIsolation: true, | ||
| + | nodeIntegration: false | ||
| + | } | ||
| + | }) | ||
| + | |||
| + | if (isDev) { | ||
| + | win.loadURL('http://127.0.0.1:5173') | ||
| + | } else { | ||
| + | win.loadFile(path.join(__dirname, '../dist/index.html')) | ||
| + | } | ||
| + | } | ||
| + | |||
| + | app.whenReady().then(() => { | ||
| + | createWindow() | ||
| + | |||
| + | app.on('activate', () => { | ||
| + | if (BrowserWindow.getAllWindows().length === 0) createWindow() | ||
| + | }) | ||
| + | }) | ||
| + | |||
| + | app.on('window-all-closed', () => { | ||
| + | if (process.platform !== 'darwin') app.quit() | ||
| + | }) | ||
| + | ``` | ||
| + | </code> | ||
| + | |||
| + | ==== 8.2 `electron/preload.cjs` ==== | ||
| + | |||
| + | |||
| + | |||