Embedding
This page documents the embedding process
Instead of always shipping the frontend files alongside your binary it is also possible to embed all the web-content into your saucer application.
Saucer offers a built-in utility to achieve this via CMake, but users are free to either generate the embedding files themselves or roll their own embedding mechanism by using custom schemes.
Pre-Requisites
Section titled “Pre-Requisites”- A static version of the web-page to embed
Automated Embedding
Section titled “Automated Embedding”The recommended way to embed web-content is to use the saucer_embed
CMake Function.
Let’s assume you have a project structure similar to this:
Directoryout (created by e.g.
pnpm run build
)Directorylogos
- …
Directory_next
- …
- 404.html
- icon.webp
- index.html
- …
- package.json
- CMakeLists.txt
Then conduct the following changes to your CMakeLists.txt
:
12 collapsed lines
# --------------------------------------------------------------------------------------------------------# Link libraries# --------------------------------------------------------------------------------------------------------
include(FetchContent)
FetchContent_Declare( saucer GIT_REPOSITORY "https://github.com/saucer/saucer" GIT_TAG $VERSION$)
FetchContent_MakeAvailable(saucer)
saucer_embed("out")target_link_libraries(${PROJECT_NAME} PRIVATE saucer::saucer saucer::embedded)
Using the Embedding Files
Section titled “Using the Embedding Files”After linking against the generated saucer::embedded
target you are all set to use the embedded files.
#include <saucer/smartview.hpp>#include <saucer/embedded/all.hpp>
coco::stray start(saucer::application *){1 collapsed line
// ... webview->set_url("..."); webview->embed(saucer::embedded::all()); webview->serve("/index.html");1 collapsed line
// ...}