Getting Live Reload To Work In Your Vite Ionic Project Using VueJS Or ReactJS
Tags: ionic, vite, react, vue
Published: 2022-08-12 05:30:25


>March 10, 2023 - Updated Content Here : https://dev.to/aaronksaunders/how-to-create-a-mobile-app-using-vite-vue-and-ionic-capacitor-in-8-minutes-including-explanation-1c4g

---

## Getting Live Reload To Work In Your Vite Ionic Project

I like to use [ViteJS](https://vitejs.dev/) in my [Ionic Framework](https://ionicframework.com/) Projects because is is extremely fast. In some situations there is a need for using the [Capacitor Live Reload](https://capacitorjs.com/docs/guides/live-reload) ability you normally get from Ionic Framework [Capacitor](https://capacitorjs.com) Projects; this is helpful with the developer experience when working on the physical device.

Trying the normal ionic cli commands will not work, but I have outlined an approach below that will work for you.

>I don't use Capacitor Live Reload that often, but this is a manual approach to get it going with the Vite in ReactJS or VueJS project. I provide sample projects linked below

**First Start Your Server**
```
aaronksaunders@Aarons-14MacBookProM1Pro my-react-app % npm run dev

> my-react-app@0.0.0 dev
> vite


  VITE v3.0.6  ready in 359 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose
12:57:47 AM [vite] hmr update /src/App.tsx
```


**Then modify `capacitor.config.ts`** using the address the server is running on from the command above
```
const config: CapacitorConfig = {
  appId: 'my.react.app',
  appName: 'my-react-app',
  webDir: 'dist',
  bundledWebRuntime: false,
  server : {
    "url" : "http://127.0.0.1:5173/"  //<= use address the server is running on locally
  }
};
```
**And finally deploy your app to the device**
```
aaronksaunders@Aarons-14MacBookProM1Pro my-react-app % npx cap run ios --external  --target=73CE91C9-4855-496B-9481-CA486652E9D7
✔ Copying web assets from dist to ios/App/App/public in 12.83ms
✔ Creating capacitor.config.json in ios/App/App in 1.35ms
✔ copy ios in 25.05ms
✔ Updating iOS plugins in 1.96ms
[info] Found 4 Capacitor plugins for ios:
       @capacitor/app@4.0.1
       @capacitor/haptics@4.0.1
       @capacitor/keyboard@4.0.1
       @capacitor/status-bar@4.0.1
✔ Updating iOS native dependencies with pod install in 2.53s
✔ update ios in 2.56s
✔ Running xcodebuild in 3.20s
✔ Deploying App.app to 73CE91C9-4855-496B-9481-CA486652E9D7 in 1.51s
aaronksaunders@Aarons-14MacBookProM1Pro my-react-app % 
```
Now your mobile app is pointing to the local server running and you basically have live-reload working. I am certain there is another approach, but like I said I don't use it often enough. Hopefully, this gets you moving

**REMEMBER**
remove the edit to the `capacitor.config.ts` before deploying to production otherwise the app will be looking for the local server to run the app !!

## Here Are Some Ionic Capacitor Vite Templates 
These templates have been tested on IOS and Android and work with the latest version of Ionic as of the date of this post.

### REACTJS
{% github aaronksaunders/ionic-capacitor-react-vite-app %}

### VUEJS
{% github aaronksaunders/ionicv6-beta-vue-vite-project %}