Skip to content

Commit 9e3a5af

Browse files
authored
Upgrade leptos template to version 0.7 (#694)
1 parent b0de149 commit 9e3a5af

File tree

14 files changed

+126
-109
lines changed

14 files changed

+126
-109
lines changed

templates/leptos/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
target
22
node_modules
33
.wrangler
4-
public/pkg
5-
build
4+
build

templates/leptos/Cargo.toml

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,69 @@ codegen-units = 1
1414
crate-type = ["cdylib"]
1515

1616
[dependencies]
17-
worker = { version="0.5.0", features=['http', 'axum', 'd1'], optional = true }
18-
axum = { version = "0.7", default-features = false, optional = true }
17+
axum = { version = "0.7", default-features = false, optional = true }
18+
console_error_panic_hook = "0.1"
19+
getrandom = { version = "0.2.15", features = ["js"]}
20+
leptos = { version = "0.7"{% if use_nightly %}, features = ["nightly"]{% endif %} }
21+
leptos_axum = { version = "0.7", default-features = false, features = ["wasm"], optional = true }
22+
leptos_meta = { version = "0.7" }
23+
leptos_router = { version = "0.7"{% if use_nightly %}, features = ["nightly"]{% endif %} }
1924
tower-service = "0.3"
20-
console_error_panic_hook = { version = "0.1" }
21-
console_log = { version = "1.0", optional = true }
22-
gloo-net = { version = "0.6", features = ["http"] }
23-
gloo-timers = { version = "0.3", features = ["futures"] }
24-
leptos = "0.6"
25-
leptos_axum = { version = "0.6", default-features = false, features = [
26-
"wasm",
27-
], optional = true }
28-
leptos_meta = "0.6"
29-
leptos_router = "0.6"
30-
leptos_dom = "0.6"
31-
log = "0.4"
32-
once_cell = "1.19"
33-
serde = { version = "1.0", features = ["derive"] }
34-
serde_json = "1.0"
35-
tower = { version = "0.5", optional = true }
36-
wasm-bindgen = { version = "0.2.92", optional = true }
37-
wasm-bindgen-futures = "0.4"
25+
wasm-bindgen = "=0.2.100"
26+
worker = { version = "0.5", features = ["http", "axum", "d1"], optional = true }
3827

3928
[features]
40-
hydrate = [
41-
"dep:console_log",
42-
"leptos/hydrate",
43-
"leptos_meta/hydrate",
44-
"leptos_router/hydrate",
45-
"leptos_dom/hydrate",
46-
"dep:wasm-bindgen",
47-
]
29+
hydrate = ["leptos/hydrate"]
4830
ssr = [
4931
"dep:axum",
32+
"dep:leptos_axum",
33+
"dep:worker",
5034
"leptos/ssr",
5135
"leptos_meta/ssr",
5236
"leptos_router/ssr",
53-
"leptos_dom/ssr",
54-
"dep:leptos_axum",
55-
"dep:worker",
5637
]
5738

5839
[package.metadata.leptos]
5940
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
60-
output-name = "leptos_worker"
61-
# The site root folder is where cargo-leptos generate all output. WARNING all content of this folder will be erased on a rebuild. Use it in your server setup.
62-
site-root = "public"
41+
output-name = "{{project-name}}"
42+
43+
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
44+
site-root = "target/site"
45+
6346
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
6447
# Defaults to pkg
6548
site-pkg-dir = "pkg"
49+
6650
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
67-
#style-file = "./style.css"
68-
# [Optional] Files in the asset-dir will be copied to the site-root directory
51+
style-file = "style/main.css"
52+
53+
# Assets source dir. All files found here will be copied and synchronized to site-root.
54+
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
55+
#
56+
# Optional. Env: LEPTOS_ASSETS_DIR.
6957
assets-dir = "assets"
58+
7059
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
7160
site-addr = "127.0.0.1:8787"
61+
7262
# The port to use for automatic reload monitoring
7363
reload-port = 3001
64+
7465
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
66+
# [Windows] for non-WSL use "npx.cmd playwright test"
67+
# This binary name can be checked in Powershell with Get-Command npx
7568
end2end-cmd = "cargo make test-ui"
76-
end2end-dir = "e2e"
69+
end2end-dir = "end2end"
70+
7771
# The browserlist query used for optimizing the CSS.
7872
browserquery = "defaults"
73+
7974
# Set by cargo-leptos watch when building with that tool. Controls whether autoreload JS will be included in the head
8075
watch = false
76+
8177
# The environment Leptos will run in, usually either "DEV" or "PROD"
8278
env = "DEV"
79+
8380
# The features to use when compiling the bin target
8481
#
8582
# Optional. Can be over-ridden with the command line parameter --bin-features
@@ -98,4 +95,4 @@ lib-features = ["hydrate"]
9895
# If the --no-default-features flag should be used when compiling the lib target
9996
#
10097
# Optional. Defaults to false.
101-
lib-default-features = false
98+
lib-default-features = false
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[template]
2-
exclude = ["*.ico"]
1+
[placeholders]
2+
use_nightly = { prompt = "Use nightly features?", default = false, type = "bool" }
-4.19 KB
Binary file not shown.

templates/leptos/src/api/mod.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

templates/leptos/src/api/say_hello.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

templates/leptos/src/app.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
1-
use leptos::*;
1+
use leptos::prelude::*;
2+
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet};
3+
use leptos_router::{
4+
components::{Route, Router, Routes},
5+
StaticSegment,
6+
};
27

