dioxus/examples/tailwind
2024-01-16 08:42:16 -06:00
..
dist show off the new asset system in the examples 2023-12-17 11:45:27 -06:00
public create complete tailwind example project with steps to setup tailwind 2023-03-26 11:29:56 -05:00
src implement launch builder for the desktop and web platforms 2024-01-16 08:42:16 -06:00
Cargo.toml Pin assets sha to keep CI in check 2024-01-08 14:54:02 -08:00
Dioxus.toml show off the new asset system in the examples 2023-12-17 11:45:27 -06:00
input.css create complete tailwind example project with steps to setup tailwind 2023-03-26 11:29:56 -05:00
README.md Updated packages and comments referencing old CLI location (#1786) 2024-01-04 18:41:05 -06:00
tailwind.config.js create complete tailwind example project with steps to setup tailwind 2023-03-26 11:29:56 -05:00

Example: Basic Tailwind usage

This example shows how an app might be styled with TailwindCSS.

Setup

  1. Install the Dioxus CLI:
cargo install dioxus-cli
  1. Install npm: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
  2. Install the tailwind css cli: https://tailwindcss.com/docs/installation
  3. Initialize the tailwind css project:
npx tailwindcss init

This should create a tailwind.config.js file in the root of the project.

  1. Edit the tailwind.config.js file to include rust files:
module.exports = {
    mode: "all",
    content: [
        // include all rust, html and css files in the src directory
        "./src/**/*.{rs,html,css}",
        // include all html files in the output (dist) directory
        "./dist/**/*.html",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
}
  1. Create a input.css file with the following content:
@tailwind base;
@tailwind components;
@tailwind utilities;
  1. Create a Dioxus.toml file with the following content that links to the tailwind.css file:
[application]

# App (Project) Name
name = "Tailwind CSS + Dioxus"

# Dioxus App Default Platform
# desktop, web, mobile, ssr
default_platform = "web"

# `build` & `serve` dist path
out_dir = "dist"

# resource (public) file folder
asset_dir = "public"

[web.app]

# HTML title tag content
title = "dioxus | ⛺"

[web.watcher]

# when watcher trigger, regenerate the `index.html`
reload_html = true

# which files or dirs will be watcher monitoring
watch_path = ["src", "public"]

# include `assets` in web platform
[web.resource]

# CSS style file
style = ["/tailwind.css"]

# Javascript code file
script = []

[web.resource.dev]

# serve: [dev-server] only

# CSS style file
style = []

# Javascript code file
script = []

Bonus Steps

  1. Install the tailwind css vs code extension
  2. Go to the settings for the extension and find the experimental regex support section. Edit the setting.json file to look like this:
"tailwindCSS.experimental.classRegex": ["class: \"(.*)\""],
"tailwindCSS.includeLanguages": {
    "rust": "html"
},

Development

  1. Run the following command in the root of the project to start the tailwind css compiler:
npx tailwindcss -i ./input.css -o ./public/tailwind.css --watch

Web

  • Run the following command in the root of the project to start the dioxus dev server:
dx serve --hot-reload

Desktop

  • Launch the dioxus desktop app
cargo run