- Install the Dioxus CLI:
cargo install dioxus-cliMake sure the wasm32-unknown-unknown target for rust is installed:
rustup target add wasm32-unknown-unknown- Install npm: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
- Install the tailwind css cli: https://tailwindcss.com/docs/installation
- Initialize the tailwind css project:
npx tailwindcss initCreate frontend crate:
cargo new --bin demo
cd demoAdd Dioxus and the web renderer as dependencies (this will edit your Cargo.toml):
cargo add dioxus
cargo add dioxus-webThis should create a tailwind.config.js file in the root of the project.
- Edit the
tailwind.config.jsfile 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: [],
}- Create a
input.cssfile with the following content:
@tailwind base;
@tailwind components;
@tailwind utilities;- Create a
Dioxus.tomlfile with the following content that links to thetailwind.cssfile:
[application]
# App (Project) Name
name = "Rusty Films"
# 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 = "🦀 | Rusty Films"
[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 = []- Install the tailwind css vs code extension
- 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"
},- 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- Run the following command in the root of the project to start the dioxus dev server:
dioxus serve --port 8000- Open the browser to http://localhost:8000