38
use crate::components::show_data_from_api::ShowDataFromApi;
49

10+
pub fn shell(options: LeptosOptions) -> impl IntoView {
11+
view! {
12+
<!DOCTYPE html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="utf-8"/>
16+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
17+
<AutoReload options=options.clone() />
18+
<HydrationScripts options/>
19+
<MetaTags/>
20+
</head>
21+
<body>
22+
<App/>
23+
</body>
24+
</html>
25+
}
26+
}
27+
528
#[component]
629
pub fn App() -> impl IntoView {
30+
// Provides context that manages stylesheets, titles, meta tags, etc.
31+
provide_meta_context();
32+
33+
view! {
34+
// injects a stylesheet into the document <head>
35+
// id=leptos means cargo-leptos will hot-reload this stylesheet
36+
<Stylesheet id="leptos" href="/pkg/{{project-name}}.css"/>
37+
38+
// content for this welcome page
39+
<Router>
40+
<main>
41+
<Routes fallback=|| "Page not found.".into_view()>
42+
<Route path=StaticSegment("") view=HomePage/>
43+
</Routes>
44+
</main>
45+
</Router>
46+
}
47+
}
48+
49+
/// Renders the home page of your application.
50+
#[component]
51+
fn HomePage() -> impl IntoView {
752
view! {
853
<h1>"Hello world!"</h1>
954
<ShowDataFromApi />
1055
}
11-
}
56+
}

templates/leptos/src/components.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod show_data_from_api;

templates/leptos/src/components/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
use leptos::*;
1+
use leptos::prelude::*;
22

3-
use crate::api::say_hello::say_hello;
3+
#[server(SayHello)]
4+
pub async fn say_hello(num: i32) -> Result<String, ServerFnError> {
5+
Ok(format!("Hello from the API!!! I got {num}"))
6+
}
47

58
#[component]
69
pub fn ShowDataFromApi() -> impl IntoView {
7-
let value = create_rw_signal("".to_string());
8-
let counter = create_rw_signal(0);
10+
let value = RwSignal::new("".to_string());
11+
let counter = RwSignal::new(0);
912

1013
let on_click = move |_| {
11-
spawn_local(async move {
14+
leptos::task::spawn_local(async move {
1215
let api_said = say_hello(counter.get()).await.unwrap();
1316
value.set(api_said);
1417
counter.update(|v| *v += 1);
@@ -21,4 +24,4 @@ pub fn ShowDataFromApi() -> impl IntoView {
2124
<p>{value}</p>
2225
</div>
2326
}
24-
}
27+
}

0 commit comments

Comments
 (0)