Cross-Platform application with Ruby + Tauri
Joseph Schito
Posted on January 25, 2024
Is there any way to create a cross-platform client application that consumes a fraction of resources than Electron would use... with Ruby? 🤯
TLDR;
yes, this is the way 👇
Run
sh <(curl https://create.tauri.app/sh)
-
Set:
-
Project name:
your-project
(what you want) -
Choose which language to use for your frontend:
"TypeScript / JavaScript"
-
Choose your package manager:
npm
(what you want) -
Choose your UI template:
Vanilla
-
Choose your UI flavor:
JavaScript
-
Project name:
-
Run:
gem install opal
cd your-project
echo "puts 'Hello from Opal!'" | cat > src/main.rb
- open
src/index.html
file and move<script type="module" src="/main.js" defer></script>
line to the bottom mkdir src/app
npm install
npm run tauri dev
-
Edit
src-tauri/tauri.conf.json
:- set
beforeDevCommand
with"opal --output=src/main.js --watch -c src/main.rb -I src/app"
- set
beforeBuildCommand
with"opal -c src/main.rb --output=src/main.js --no-source-map -I src/app"
- set
Go to the window console (https://tauri.app/v1/guides/debugging/application/#webview-console),
you should seeHello from Opal!
🥳
Amazing uh? But... what next?
- Add any
.rb
file insrc/app
and require it fromsrc/main.rb
, yeah that's it! - Build it with
npm run tauri build
~6MB Space (notice that I didn't minify or optimize anything...)
~20-30MB Ram (this is crazy)
Joseph 😉
Resources:
Opal guides
Tauri guides
💖 💪 🙅 🚩
Joseph Schito
Posted on January 25, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.