<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kinjalk Tripathi</title>
    <description>The latest articles on DEV Community by Kinjalk Tripathi (@kinxyo).</description>
    <link>https://dev.to/kinxyo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1262123%2Fd0c6bc50-a73f-41ec-98a3-9206ef79561d.jpeg</url>
      <title>DEV Community: Kinjalk Tripathi</title>
      <link>https://dev.to/kinxyo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kinxyo"/>
    <language>en</language>
    <item>
      <title>Nuxt 3 as frontend for Tauri.</title>
      <dc:creator>Kinjalk Tripathi</dc:creator>
      <pubDate>Sun, 21 Jan 2024 10:38:05 +0000</pubDate>
      <link>https://dev.to/kinxyo/nuxt-3-as-frontend-for-tauri-34gf</link>
      <guid>https://dev.to/kinxyo/nuxt-3-as-frontend-for-tauri-34gf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Nuxt&lt;/strong&gt; is a microframework for Vue.js. It is basically a fullstack framework for javascript. It includes both frontend &amp;amp; the backend, however we will only use the frontend part.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One may be inclined to think that Nuxt might be an overkill, but it isn’t. Nuxt is much more than Vue. It’s provides a better frontend experience which compares to none. Vue, however, can be ideal for smaller application.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tauri&lt;/strong&gt;, on the other hand, is a toolkit for creating desktop application in Rust. The concept is similiar to Electron however Tauri requires lesser storage and memory (making it superior in some people’s book 👀).&lt;/p&gt;

&lt;h2&gt;
  
  
  DEVELOPMENT
&lt;/h2&gt;

&lt;p&gt;To setup both of these in harmony, I would first recommend watching this video by Simon Hyll. He shows how to setup the folder structure properly.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/MOnf_kGI6L0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In case, you wanna skip the video, here’s the tree-view of the directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
|-- src
|   |-- pages
|   &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; public
|-- src-tauri
|   |-- Cargo.lock
|   |-- Cargo.toml
|   |-- build.rs
|   |-- icons
|   |-- src
|   |-- target
|   &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; tauri.conf.json
|-- tsconfig.json
|-- yarn.lock
|-- README.md
|-- nuxt.config.ts
|-- package-lock.json
|-- package.json
|-- server
    &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have them setup, you can happily start developing your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  PRODUCTION
&lt;/h2&gt;

&lt;p&gt;After you’re done with your developmental build and want to create a binary for your application, you will need to run the build command.&lt;/p&gt;

&lt;p&gt;But before that, you must configure a few files (which hardly takes 1 minute).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuwd784uef5exx5hj9p6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuwd784uef5exx5hj9p6.png" alt="Top wtf moments when developing Tauri apps with Nuxt" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’ll run the build command without configuring the files, you’ll likely run into the above error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;Usually, popular frontend frameworks like React and Vue, create a dedicated folder (i.e dist folder) where they keep the static build of the frontend by pre-rendering the routes. These files are then served by the server and rendered by the browser. Since Tauri uses browser rendering engine to manifest the frontend therefore it naturally requires the static build. Hence, the above error only occurs when Tauri isn’t successful in finding the static build.&lt;/p&gt;

&lt;p&gt;Nuxt, being a full-stack framework, by default renders the build files on demand via its &lt;em&gt;node&lt;/em&gt; server instead of pre-rendering. This creates a conflict as Tauri requires static build files in advance to manifest the frontend of your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;Since we’re already using Rust for the backend therefore we’ll disable the server-side rendering for Nuxt. &lt;br&gt;
Add the following code in &lt;em&gt;nuxt.config.ts&lt;/em&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineNuxtConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we’ll simply tell Nuxt to prerender our site (meaning, create static files instead of relying on the server to run and process them during runtime). We do this by adding the following code to our &lt;em&gt;nuxt.config.ts&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;routeRules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;prerender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="cm"&gt;/* do the same for all routes used */&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, we need to specify the path to our static files folder. In tauri.conf.json, point to the public folder located in the .output folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"distDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"../.output/public"&lt;/span&gt;&lt;span class="w"&gt;    
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Completed
&lt;/h3&gt;

&lt;p&gt;Cool! So now you can run the build command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn tauri build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you aren’t using yarn then you can refer to other build commands &lt;a href="https://tauri.app/v1/guides/building/windows/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Remark
&lt;/h2&gt;

&lt;p&gt;To refer an actual project in the process, you can check out my github repo— &lt;a href="https://github.com/kinxyo/CooperAI"&gt;AI Therapist&lt;/a&gt; application.&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>tauri</category>
      <category>rust</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
