leptos/examples/hackernews
Greg Johnston c8f0988e53
Merge pull request #292 from gbj/router-warnings
Implement `state` and `replace` correctly in `leptos_router` and clear warnings
2023-01-09 21:11:28 -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 Merge pull request #292 from gbj/router-warnings 2023-01-09 21:11:28 -05:00
Cargo.toml Merge pull request #286 from benwis/favicons 2023-01-09 19:57:27 -05:00
index.html Updated hacker news example to new SFA format and added a README 2022-11-14 09:03:44 -08:00
LICENSE Updated hacker news example to new SFA format and added a README 2022-11-14 09:03:44 -08:00
Makefile.toml Add build-examples task to cargo make CI 2023-01-02 13:29:37 -05:00
README.md Bugfixes, using cargo-leptos for CSS, and updating READMEs. 2022-12-31 18:39:05 -08:00
style.css Updated hacker news example to new SFA format and added a README 2022-11-14 09:03:44 -08:00

Leptos Hacker News Example

This example creates a basic clone of the Hacker News site. It showcases Leptos' ability to create both a client-side rendered app, and a server side rendered app with hydration, in a single repository

Client Side Rendering

To run it as a Client Side App, you can issue trunk serve --open in the root. This will build the entire app into one CSR bundle. Make sure you have trunk installed with cargo install trunk.

Server Side Rendering with cargo-leptos

cargo-leptos is now the easiest and most featureful way to build server side rendered apps with hydration. It provides automatic recompilation of client and server code, wasm optimisation, CSS minification, and more! Check out more about it here

  1. Install cargo-leptos
cargo install --locked cargo-leptos
  1. Build the site in watch mode, recompiling on file changes
cargo leptos watch
  1. When ready to deploy, run
cargo leptos build --release

Server Side Rendering without cargo-leptos

To run it as a server side app with hydration, you'll need to have wasm-pack installed.

  1. Edit the [package.metadata.leptos] section and set site-root to "pkg". 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.
  2. Install wasm-pack
cargo install wasm-pack
  1. Build the Webassembly used to hydrate the HTML from the server
wasm-pack build --target=web --debug --no-default-features --features=hydrate
  1. Run the server to serve the Webassembly, JS, and HTML
cargo run --no-default-features --features=ssr