htmlbuilder
Official sources are open to Staxis GitLab group members:
how to join and view the code.
Repository: htmlbuilder development
Versions: tags
and releases
Description
htmlbuilder generates static HTML pages from editable files and shared include fragments. It reads server-edits, expands each page's includes, and writes the results to the configured public directory. Use it when pages can be generated ahead of requests, without a view engine rendering a response for each visit.
The builder prepares files; httpStatics can serve them afterwards. For pages rendered from application data at request time, see the viewEngine alternatives. This page covers the current htmlbuilder pack, not the additional build features used by the documentation site's own tooling.
Read before flight
-
We suggest keeping editable pages and include fragments outside the served public directory. Everything expanded into a generated page becomes part of its public HTML, so do not include server-only data or secrets.
-
We suggest reviewing the target path and its Guardian filesystem rules together. A build replaces the HTML files it generates; it does not remove obsolete output or copy stylesheets, images, and other assets.
-
We suggest using a directory named fragments for include-only HTML. Other source directories are scanned recursively and their .html files become independent output pages.
Files Map
| File | Purpose |
|---|---|
| main.js | Finds source pages, expands includes, optionally minifies, and writes generated HTML |
| configs.js | Supplies default output settings and filesystem permissions |
| manifest.json | Declares the htmlbuilder label and typology |
| .fomap | File map used by the Manager installation flow |
| README.md | Pack-local setup and usage reference |
| htmlbuild (repository root) | Command-line launcher to copy into the Staxis project root |
Requirements and Installation
Install the pack through the Manager:
manager -> install -> htmlbuilder
Copy the repository's root htmlbuild launcher into your Staxis project root, alongside config.js. The supplied .fomap installs the pack directory but does not copy this root launcher. Its current import expects system-lrpcks/htmlbuilder/main.js; adapt that path if your project uses another pack directory. Preserve any existing custom launcher rather than replacing it without review.
The command uses the Staxis Core's #core:layers and #core:loaders imports and reads the active config.js. No additional npm build library, HTTP listener, or view engine is required to generate pages. The CLI constructs the builder directly; a build does not require starting the HTTP application.
Configuration
The build settings belong to config.htmlBuilder, directly under the exported config object. Filesystem rules belong to config.engineopt.guard.allowedFileAccess. Merge the supplied defaults while preserving other settings and other packs' access rules:
// config.js -> config (merge into the exported object)
htmlBuilder: {
minify: true,
target: 'server-public/frontoffice'
},
engineopt: {
guard: {
allowedFileAccess: [{
pack: 'htmlbuilder',
roots: [
'./server-edits',
'./server-edits/*',
'./server-public/frontoffice',
'./server-public/frontoffice/*'
]
}]
}
}
server-edits is the current fixed source directory. config.htmlBuilder.target selects the output directory relative to the project root. If you change it, also update the target directory and its contents in htmlbuilder's allowedFileAccess entry. The target directory and any required subdirectories are created during the build.
config.htmlBuilder.minify defaults to true in the supplied configuration. Set it to false to retain formatting by default; --minify enables minification for one invocation. The minifier collapses whitespace-only runs between tags to a single space and preserves whitespace-sensitive contents such as pre, script, style, and textarea.
Source Layout
The current builder reads .html pages recursively and preserves their directory structure. In each directory, home.html becomes index.html. A single leading - or ~ is removed from other output filenames. Keep output names unique: home.html and index.html in the same source directory would both generate index.html and cause the build to fail.
server-edits/
home.html
about.html
guide/
home.html
fragments/
header.html
server-public/frontoffice/
index.html
about.html
guide/
index.html
Directories named fragments are excluded from the page scan, but their files remain available to include directives. A non-HTML extension is another way to keep a fragment from becoming a standalone page. Stylesheets, scripts, and images need their own copy or deployment flow; HTML references to those files are left unchanged.
Include Fragments
Each include path is relative to the file containing the directive. This also applies when one fragment includes another. For example:
<!-- server-edits/home.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Staxis Site</title>
</head>
<body>
<include "fragments/header.html">
<main>
<h1>Welcome</h1>
</main>
</body>
</html>
<!-- server-edits/fragments/header.html -->
<header>
<a href="/">My Staxis Site</a>
</header>
A page inside server-edits/guide can include the same header with:
<include "../fragments/header.html">
Quoted paths can contain spaces. The unquoted form shown in the root README is also accepted. Include files are read through the Core filesystem gate; their paths must remain permitted by the project's policy. Empty directives, circular includes, or unreadable files fail the build.
How to Use
From the Staxis project root, run the launcher after preparing config.js and server-edits:
node htmlbuild
node htmlbuild --minify
The launcher reports each generated relative filename as Built followed by its path. Invalid arguments or build errors report Build failed and set a non-zero exit code. No HTML source pages is also an error.
The builder renders all pages before writing their output, so include and duplicate-name errors stop that build before replacement begins. Output is not cleaned automatically: removing a source page does not delete its previously generated file. After a successful build, serve the configured output through httpStatics or your chosen static host. There is no automatic file watcher or rebuild on each HTTP request in this version.
Documentation
This page is the HTML adaptation of the pack's README.md and its more detailed pack-local README.md, checked against the current implementation. The pack-local reference reflects recursive page discovery and the current output configuration. Complete Staxis onboarding to request access to the official GitLab sources.