This project is a basic example of a SvelteKit app integrated with Capacitor for native mobile platform support. The backend is powered by a simple Express server.
This project allows you to run a SvelteKit web app and build it into a native mobile app using Capacitor. Capacitor enables web applications to run natively on iOS and Android platforms.
To get started with this project, you will need to have Node.js installed. If you haven't already, download and install it from here.
Clone the repository and install the required dependencies:
git clone https://github.com/NashTech-Labs/sveltkit-capacitor-template.git
cd sveltekit-capacitor-template
cd template-sveltekit-capacitor
npm install
This will install all required packages, including SvelteKit and Capacitor.
To run the SvelteKit application in development mode, use the following command:
npm run dev
This will start the development server, and you can view your app in the browser at http://localhost:5173.
cd ../server
npm install
.env
file in the backend root:MONGODB_URI=<your_mongo_db_connection_string>
PORT=3000
npm run start
To build the SvelteKit app for production, use the build
script:
npm run build
This will output the static files for your app in the build
directory.
After building the app for production, you can use Capacitor to generate native Android or iOS projects. Follow the steps below:
Add a plateform:
For Android:
npx cap add android
For iOS:
npx cap add ios
Sync your app with Capacitor:
npx cap sync
Open the platform in Android Studio or Xcode:
For Android:
npx cap open android
For iOS:
npx cap open ios
Here are some useful Capacitor commands:
npx cap sync
- Syncs the web app with native platforms.npx cap open android
- Opens the Android project in Android Studio.npx cap open ios
- Opens the iOS project in Xcode.npx cap copy
- Copies the web assets to the native platforms.npx cap run
- Runs the native project (Android/iOS).