mega compile

The compile command (also aliased as mega build) compiles Solidity contracts using Foundry’s Forge under the hood.

Usage

mega compile [options]

Options

Mega CLI passes all options directly to Forge. Here are some commonly used options:

OptionDescription
--namesPrint compiled contract names
--sizesPrint compiled non-test contract sizes
--forceClear the cache and recompile
--optimizeActivate the Solidity optimizer
--watchWatch for changes and recompile

The mega compile command supports all options available in forge build. See the Forge documentation for a complete list.

Description

This command compiles your Solidity contracts using Foundry’s Forge compiler. It’s a wrapper around forge build that ensures compatibility with the Mega CLI workflow while providing access to all of Forge’s powerful compilation options.

Examples

Basic compilation

mega compile

Optimize contracts and show sizes

mega compile --optimize --sizes

Watch for changes and recompile automatically

mega compile --watch

Force recompilation by clearing the cache

mega compile --force
  • deploy - Deploy compiled contracts
  • setup - Ensure Foundry is properly installed