mirror of
https://github.com/leptos-rs/leptos
synced 2024-09-20 06:21:57 +00:00
Move the examples out of the workspace, and standardize naming. All of the SSR examples now work with cargo-leptos
This commit is contained in:
parent
60f0bf23fd
commit
f45d33db73
61 changed files with 46 additions and 85 deletions
16
Cargo.toml
16
Cargo.toml
|
@ -16,26 +16,12 @@ members = [
|
||||||
"meta",
|
"meta",
|
||||||
"router",
|
"router",
|
||||||
|
|
||||||
# examples
|
|
||||||
"examples/counter",
|
|
||||||
"examples/counter-isomorphic",
|
|
||||||
"examples/counters",
|
|
||||||
"examples/counters-stable",
|
|
||||||
"examples/fetch",
|
|
||||||
"examples/hackernews",
|
|
||||||
"examples/hackernews-axum",
|
|
||||||
"examples/parent-child",
|
|
||||||
"examples/router",
|
|
||||||
"examples/todomvc",
|
|
||||||
"examples/todo-app-sqlite",
|
|
||||||
"examples/todo-app-sqlite-axum",
|
|
||||||
|
|
||||||
# book
|
# book
|
||||||
"docs/book/project/ch02_getting_started",
|
"docs/book/project/ch02_getting_started",
|
||||||
"docs/book/project/ch03_building_ui",
|
"docs/book/project/ch03_building_ui",
|
||||||
"docs/book/project/ch04_reactivity",
|
"docs/book/project/ch04_reactivity",
|
||||||
]
|
]
|
||||||
exclude = ["benchmarks"]
|
exclude = ["benchmarks", "examples"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "leptos_counter_isomorphic"
|
name = "counter_isomorphic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -46,16 +46,16 @@ skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||||
|
|
||||||
[package.metadata.leptos]
|
[package.metadata.leptos]
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "leptos_counter_isomorphic"
|
output-name = "counter_isomorphic"
|
||||||
# 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.
|
# 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.
|
||||||
site-root = "/pkg"
|
site-root = "target/site"
|
||||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||||
# Defaults to pkg
|
# Defaults to pkg
|
||||||
site-pkg-dir = "pkg"
|
site-pkg-dir = "pkg"
|
||||||
# [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
|
# [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
|
||||||
# style-file = "src/styles/tailwind.css"
|
# style-file = "src/styles/tailwind.css"
|
||||||
# [Optional] Files in the asset-dir will be copied to the site-root directory
|
# [Optional] Files in the asset-dir will be copied to the site-root directory
|
||||||
assets-dir = "static/assets"
|
# assets-dir = "static/assets"
|
||||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||||
site-address = "127.0.0.1:3000"
|
site-address = "127.0.0.1:3000"
|
||||||
# The port to use for automatic reload monitoring
|
# The port to use for automatic reload monitoring
|
|
@ -31,12 +31,17 @@ cfg_if! {
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
crate::counters::register_server_functions();
|
crate::counters::register_server_functions();
|
||||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||||
|
let leptos_options = &conf.leptos_options;
|
||||||
|
let site_root = &leptos_options.site_root;
|
||||||
|
let pkg_dir = &leptos_options.site_pkg_dir;
|
||||||
|
let bundle_path = format!("/{site_root}/{pkg_dir}");
|
||||||
let addr = conf.leptos_options.site_address.clone();
|
let addr = conf.leptos_options.site_address.clone();
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let leptos_options = &conf.leptos_options;
|
let leptos_options = &conf.leptos_options;
|
||||||
App::new()
|
App::new()
|
||||||
.service(Files::new("/pkg", "./pkg"))
|
.service(Files::new("/pkg", "./pkg")) // used by wasm-pack and cargo run. Can be removed if using cargo-leptos
|
||||||
|
.service(Files::new(&bundle_path, format!("./{bundle_path}"))) // used by cargo-leptos. Can be removed if using wasm-pack and cargo run.
|
||||||
.service(counter_events)
|
.service(counter_events)
|
||||||
.route("/api/{tail:.*}", leptos_actix::handle_server_fns())
|
.route("/api/{tail:.*}", leptos_actix::handle_server_fns())
|
||||||
.route("/{tail:.*}", leptos_actix::render_app_to_stream(leptos_options.to_owned(), |cx| view! { cx, <Counters/> }))
|
.route("/{tail:.*}", leptos_actix::render_app_to_stream(leptos_options.to_owned(), |cx| view! { cx, <Counters/> }))
|
|
@ -1,7 +0,0 @@
|
||||||
// This file is auto-generated. Changing it will have no effect on leptos. Change these by changing RenderOptions and rerunning
|
|
||||||
RenderOptions {
|
|
||||||
pkg-path "/pkg/leptos_hackernews"
|
|
||||||
environment "PROD"
|
|
||||||
socket-address "127.0.0.1:3000"
|
|
||||||
reload-port 3001
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "leptos_hackernews"
|
name = "hackernews"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -45,17 +45,11 @@ ssr = [
|
||||||
denylist = ["actix-files", "actix-web", "leptos_actix"]
|
denylist = ["actix-files", "actix-web", "leptos_actix"]
|
||||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||||
|
|
||||||
[[workspace.metadata.leptos]]
|
[package.metadata.leptos]
|
||||||
# The name of your leptos package
|
|
||||||
name = "leptos_hackernews"
|
|
||||||
# The name of the leptos server/bin package. Can be different from your lib package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
bin-package = "leptos_hackernews"
|
|
||||||
# The name of the leptos frontend/lib package. Can be different from your bin package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
lib-package = "leptos_hackernews"
|
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "leptos_hackernews"
|
output-name = "hackernews"
|
||||||
# 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.
|
# 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.
|
||||||
site-root = "pkg"
|
site-root = "site/target"
|
||||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||||
# Defaults to pkg
|
# Defaults to pkg
|
||||||
site-pkg-dir = "pkg"
|
site-pkg-dir = "pkg"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use leptos::{component, provide_context, view, IntoView, Scope};
|
use leptos::{component, view, IntoView, Scope};
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use leptos_router::*;
|
use leptos_router::*;
|
||||||
mod api;
|
mod api;
|
||||||
|
@ -11,7 +11,7 @@ use routes::users::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App(cx: Scope) -> impl IntoView {
|
pub fn App(cx: Scope) -> impl IntoView {
|
||||||
provide_context(cx, MetaContext::default());
|
provide_meta_context(cx);
|
||||||
view! {
|
view! {
|
||||||
cx,
|
cx,
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -7,7 +7,7 @@ cfg_if! {
|
||||||
if #[cfg(feature = "ssr")] {
|
if #[cfg(feature = "ssr")] {
|
||||||
use actix_files::{Files};
|
use actix_files::{Files};
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use leptos_hackernews::*;
|
use hackernews::{App,AppProps};
|
||||||
|
|
||||||
#[get("/style.css")]
|
#[get("/style.css")]
|
||||||
async fn css() -> impl Responder {
|
async fn css() -> impl Responder {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "leptos_hackernews_axum"
|
name = "hackernews_axum"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -53,15 +53,9 @@ ssr = [
|
||||||
denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
|
denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
|
||||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||||
|
|
||||||
[[workspace.metadata.leptos]]
|
[package.metadata.leptos]
|
||||||
# The name of your leptos package
|
|
||||||
name = "leptos_hackernews_axum"
|
|
||||||
# The name of the leptos server/bin package. Can be different from your lib package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
bin-package = "leptos_hackernews_axum"
|
|
||||||
# The name of the leptos frontend/lib package. Can be different from your bin package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
lib-package = "leptos_hackernews_axum"
|
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "leptos_hackernews_axum"
|
output-name = "hackernews_axum"
|
||||||
# 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.
|
# 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.
|
||||||
site-root = "site/target"
|
site-root = "site/target"
|
||||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
|
@ -1,7 +1,5 @@
|
||||||
[workspace]
|
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "leptos_tailwind_example"
|
name = "tailwind"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -79,9 +77,9 @@ opt-level = 'z'
|
||||||
|
|
||||||
[package.metadata.leptos]
|
[package.metadata.leptos]
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "leptos_tailwind_example"
|
output-name = "tailwind"
|
||||||
# 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.
|
# 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.
|
||||||
site-root = "/pkg"
|
site-root = "target/site"
|
||||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||||
# Defaults to pkg
|
# Defaults to pkg
|
||||||
site-pkg-dir = "pkg"
|
site-pkg-dir = "pkg"
|
||||||
|
|
|
@ -3,9 +3,8 @@ use leptos_meta::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App(cx: Scope) -> impl IntoView {
|
pub fn App(cx: Scope) -> impl IntoView {
|
||||||
provide_context(cx, MetaContext::default());
|
provide_context(cx, MetaContext::new());
|
||||||
let (count, set_count) = create_signal(cx, 0);
|
let (count, set_count) = create_signal(cx, 0);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
cx,
|
cx,
|
||||||
<main class="my-0 mx-auto max-w-3xl text-center">
|
<main class="my-0 mx-auto max-w-3xl text-center">
|
||||||
|
|
|
@ -11,11 +11,10 @@ cfg_if! {
|
||||||
pub fn hydrate() {
|
pub fn hydrate() {
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
_ = console_log::init_with_level(log::Level::Debug);
|
_ = console_log::init_with_level(log::Level::Debug);
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
|
|
||||||
log!("hydrate mode - hydrating");
|
log!("hydrate mode - hydrating");
|
||||||
|
|
||||||
leptos::hydrate(body().unwrap(), |cx| {
|
leptos::mount_to_body(|cx| {
|
||||||
view! { cx, <App/> }
|
view! { cx, <App/> }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,17 @@ cfg_if! {
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||||
let addr = conf.leptos_options.site_address.clone();
|
let addr = conf.leptos_options.site_address.clone();
|
||||||
|
let leptos_options = &conf.leptos_options;
|
||||||
|
let site_root = &leptos_options.site_root;
|
||||||
|
let pkg_dir = &leptos_options.site_pkg_dir;
|
||||||
|
let bundle_path = format!("/{site_root}/{pkg_dir}");
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let leptos_options = &conf.leptos_options;
|
let leptos_options = &conf.leptos_options;
|
||||||
App::new()
|
App::new()
|
||||||
.service(css)
|
.service(css)
|
||||||
.service(Files::new("/pkg", "./pkg"))
|
.service(Files::new("/pkg", "./pkg")) // used by wasm-pack and cargo run. Can be removed if using cargo-leptos
|
||||||
|
.service(Files::new(&bundle_path, format!("./{bundle_path}"))) // used by cargo-leptos. Can be removed if using wasm-pack and cargo run.
|
||||||
.route("/{tail:.*}", leptos_actix::render_app_to_stream(leptos_options.to_owned(), |cx| view! { cx, <App/> }))
|
.route("/{tail:.*}", leptos_actix::render_app_to_stream(leptos_options.to_owned(), |cx| view! { cx, <App/> }))
|
||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,13 +47,7 @@ ssr = [
|
||||||
denylist = ["actix-files", "actix-web", "leptos_actix", "sqlx"]
|
denylist = ["actix-files", "actix-web", "leptos_actix", "sqlx"]
|
||||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||||
|
|
||||||
[[workspace.metadata.leptos]]
|
[package.metadata.leptos]
|
||||||
# The name of your leptos package
|
|
||||||
name = "todo_app_sqlite"
|
|
||||||
# The name of the leptos server/bin package. Can be different from your lib package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
bin-package = "todo_app_sqlite"
|
|
||||||
# The name of the leptos frontend/lib package. Can be different from your bin package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
lib-package = "todo_app_sqlite"
|
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "todo_app_sqlite"
|
output-name = "todo_app_sqlite"
|
||||||
# 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.
|
# 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.
|
|
@ -25,6 +25,7 @@ cfg_if! {
|
||||||
|
|
||||||
crate::todo::register_server_functions();
|
crate::todo::register_server_functions();
|
||||||
|
|
||||||
|
|
||||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||||
let addr = conf.leptos_options.site_address.clone();
|
let addr = conf.leptos_options.site_address.clone();
|
||||||
|
|
|
@ -61,13 +61,7 @@ denylist = [
|
||||||
]
|
]
|
||||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||||
|
|
||||||
[[workspace.metadata.leptos]]
|
[package.metadata.leptos]
|
||||||
# The name of your app
|
|
||||||
name = "todo_app_sqlite_axum"
|
|
||||||
# The name of the leptos server/bin package. Can be different from your lib package if they are in different crates. Otherwise, can be the same
|
|
||||||
bin-package = "todo_app_sqlite_axum"
|
|
||||||
# The name of the leptos frontend/lib package. Can be different from your bin package if they are in different crates. Otherwise, they'd be the same
|
|
||||||
lib-package = "todo_app_sqlite_axum"
|
|
||||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||||
output-name = "todo_app_sqlite_axum"
|
output-name = "todo_app_sqlite_axum"
|
||||||
# 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.
|
# 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.
|
|
@ -133,7 +133,6 @@ pub async fn get_configuration(path: Option<&str>) -> Result<ConfFile, LeptosCon
|
||||||
Some(p) => fs::read_to_string(p).map_err(|_| LeptosConfigError::ConfigNotFound)?,
|
Some(p) => fs::read_to_string(p).map_err(|_| LeptosConfigError::ConfigNotFound)?,
|
||||||
None => fs::read_to_string("Cargo.toml").map_err(|_| LeptosConfigError::ConfigNotFound)?,
|
None => fs::read_to_string("Cargo.toml").map_err(|_| LeptosConfigError::ConfigNotFound)?,
|
||||||
};
|
};
|
||||||
// text = text.replace("[[workspace.metadata.leptos]]", "[package.metadata.leptos]");
|
|
||||||
|
|
||||||
let re: Regex =
|
let re: Regex =
|
||||||
Regex::new(r#"(?m)^\[package.metadata.leptos\]|(?m)^\[\[workspace.metadata.leptos\]\]"#)
|
Regex::new(r#"(?m)^\[package.metadata.leptos\]|(?m)^\[\[workspace.metadata.leptos\]\]"#)
|
||||||
|
|
|
@ -21,5 +21,3 @@ futures = "0.3"
|
||||||
default = ["ssr"]
|
default = ["ssr"]
|
||||||
ssr = ["leptos/ssr", "dep:actix-files", "dep:actix-web"]
|
ssr = ["leptos/ssr", "dep:actix-files", "dep:actix-web"]
|
||||||
hydrate = ["leptos/hydrate", "dep:wasm-bindgen", "dep:gloo"]
|
hydrate = ["leptos/hydrate", "dep:wasm-bindgen", "dep:gloo"]
|
||||||
|
|
||||||
[workspace]
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ name = "test-bench"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[workspace]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = "0.1"
|
||||||
gloo = { version = "0.8", features = ["futures"] }
|
gloo = { version = "0.8", features = ["futures"] }
|
||||||
|
|
|
@ -47,3 +47,4 @@ miniserde = ["dep:miniserde"]
|
||||||
|
|
||||||
[package.metadata.cargo-all-features]
|
[package.metadata.cargo-all-features]
|
||||||
denylist = ["stable"]
|
denylist = ["stable"]
|
||||||
|
|
||||||
|
|
|
@ -25,3 +25,5 @@ stable = ["leptos/stable"]
|
||||||
|
|
||||||
[package.metadata.cargo-all-features]
|
[package.metadata.cargo-all-features]
|
||||||
denylist = ["stable"]
|
denylist = ["stable"]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue