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
18
Cargo.toml
18
Cargo.toml
|
@ -16,26 +16,12 @@ members = [
|
|||
"meta",
|
||||
"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
|
||||
"docs/book/project/ch02_getting_started",
|
||||
"docs/book/project/ch03_building_ui",
|
||||
"docs/book/project/ch04_reactivity",
|
||||
]
|
||||
exclude = ["benchmarks"]
|
||||
exclude = ["benchmarks", "examples"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
|
@ -43,4 +29,4 @@ lto = true
|
|||
opt-level = 'z'
|
||||
|
||||
[workspace.metadata.cargo-all-features]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "leptos_counter_isomorphic"
|
||||
name = "counter_isomorphic"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -46,16 +46,16 @@ skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
|||
|
||||
[package.metadata.leptos]
|
||||
# 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.
|
||||
site-root = "/pkg"
|
||||
site-root = "target/site"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to 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
|
||||
# style-file = "src/styles/tailwind.css"
|
||||
# [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.
|
||||
site-address = "127.0.0.1:3000"
|
||||
# The port to use for automatic reload monitoring
|
|
@ -31,12 +31,17 @@ cfg_if! {
|
|||
async fn main() -> std::io::Result<()> {
|
||||
crate::counters::register_server_functions();
|
||||
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();
|
||||
|
||||
HttpServer::new(move || {
|
||||
let leptos_options = &conf.leptos_options;
|
||||
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)
|
||||
.route("/api/{tail:.*}", leptos_actix::handle_server_fns())
|
||||
.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]
|
||||
name = "leptos_hackernews"
|
||||
name = "hackernews"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -45,17 +45,11 @@ ssr = [
|
|||
denylist = ["actix-files", "actix-web", "leptos_actix"]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[[workspace.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"
|
||||
[package.metadata.leptos]
|
||||
# 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.
|
||||
site-root = "pkg"
|
||||
site-root = "site/target"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to pkg
|
||||
site-pkg-dir = "pkg"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use cfg_if::cfg_if;
|
||||
use leptos::{component, provide_context, view, IntoView, Scope};
|
||||
use leptos::{component, view, IntoView, Scope};
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
mod api;
|
||||
|
@ -11,7 +11,7 @@ use routes::users::*;
|
|||
|
||||
#[component]
|
||||
pub fn App(cx: Scope) -> impl IntoView {
|
||||
provide_context(cx, MetaContext::default());
|
||||
provide_meta_context(cx);
|
||||
view! {
|
||||
cx,
|
||||
<>
|
||||
|
|
|
@ -7,7 +7,7 @@ cfg_if! {
|
|||
if #[cfg(feature = "ssr")] {
|
||||
use actix_files::{Files};
|
||||
use actix_web::*;
|
||||
use leptos_hackernews::*;
|
||||
use hackernews::{App,AppProps};
|
||||
|
||||
#[get("/style.css")]
|
||||
async fn css() -> impl Responder {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "leptos_hackernews_axum"
|
||||
name = "hackernews_axum"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -53,15 +53,9 @@ ssr = [
|
|||
denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[[workspace.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"
|
||||
[package.metadata.leptos]
|
||||
# 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.
|
||||
site-root = "site/target"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
|
@ -1,7 +1,5 @@
|
|||
[workspace]
|
||||
|
||||
[package]
|
||||
name = "leptos_tailwind_example"
|
||||
name = "tailwind"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -79,9 +77,9 @@ opt-level = 'z'
|
|||
|
||||
[package.metadata.leptos]
|
||||
# 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.
|
||||
site-root = "/pkg"
|
||||
site-root = "target/site"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to pkg
|
||||
site-pkg-dir = "pkg"
|
||||
|
|
|
@ -3,9 +3,8 @@ use leptos_meta::*;
|
|||
|
||||
#[component]
|
||||
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);
|
||||
|
||||
view! {
|
||||
cx,
|
||||
<main class="my-0 mx-auto max-w-3xl text-center">
|
||||
|
|
|
@ -9,15 +9,14 @@ cfg_if! {
|
|||
|
||||
#[wasm_bindgen]
|
||||
pub fn hydrate() {
|
||||
console_error_panic_hook::set_once();
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
console_error_panic_hook::set_once();
|
||||
console_error_panic_hook::set_once();
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
|
||||
log!("hydrate mode - hydrating");
|
||||
log!("hydrate mode - hydrating");
|
||||
|
||||
leptos::hydrate(body().unwrap(), |cx| {
|
||||
view! { cx, <App/> }
|
||||
});
|
||||
leptos::mount_to_body(|cx| {
|
||||
view! { cx, <App/> }
|
||||
});
|
||||
}
|
||||
}
|
||||
else if #[cfg(feature = "csr")] {
|
||||
|
|
|
@ -18,11 +18,17 @@ cfg_if! {
|
|||
async fn main() -> std::io::Result<()> {
|
||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||
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 || {
|
||||
let leptos_options = &conf.leptos_options;
|
||||
App::new()
|
||||
.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/> }))
|
||||
.wrap(middleware::Compress::default())
|
||||
})
|
||||
|
|
|
@ -47,13 +47,7 @@ ssr = [
|
|||
denylist = ["actix-files", "actix-web", "leptos_actix", "sqlx"]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[[workspace.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"
|
||||
[package.metadata.leptos]
|
||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||
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.
|
|
@ -25,6 +25,7 @@ cfg_if! {
|
|||
|
||||
crate::todo::register_server_functions();
|
||||
|
||||
|
||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||
let addr = conf.leptos_options.site_address.clone();
|
||||
|
|
@ -61,13 +61,7 @@ denylist = [
|
|||
]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[[workspace.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"
|
||||
[package.metadata.leptos]
|
||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||
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.
|
|
@ -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)?,
|
||||
None => fs::read_to_string("Cargo.toml").map_err(|_| LeptosConfigError::ConfigNotFound)?,
|
||||
};
|
||||
// text = text.replace("[[workspace.metadata.leptos]]", "[package.metadata.leptos]");
|
||||
|
||||
let re: Regex =
|
||||
Regex::new(r#"(?m)^\[package.metadata.leptos\]|(?m)^\[\[workspace.metadata.leptos\]\]"#)
|
||||
|
|
|
@ -20,6 +20,4 @@ futures = "0.3"
|
|||
[features]
|
||||
default = ["ssr"]
|
||||
ssr = ["leptos/ssr", "dep:actix-files", "dep:actix-web"]
|
||||
hydrate = ["leptos/hydrate", "dep:wasm-bindgen", "dep:gloo"]
|
||||
|
||||
[workspace]
|
||||
hydrate = ["leptos/hydrate", "dep:wasm-bindgen", "dep:gloo"]
|
|
@ -3,8 +3,6 @@ name = "test-bench"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
console_error_panic_hook = "0.1"
|
||||
gloo = { version = "0.8", features = ["futures"] }
|
||||
|
|
|
@ -47,3 +47,4 @@ miniserde = ["dep:miniserde"]
|
|||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["stable"]
|
||||
|
||||
|
|
|
@ -25,3 +25,5 @@ stable = ["leptos/stable"]
|
|||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["stable"]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue