Skip to main content

Crate web_modules

Crate web_modules 

Source
Expand description

Pure-Rust, buildless toolchain for ES modules and Web Components. No Node, no bundler.

It vendors each npm package into a web_modules/ tree with an import map (Snowpack-style) and serves them through an on-the-fly transform dev server (like @web/dev-server), built entirely in Rust on npm-utils, oxc and grass. It emits native ES modules and leaves bare-specifier resolution to the browser’s import map; it is not a bundler.

§Modules

Core (always on):

  • vendor: resolve, download and extract npm packages into a web_modules/ tree (via npm-utils) and accumulate the import map.
  • importmap: a deterministic import-map composer (build, merge fragments, render the <script type="importmap">).

Processors (applied to your source and assets):

  • typescript: TypeScript and modern JS → browser JS via oxc, with legacy decorators configured for Lit.
  • scss: SCSS → CSS via grass.
  • minify: JS minification via oxc_minifier.
  • dts: .d.ts emission. i18n: XLIFF merge. icons: favicons from a PNG.

Toolchain (build and serve):

  • build: vendor, transform and render into an output dir.
  • bundle: fold an app plus its node_modules/ (CommonJS and all) into one browser ESM file via rolldown, for React-class packages that ship only CommonJS.
  • templates: HTML templating (importmap injection).
  • server / dev: serve embedded assets, or compile on the fly with file-watching and live-reload.

Re-exports§

pub use build::Build;
pub use build::compress;
pub use build::templates;
pub use npm_utils as npm;
pub use include_dir;

Modules§

build
Build-time toolchain for a consumer crate’s build.rs.
cli_config
CLI scaffolding (the feature_args! macro + the NoConfig placeholder) that lets each compiler processor carry its own clap config. Compiled only with cli, so the library path stays clap-free. CLI scaffolding for the compiler processors — compiled only with the cli feature, so the library path stays clap-free (the deliberate design noted on the cli feature in Cargo.toml).
dev
A buildless dev server: serve a frontend straight from source, compiling TypeScript and SCSS on the fly per request (mtime-cached) and live-reloading the browser when files change.
dts
Emit TypeScript declaration files (.d.ts) via oxc_isolated_declarations.
i18n
Read and merge XLIFF 1.2 localisation files (e.g. lit-localize interchange) into a { id: translation } map for runtime use, via quick_xml.
icons
Generate favicons and app icons from a source PNG, via image + ico.
importmap
A small, deterministic import map composer.
minify
JavaScript minification via oxc_minifier + minified codegen.
mount
Compose a frontend from many prefix-mounted source directories.
reject
Reject-path filtering: keep config / secret / server-side files out of built output, bundles, and served responses.
scss
SCSS → CSS compilation via grass (pure Rust, no Node/dart-sass).
server
Axum integration: serve a frontend from a set of known roots.
static_files
Copy non-source static files into an output tree.
symlinks
Symlink policy for walking and serving source trees.
tsconfig
Generate TypeScript tsconfig paths from a set of Mounts: the editor / tsc side of import resolution, co-generated from the same mount set as the runtime Importmap so the two can’t drift.
typescript
TypeScript / modern JS → browser JS via oxc.
vendor
Vendor packages into a web_modules/ tree and build the import map.

Structs§

Dev
The fluent dev-server builder (feature builder), at the crate root alongside Frontend. Fluent builder for the dev server: compile TS/SCSS on the fly, render *.tera, watch the source roots and live-reload the browser.
Frontend
Serve a frontend from one or more known roots. Default: a single root at /.
Mount
A source directory mounted into the composed app.

Enums§

Decorators
The decorator-lowering mode (web_modules::Decorators), always available so the build Processors set can carry it regardless of which processors are compiled. Decorator handling for the TypeScript transform. Defined here (always compiled) so the build Processors set can carry it whether or not the typescript processor is enabled; re-exported at the crate root as web_modules::Decorators (and, with the typescript feature, as web_modules::typescript::Decorators). It takes effect only when the typescript processor actually runs.
Error
Anything that can go wrong inside web_modules.
SymlinkMode
How symlinks in a source tree behave, everywhere: the build preflight, the dev server, and the static router. Selected on Processors::symlinks (so build and dev share it), on Frontend::symlinks, and via --symlinks on the CLI.

Functions§

serve
Bind addr and serve app until the process stops.

Type Aliases§

Result
Convenience alias: Result<T, web_modules::Error>.