DEV Community

Cover image for Cross-Platform application with Ruby + Tauri
Joseph Schito
Joseph Schito

Posted on

Cross-Platform application with Ruby + Tauri

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 👇

  1. Run sh <(curl https://create.tauri.app/sh)

  2. 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 Tauri setup
  3. 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
  4. 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" Tauri configuration
  5. Go to the window console (https://tauri.app/v1/guides/debugging/application/#webview-console),
    you should see Hello from Opal! 🥳
    Tauri application

Amazing uh? But... what next?

  • Add any .rb file in src/app and require it from src/main.rb, yeah that's it!
  • Build it with npm run tauri build

Build Space
Build ram

~6MB Space (notice that I didn't minify or optimize anything...)
~20-30MB Ram (this is crazy)

Joseph 😉

Resources:
Opal guides
Tauri guides

Top comments (0)