The primary focus of moon is a task runner. In moon, a task is a binary or system command that is run as a child process within the context of a project. Tasks are defined per project withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/moonrepo/moon/llms.txt
Use this file to discover all available pages before exploring further.
moon.yml, or inherited by many projects with .moon/tasks/**/*.
Configuring a Task
Most projects utilize the same core tasks: linting, testing, code formatting, typechecking, and building. Let’s implement a build task within a project. Begin by creating themoon.yml file at the root of a project and add build to the tasks field with a command parameter:
moon.yml
Adding Arguments
Arguments can be defined with theargs setting or directly in the command:
moon.yml
Inputs
Our task above works, but isn’t very efficient as it always runs, regardless of what has changed since the last time it ran. This becomes problematic in CI environments and locally. To mitigate this, moon provides inputs - file paths, globs, and environment variables that are used by the task. Moon will compare these inputs to calculate whether to run or return the previous run state from cache. Let’s expand the task with theinputs setting:
moon.yml
- Any files within the
srcfolder (relative from the project’s root) - The
webpack.config.jsfile in the project’s root - The
webpack-shared.config.jsfile in the workspace root (denoted by the leading/)
Inputs are a powerful feature that can be fine-tuned to your project’s needs. Be as granular or open as you want!
Environment Variable Inputs
You can also include environment variables as inputs:moon.yml
Outputs
Outputs are the opposite of inputs - they are files and folders created as a result of running the task. Outputs are optional, as not all tasks require them, and the ones that do are typically build-related. Declaring outputs is important for incremental builds and smart caching! When moon encounters a build that has already been built, it hydrates all necessary outputs from the cache, then immediately exits. No more waiting for long builds! Let’s expand our task with theoutputs setting:
moon.yml
@out(0) token references the first output directory, ensuring the build goes to the correct location.
Task Dependencies
For scenarios where you need to run a task before another task, use thedeps setting with targets:
<project>:<task>- Full canonical target~:<task>or<task>- A task within the current project^:<task>- A task from all depended on projects
moon.yml
Using File Groups
Once you’re familiar with configuring tasks, you may notice certain inputs being repeated. To reduce boilerplate, moon provides file groups, which enable grouping of similar file types:moon.yml
@globs(sources) and @globs(configs) tokens expand to all files matching those file groups.
Common Task Patterns
Here are some common task configurations:- Build Task
- Test Task
- Lint Task
- Type Check Task
- Dev Server Task
moon.yml
Task Options
Here are some useful task options:moon.yml
Global Task Configuration
To avoid repeating the same tasks across multiple projects, create global task configurations in.moon/tasks/:
.moon/tasks/node.yml
language setting!
Example: Complete Task Configuration
Here’s a complete example:moon.yml
Next Steps
Run a Task
Learn how to run tasks with moon
Task Configuration Reference
View all available task configuration options