v2.0.0 - The new version is here, this comes with some better defaults, vite as the build manager, built in routing library, TypeScript, and aliases. While this could be seen as an 'incremental' update I think this works as a v2.0.0 as it was a complete rewrite.
Note that you will need to have Node.js installed.
Install the dependencies...
git clone "https://github.com/drannex42/svelte-capacitor.git" cd svelte-capacitor npm install
npm run dev:start
npx cap add android // (or ios)
Please see section below (Develop on your device with livereload)
If you're only targeting Android, you only need to change the
server.url section in
capacitor.config.json to use
http://10.0.2.2:5001, since Android Studio already adds a
localhost proxy. Just remember to remove it when building your app for production.
If you're targeting iOS or both, you will need to append your workstation IP to the
server.url section in
capacitor.config.json instead. To discover your workstation IP, just run
ifconfig or find it on the network settings.
Tip: Remember you will need the
http:// before the server IP.
Back in the root folder:
npm run dev:android or
npm run dev:ios
This will run the capacitor/svelte project with a web view pointing to your workstation's IP. You should see the message
Welcome to Svelte! if svelte loaded correctly.
Try to change something in
App.svelte, and you should see the content reload on your device.
cordova-res ios --skip-config --copy cordova-res android --skip-config --copy
Remember to remove the
npm run build:android or
npm run build:ios
You can use any Chromium-based browser and use their Developer Tools (for Android atleast, have not tested iOS) to debug and access console commands on your personal device, by going to chrome://inspect#devices., edge://inspect#devices., vivaldi://inspect#devices., brave://inspect#devices, &c.
The standard web inspector will also work for debugging and rewriting styling and html without using your IDE just like when building a normal website. This may have some issues with some forms of SVG-related svelte templating (I have had issues with using some chart libraries displaying in the web inspector), they will still show up on the device but not in the preview.
You may use the address bar in the developer tools to navigate to direct views in your application, even without any tappable links to do so. This allows you to create hidden routes for testing.
Place any assets, CSS, client JS, Images in the
assets folder - not the public folder! On build and usage this will add everything to the public dist folder for copying to the device application. See Vite.js on this settings.
@components, @store, and @utils: If you have ever taken a look at sveltekit they have these nify aliases throughout their code so you don't have to write '../../../components' or what have you. Now you can just do '@components/file' and Vite will readily load them from the components folder, this makes it easy to create changes as you don't need to change the file location on every move or copy. Please check out the Vite Aliases package for more questions.
Since this is a Svelte application you will be able to use any routing manager that you prefer. I prefer routify, but others such as the following will work as well (Routify is built into this project, but easily changed)
CapacitorJS is/was based on Cordova and has complete backwards compatibility with cordova plugins. To find plugins that allow you to access the device api's easier, attempt to find cordova or capacitor plugins. You will need to view their (capacitorjs) docs to learn how to properly accesss those.
Submit a PR! I would love to have more people working on this, the advantages of a system such as this vs NativeScript or React Native are innumerable especially in regards for how quickly you can get started and instant developer options and this could be built out to something great!
I would love to keep a collection of all the projects using this!
This template was created by Drannex42 (Macleod Sawyer) of DNX Industries - Source can be found here