moth compiles and tools Moth projects. You use it from the command line to create projects, check them, build them and run the hot-reloading dev server.
If you are running the compiler from the repository instead of an installed moth binary, use cargo run -- before the same commands:
cargo run -- dev .
cargo run -- check .
cargo run -- build .| Command | Use | Notes |
|---|---|---|
|
Prints the current command list and supported flags. | Use this to find command-specific options. |
|
Prints the current compiler/tool version. | |
|
Creates an HTML project. | Accepts an optional path and |
|
Runs project discovery, frontend compilation, type checking, HIR lowering and borrow validation without writing build artifacts. | Add |
|
Builds the project, starts a local dev server, watches files and reloads the browser when sources change. | This is the main day-to-day command for working on HTML projects. |
|
Builds the project and writes output files. | Without |
|
Runs the compiler integration test suite. (developer tool) | Mainly useful when working on the compiler itself. Use |
| Flag | Applies to | Effect |
|---|---|---|
|
|
Selects the release build profile and release output folder where supported. |
|
HTML builds | Selects the HTML-Wasm backend for an HTML build. |
|
|
Prints compact diagnostics or test summaries for tools, logs and LLM workflows. |
|
|
Allows replacing existing scaffold-owned files after a confirmation warning. Never overwrites |
|
|
Configures the local dev server. Defaults are `127.0.0.1`, `6342` and `300`. |
An HTML project keeps settings in @config.moth and executable page content in @entry.moth. The first build creates output folders and manifests. See Project structure for routing, assets and output rules.
Project and builder settings are ordinary top-level compile-time constants. The project and html records are optional:
project #= (
name = "my_site",
)
html #= ()The selected directory is the source root. To supply a version, add it to the project record or pass a configurable value through the $config input marker.
@entry.moth supplies HTML metadata with direct const builder slots. An empty or metadata-only entry still produces a page:
[$in title:Welcome]A directory with @entry.moth is entry-eligible, including when the file is empty.
Start a new project:
moth new html
moth new html my-site
moth new html ~/projects/my-siteIf you omit the path, moth asks for confirmation in the current directory:
No project path specified. Current directory: /your/path
Create the new HTML project in this directory? y/N:If the target directory already exists, you are given three choices:
Target directory already exists:
/path/to/target
What do you want to do?
1. Create the project inside this directory
2. Create a new child folder for the project inside this directory
3. Cancel
Choose 1/2/3:If the path contains directories that do not exist, moth asks before creating them:
The project target contains directories that do not exist:
/path/to/new/site
Create the missing directories and scaffold the project there? y/N:After the final directory is chosen, moth asks for the project name:
Project name (press Enter to use project directory name):Then it asks whether to add a .gitignore with Moth defaults:
Add a .gitignore with Moth defaults? Y/n:If .gitignore already exists, moth asks whether to append missing defaults instead of overwriting.
A project after its first build looks like this:
project-root/
├── @config.moth
├── @entry.moth
├── _dev/
│ └── .moth_manifest
├── _release/
│ └── .moth_manifest
└── .gitignore_dev/ and _release/ are hidden output folders..moth_manifest files are build-system metadata for safe stale-output cleanup.@config.moth is the optional build-only project config. It never becomes a page or joins the module graph.@entry.moth is the executable entry root at the selected project root. Its presence selects the page, including when the file is empty or holds only metadata.@package.moth packages under the selected source root for project-local packages.--force allows replacing scaffold-owned files when they already exist:
moth new html my-site --forceIt still asks for a second confirmation and never overwrites .gitignore or unrelated files.
After creation, check and run the project:
cd my-site
moth check .
moth dev .dev handles normal day-to-day Moth project work. It builds the project, serves the generated files locally, watches for source changes and sends reload events to the browser.
moth dev .By default, open:
http://127.0.0.1:6342/Useful dev-server options:
moth dev . --port 8080
moth dev . --host 0.0.0.0
moth dev . --poll-interval-ms 100When a build fails, fix the reported error and save again. The dev server is designed around fast feedback rather than a manual rebuild loop.
Use build when you want files written to disk without running the dev server.
moth build .For a release build:
moth build . --releaseFor HTML projects, generated files are written under the configured output folder. The default scaffold uses _dev for development output and _release for release output.
check gives the fastest correctness signal for editor loops and CI-style validation. It doesn't write output artifacts, but it runs the shared frontend diagnostics that all backends use.
moth check .Use terse mode when another tool will read the output:
moth check . --terseTerse diagnostics have a stable compact shape:
E|type|@entry.moth|4:12|Expected Bool, found I32|help=Use a Bool expression here.
W|identifier_naming_convention|button.moth|1:1|Dependency alias case mismatchMoth uses the same formatted diagnostic system across the compiler front end and backend builders. That means syntax errors, type errors, config errors, file errors, borrow-checker errors, dev-server errors and backend errors use the same basic shape.
A normal diagnostic contains:
Example shape:
Type Error (ಠ_ಠ) 🔥
Declaration 'count' has incompatible initializer type. Expected 'I32', but found 'String'.
--> @entry.moth:6:17
|
6 | count I32 = "wrong"
| ^^^^^^^
Use an I32 value here, or change the declaration type.Read diagnostics from top to bottom:
| Kind | Meaning | Usual fix |
|---|---|---|
| Syntax Error | The source text could not be parsed as Moth syntax. | Check punctuation, block delimiters, template brackets, dependency clauses and declaration shape. |
| Type Error | The expression type does not match the expected type. | Check annotations, return types, function arguments, collection element types and contextual casts. |
| Language Rule Error | The syntax is valid, but it violates a language rule. | Check things like mutability, binding visibility, unsupported feature surfaces, duplicate names or invalid top-level code. |
| Missing File or Directory | The project references a file, directory, dependency path or output path that cannot be resolved. | Check spelling, relative paths, the selected project directory and project config. |
| Malformed Config | The project config exists but contains unsupported, missing or invalid settings. | Check `@config.moth` and backend-specific config rules. |
| Borrow Checker Violation | The program violates Moth's access and ownership rules. | Check mutable/exclusive access, later uses after possible moves and overlapping borrows. |
| Dev Server Issue | The local server could not start, watch, build or serve the project correctly. | Check port conflicts, host binding, project path, and file permissions. |
| Compiler Bug / HIR / LIR / WASM Generation Bug | The compiler hit an internal invariant or unsupported backend path. | Reduce the input if practical and report it. User code should receive structured errors instead of compiler bugs. |
Warnings identify source that can compile but deserves attention, such as naming mismatches and malformed HTML or CSS template content. Use moth check . to review them without writing build output.