Giter Site home page Giter Site logo

tauri-next-boilerplate's Introduction

Tauri + NextJS

A boilerplate project for a Tauri app with a NextJS 13 front-end.

Note that this project deviates from the current Tauri guide in a few places:

  1. As of Next 13 we can now use the app folder as recommended by the Next team.
  2. Adding next export to package.json is no longer required, and the recommended way is to add output: export to `next.config.js instead.

TODO

  1. Check if we really need to have the "use client" flag with new Next 13 way of doing SSR
  2. Add stitches.dev for styling with CSS-in-JS
  3. Splash-screen
  4. Some cooler Icons?
  5. See if we can make the GreetingArg struct work with &str argument for name

Development

To run the program in development, use the following command from the project root folder:

npm run tauri dev

Shared Types and Commands

Tauri lets you enhance your frontend with native capabilities. We call these Commands, essentially Rust functions that you can call from your frontend JavaScript. This enables you to handle heavy processing or calls to the OS in much more performant Rust code.

This boilerplate project has one such command found in src/main.rs, and we are calling this command from our NextJS app inside app/page.tsx via the wrapper function inside api/greeter.ts. If we call the invoke() function from the Tauri SDK directly inside our pages, then we will not get code-completion on the available Commands and their associated types. Putting the invoke-call inside a wrapper-function solves this.

It would also be nice to be able to get types for Enums and Structs we might define inside our Rust code available for our type-script code as well. To do this, we have Typeshare added as a crate to the project, so types can be generated from the Rust code by running:

npm run typeshare

This will update the types.ts file inside the ./api/ folder, and expose the exported types via the @types path.

Include the #[typeshare] attribute with any struct or enum you define to generate type definitions:

// Rust type definitions

#[typeshare]
struct MyStruct {
    my_name: String,
    my_age: u32,
}

#[typeshare]
#[serde(tag = "type", content = "content")]
enum MyEnum {
    MyVariant(bool),
    MyOtherVariant,
    MyNumber(u32),
}
// Generated Typescript definitions

export interface MyStruct {
  my_name: string;
  my_age: number;
}

export type MyEnum =
  | { type: "MyVariant", content: boolean }
  | { type: "MyOtherVariant", content: undefined }
  | { type: "MyNumber", content: number };

NextJS

This project uses the app folder and router introduced in Next 13. To start editing the Next pages, start by modifying app/page.tsx.

This project uses next/font to automatically optimize and load Inter, a custom Google Font.

Tauri

It's a convention for Tauri apps to place all core-related files into the src-tauri folder. Inside you will also see the src sub-folder, and this is where all the Rust code lives, with src/main.rs being the entry point to your Rust program and the place where we bootstrap into Tauri.

Learn More

To learn more about Rust, take a look at:

To learn more about Next.js, take a look at the following resources:

tauri-next-boilerplate's People

Contributors

jkhoel avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.