generated from alecodes/base-template
build: simplify build & run process of FE files
use external bun packages to bundle files, run this package in the build.rs script
This commit is contained in:
parent
e379967907
commit
6ee345763f
6 changed files with 40 additions and 77 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -13,35 +13,6 @@ use tower_http::trace::TraceLayer;
|
|||
use tracing::info;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
fn load_templates() -> Result<Environment<'static>> {
|
||||
let mut tmpl_env = Environment::new();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
tmpl_env.set_loader(minijinja::path_loader("dist")); // Path is relative to project root
|
||||
|
||||
let _ = tmpl_env.get_template("base.html");
|
||||
if tmpl_env.templates().count() == 0 {
|
||||
return Err(Error::Runtime(
|
||||
"Templates not found, did you build the frontend with `just build-frontend`??",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// only enable in production build
|
||||
#[cfg(not(debug_assertions))]
|
||||
minijinja_embed::load_templates!(&mut tmpl_env);
|
||||
|
||||
let global_routes = vec![Link {
|
||||
path: "/about".to_owned(),
|
||||
text: "About".to_owned(),
|
||||
subpages: vec![],
|
||||
}];
|
||||
tmpl_env.add_global("global_routes", Value::from_serialize(&global_routes));
|
||||
|
||||
Ok(tmpl_env)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let config = Config::new("./config.toml".into())?;
|
||||
|
|
@ -56,7 +27,9 @@ async fn main() -> Result<()> {
|
|||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
let mut tmpl_env = load_templates()?;
|
||||
let mut tmpl_env = Environment::new();
|
||||
|
||||
minijinja_embed::load_templates!(&mut tmpl_env);
|
||||
|
||||
info!("Connecting to database {}", config.db);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue