Web development
Experimental. The web target is in beta and its APIs may change in any release.
Valdi Web applications use the same compiler and component model as native Valdi applications. A Web target packages the compiled modules, generated registries, resources, and browser runtime into a ZIP that the CLI serves locally.
Build and run
Start the application in one terminal:
valdi install web --application //apps/helloworld:hello_world_web
By default the CLI binds to 127.0.0.1, chooses an available port, and opens the application in the default browser. Use --host, --port, or --no-open to change that behavior.
Start hot reload in another terminal:
valdi hotreload --target //apps/helloworld:hello_world_hotreload
When exactly one matching Web session is running, valdi hotreload can discover it automatically. The current implementation performs a live reload: after a successful compiler pass, Bazel rebuilds the registered Web archive, publishes a new immutable generation, and reloads the page over a server-sent event.
Failed compiler, Bazel, or extraction steps leave the last successful generation online.
Hot-reload coordination
valdi install web and valdi hotreload are separate long-running processes. They coordinate through an owner-only, per-user registry in the operating system's temporary directory. The install process records the canonical workspace and targets, the original Bazel arguments, an authenticated loopback publication endpoint, and its process ID.
The generated target convention is:
//apps/example:example_web
|
v
//apps/example:example_hotreload
The compiler remains the only source monitor. Its normal Watchman subscription emits a lifecycle event after a successful pass; the CLI then rebuilds and publishes matching Web targets. Rebuilds are serialized and compiler events received during a rebuild are coalesced.
Web dependencies and custom views
A valdi_module may provide browser-only code with web_deps. Web dependencies must be typed ts_project targets, not filegroups.
If the module's Valdi source imports a native TypeScript API that the web dependency implements, also declare web_register_native_module_id_overrides. Without it the browser implementation is bundled, but nothing exists at the imported module id and the bundler reports Module not found. See web_register_native_module_id_overrides for the mapping and an example.
Custom views use webClass, with factories exported through webPolyglotViews. A factory receives its container DOM element and may return a changeAttribute(name, value) handler.
See Native custom views for a complete cross-platform example.
Export a package
Use the CLI to export a standalone Web archive or npm package:
valdi export web --library //apps/helloworld:hello_world_export_npm --output_path ./hello_world_web.zip
Web application and package rules can control image inlining and output directories. Published packages include the Valdi native API version metadata used by the browser runtime.
Binary module entries
Exported packages preserve .bin and .protodecl module entries as direct imports. The consuming bundler must load these files as Uint8Array values. Applications generated by valdi install web include the required configuration automatically.
For a custom Webpack configuration on a Webpack release that supports the asset/bytes module type, add the rule the generated configuration uses:
module.exports = {
module: {
rules: [
{
test: /\.(bin|protodecl)$/i,
type: 'asset/bytes',
},
],
},
};
Older Webpack releases need a loader that emits the bytes instead, such as bytes-loader.js used by the Valdi web devtools:
{
test: /\.(bin|protodecl)$/i,
use: [{ loader: require.resolve('./bytes-loader.js') }],
type: 'javascript/auto',
}
Other bundlers require an equivalent raw-bytes loader or plugin that makes a direct import of either file type return a Uint8Array.