Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Option to only build front end / CSR or backend / SSR #315

Open
ActuallyHappening opened this issue Jul 14, 2024 · 3 comments
Open

Comments

@ActuallyHappening
Copy link

I am trying to develop a Dockerfile using cargo leptos and only need to build the server binary in the docker container. There is no need to build the front end, i.e. the .html, .css, and .wasm files inside the docker container, so I am wanting to build them on my local machine and use that build to COPY target/site set into the docker container.

But, because I build the .wasm file with --release, when I run cargo leptos build --release I build both the .wasm (what I want) and the SSR binary (what I don't need). Can we add a CLI flag / option to only build the front end? This functionality is much harder to extract, but for my docker container I have hand-crafted a cargo build --target=wasm32-unknown-unknown invocation.

Currently I can just ^C the cargo leptos build process after it has built just the front end, but I would eventually like to script this, so having an option like cargo leptos build --release --front-end-only would help

@benwis
Copy link
Contributor

benwis commented Jul 14, 2024

I'm currently rewriting cargo-leptos, and that will be a feature. In the meantime, a workaround is to call wasm-pack or wasm-bindgen directly as we recommend in the example readmes

@CorvusPrudens
Copy link

If you really want this behavior in the meantime, #318 actually implements this.

The invocation would be cargo leptos build --release --lib.

@mibmo
Copy link

mibmo commented Oct 21, 2024

I'm currently rewriting cargo-leptos, and that will be a feature. In the meantime, a workaround is to call wasm-pack or wasm-bindgen directly as we recommend in the example readmes

How should I call wasm-bindgen? I think I've almost got this working for my usecase, but I don't quite get the same result as is output in site by cargo leptos build --release. Currently I'm doing wasm-bindgen --target web --no-typescript site/pkg/web.wasm site/pkg

EDIT: aha! after much debugging and staring at the source, turns out my issue was that I was optimizing the wasm prior to packing it, which I think removed some crucial instructions. The steps I ended up with are essentially just these (but not quite, as I'm doing it with nix derivations and ipetkov/crane)

  1. compile wasm: cargo build --lib --no-default-features --features hydrate --target wasm32-unknown-unknown
  2. pack: wasm-bindgen --target web --no-typescript path/to/the.wasm --out-dir site/pkg
  3. optimize: wasm-opt -Os site/pkg/web.js --output site/pkg/web.js
  4. minify: minify site/pkg/web.js --output site/pkg/web.js
  5. compile style: dart-sass --no-source-map style/main.scss site/pkg/web.css
  6. copy assets: cp -r public/* site/*
  7. cleanup: rm site/pkg/web_bg.wasm

I'm using minify as opposed to swc's minify, as swc's CLI isn't properly implemented yet, and I was doing this all from scripted bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants