Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Svelte.js with Ionic?

I am trying to build a mobile app with Svelte.js and Ionic v4.

1) I got the svelte-template.

2) Installed ionic with npm install @ionic/core@latest --save.

3) Installed postcss and imported @ionic css in global.css

Rollup is extracting the @ionic css but it seems that there maybe something wrong with the way it is doing. The ionic components are acessible, but I cannot see a thing. The css is not being applied properly.

Has anyone managed to make Svelte work with Ionic v4? Or at least, Ionic with some vanilla js?

like image 396
Fred Guth Avatar asked Oct 29 '19 16:10

Fred Guth


People also ask

Can you use Svelte with Ionic?

Happy to announce a full upgrade of my earlier project to integrate Ionic with Svelte. This time, improved and supercharged using Vite-power!

What is the difference between Ionic and capacitor?

Ionic is simply the UI layer for an app. It provides the building blocks for your app as well as the animations and gestures for more interactive parts. Capacitor is a JS library and Native runtime. It provides a JS API for interacting with Web and Native features, in a unified api.


2 Answers

this is how I eventually got it to work pretty nicely

https://ionicsvelte.firebaseapp.com/

The repo:

https://github.com/Tommertom/svelte-ionic-app

And in REPLs:

https://github.com/Tommertom/svelte-ionic-app/blob/master/REPLS.md

like image 78
TomG Avatar answered Oct 10 '22 07:10

TomG


I did. Using the CDN was easiest.

  1. Scaffold a new app: degit sveltejs/template myapp

  2. Add CDN to public/index.html above the ./global.css


<!-- ionic -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css"/>

<!-- ionicons -->
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
<script nomodule="" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>

  1. Update App.svelte
<script>
const greet = () => alert('hi')
</script>

<ion-app>
  <ion-content>
    <ion-header>
      <ion-toolbar>
        <ion-title>My App</ion-title>
      </ion-toolbar>
    </ion-header>
  </ion-content>
  <ion-footer>
    <ion-button color="secondary" expand="block" on:click={greet}>
      Greet
    </ion-button>
  </ion-footer>
</ion-app>

  1. Run
yarn && yarn dev
like image 43
deezy Avatar answered Oct 10 '22 07:10

deezy