Ionic è un toolkit libero e open source per costruire applicazioni mobile e web da un'unica base di codice. Affianca una libreria di componenti UI già stilizzati a una CLI che genera progetti con un solo comando e si rivolge ad Android, iOS e al web, con supporto desktop tramite la Universal Windows Platform.
Ionic è un livello sottile sopra gli standard web, quindi le funzionalità native dei dispositivi arrivano dai plugin: l'ecosistema di plugin di Cordova (o Capacitor, il suo successore) vi dà accesso a fotocamera, GPS, torcia e molto altro. Dietro le quinte tutto gira su Node.js, ed è da qui che parte questa guida su Debian 10.
Requisiti
- Un server con Debian 10.
- Accesso root.
Preparare il sistema
apt-get update -y
Installate gli strumenti per download e firma:
apt-get install curl gnupg2 wget -y
Installare Node.js
L'archivio Debian distribuisce una release di Node piuttosto datata, quindi aggiungete il repository NodeSource per Node 14:
curl -sL https://deb.nodesource.com/setup_14.x | bash -
Installate:
apt-get install nodejs -y
Verificate:
node --version
v14.17.1
Le app Ionic che richiedono API native si compilano con Cordova: installatelo globalmente tramite npm.
npm install -g cordova
Installare la CLI di Ionic
Anche la CLI è un pacchetto npm:
npm i -g @ionic/cli
Confermate l'installazione:
ionic -v
6.16.3
Creare il primo progetto
Avviate il generatore:
ionic start
Verranno poste tre domande — quale framework web usare, il nome del progetto e un template di partenza:
Pick a framework! ???? Please select the JavaScript framework to use for your new app. To bypass this prompt next time, supply a value for the --type option. ? Framework: Angular Every great app needs a name! ???? Please enter the full name of your app. You can change this at any time. To bypass this prompt next time, supply name, the first argument to ionic start. ? Project name: myapp Let's pick the perfect starter template! ???? Starter templates are ready-to-go Ionic apps that come packed with everything you need to build your app. To bypass this prompt next time, supply template, the second argument to ionic start. ? Starter template: tabs ? Preparing directory ./myapp in 3.69ms ? Downloading and extracting tabs starter in 591.18ms ? Integrate your new app with Capacitor to target native iOS and Android? No Your Ionic app is ready! Follow these next steps: - Go to your new project: cd ./myapp - Run ionic serve within the app directory to see your app in the browser - Run ionic capacitor add to add a native iOS or Android project using Capacitor - Generate your app icon and splash screens using cordova-res --skip-config --copy - Explore the Ionic docs for components, tutorials, and more: https://ion.link/docs - Building an enterprise app? Ionic has Enterprise Support and Features: https://ion.link/enterprise-edition
Avviare il server di sviluppo
Entrate nel progetto e avviate un dev server con hot reload in ascolto su tutte le interfacce, così da poterlo visualizzare da un'altra macchina:
cd myapp
ionic serve --host 0.0.0.0 --port 8100
Dovreste ottenere un output simile a:
> ng run app:serve --host=0.0.0.0 --port=8100 [INFO] Development server running! Local: https://localhost:8100 External: https://216.98.11.73:8100 Use Ctrl+C to quit this process [INFO] Browser window opened to https://localhost:8100!
Aprite https://your-server-ip:8100 nel browser e la vostra app vi accoglie:

Attenzione all'esposizione: il binding a 0.0.0.0 pubblica in rete un server di sviluppo privo di autenticazione. Accettabile su una LAN privata, rischioso su un IP pubblico: filtrate la porta 8100 con un firewall o restate in ascolto solo su localhost quando non state testando da remoto.
Conclusioni
Su Debian 10 sono ora pronti Node.js, Cordova, la CLI di Ionic e un progetto iniziale funzionante. Da qui, ionic generate aggiunge pagine e componenti, ionic build produce i bundle per la produzione e Capacitor incapsula lo stesso codice come app nativa quando sarete pronti per gli store.