leptos/examples/tailwind
agilarity 9997487a9c
test: lint examples with --all-features (#1008)
* test: lint all features

* fix(counter_isomorphic): check-style issues

* fix(errors_axum): check-style issues

* fix(hackernews): check-style issues

* fix(hackernews_axum): check-style issues

* fix(session_auth_axum): check-style issues

* build(session_auth_axum): add common tasks

* fix(ssr_modes): check-style issues

* build(ssr_modes_axum): add common tasks

* fix(ssr_modes_axum): check-style issues

* build(tailwind): add common tasks

* fix(tailwind): check-style issues

* fix(todo_app_sqlite_axum): check-style issues

* fix(todo_app_sqlite_viz): check-style issues
2023-05-05 22:25:29 -04:00
..
end2end Tailwind example ported 2022-12-23 13:10:45 -05:00
public Add Favicons to all the examples and standardize on the public folder for public assets 2023-01-09 15:27:52 -08:00
src test: lint examples with --all-features (#1008) 2023-05-05 22:25:29 -04:00
style feat: add fragment support for hot reloading and fix some stuff (#659) 2023-03-11 07:21:37 -05:00
.gitignore Tailwind example ported 2022-12-23 13:10:45 -05:00
Cargo.toml chore: Upgrade console_log to stable (#724) 2023-03-22 18:21:53 -04:00
LICENSE Tailwind example ported 2022-12-23 13:10:45 -05:00
Makefile.toml test: lint examples with --all-features (#1008) 2023-05-05 22:25:29 -04:00
README.md doc: add link for leptos watch 2023-01-20 20:14:09 +01:00
input.css Tailwind example ported 2022-12-23 13:10:45 -05:00
tailwind.config.js Tailwind example ported 2022-12-23 13:10:45 -05:00

README.md

Leptos Starter Template

This is a template demonstrating how to integrate TailwindCSS with the Leptos web framework and the cargo-leptos tool.

If you don't have cargo-leptos installed you can install it with

cargo install --locked cargo-leptos

Then run

npx tailwindcss -i ./input.css -o ./style/output.css --watch

and

cargo leptos watch

in this directory.

Open browser on http://localhost:3000/

You can begin editing your app at src/app.rs.

Installing Tailwind

You can install Tailwind using npm:

npm install -D tailwindcss

If you'd rather not use npm, you can install the Tailwind binary here.

Setting up with VS Code and Additional Tools

If you're using VS Code, add the following to your settings.json

  "emmet.includeLanguages": {
    "rust": "html",
    "*.rs": "html"
  },
  "tailwindCSS.includeLanguages": {
      "rust": "html",
      "*.rs": "html"
  },
  "files.associations": {
      "*.rs": "rust"
  },
  "editor.quickSuggestions": {
    "other": "on",
    "comments": "on",
    "strings": true
  },
  "css.validate": false,

Install Tailwind CSS Intellisense.

Install "VS Browser" extension, a browser at the right window.
Allow vscode Ports forward: 3000, 3001.

Notes about Tooling

By default, cargo-leptos uses nightly Rust, cargo-generate, and sass. If you run into any trouble, you may need to install one or more of these tools.

  1. rustup toolchain install nightly --allow-downgrade - make sure you have Rust nightly
  2. rustup default nightly - setup nightly as default, or you can use rust-toolchain file later on
  3. rustup target add wasm32-unknown-unknown - add the ability to compile Rust to WebAssembly
  4. cargo install cargo-generate - install cargo-generate binary (should be installed automatically in future)
  5. npm install -g sass - install dart-sass (should be optional in future

Alternatives to cargo-leptos

This crate can be run without cargo-leptos, using wasm-pack and cargo. To do so, you'll need to install some other tools. 0. cargo install wasm-pack

  1. Edit the [package.metadata.leptos] section and set site-root to ".". You'll also want to change the path of the <StyleSheet / > component in the root component to point towards the CSS file in the root. This tells leptos that the WASM/JS files generated by wasm-pack are available at ./pkg and that the CSS files are no longer processed by cargo-leptos. Building to alternative folders is not supported at this time. You'll also want to edit the call to get_configuration() to pass in Some(Cargo.toml), so that Leptos will read the settings instead of cargo-leptos. If you do so, your file/folder names cannot include dashes.

Server Side Rendering With Hydration

To run it as a server side app with hydration, first you should run

wasm-pack build --target=web --no-default-features --features=hydrate

to generate the WebAssembly to hydrate the HTML delivered from the server.

Then run the server with cargo run to serve the server side rendered HTML and the WASM bundle for hydration.

cargo run --no-default-features --features=ssr

Note that if your hydration code changes, you will have to rerun the wasm-pack command above before running cargo run

Client Side Rendering

You'll need to install trunk to client side render this bundle.

  1. cargo install trunk Then the site can be served with trunk serve --open

Attribution

Many thanks to GreatGreg for putting together this guide. You can find the original, with added details, here.