|
| 1 | +# /elixir-compile |
| 2 | + |
| 3 | +Compile Elixir code with Mix and handle compilation errors. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +Compiles Elixir projects using Mix, providing detailed error reporting, dependency resolution, and compilation optimization. Supports incremental compilation, dependency fetching, and compilation warnings/errors. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +```bash |
| 12 | +/elixir-compile [options] |
| 13 | +``` |
| 14 | + |
| 15 | +## Options |
| 16 | + |
| 17 | +### Compilation Options |
| 18 | + |
| 19 | +- `--all` - Force full recompilation |
| 20 | +- `--deps` - Compile dependencies only |
| 21 | +- `--no-deps` - Skip dependency compilation |
| 22 | +- `--no-archives-check` - Skip archives check |
| 23 | +- `--no-elixir-version-check` - Skip Elixir version check |
| 24 | +- `--no-protocol-consolidation` - Skip protocol consolidation |
| 25 | +- `--no-warnings-as-errors` - Don't treat warnings as errors |
| 26 | +- `--verbose` - Verbose compilation output |
| 27 | + |
| 28 | +### Output Options |
| 29 | + |
| 30 | +- `--quiet` - Minimal output |
| 31 | +- `--json` - Output compilation results as JSON |
| 32 | +- `--stats` - Show compilation statistics |
| 33 | +- `--time` - Show compilation timing |
| 34 | + |
| 35 | +### Help |
| 36 | + |
| 37 | +- `--help, -h` - Show help message |
| 38 | + |
| 39 | +## Examples |
| 40 | + |
| 41 | +```bash |
| 42 | +# Compile project |
| 43 | +/elixir-compile |
| 44 | + |
| 45 | +# Force full recompilation |
| 46 | +/elixir-compile --all |
| 47 | + |
| 48 | +# Compile with verbose output |
| 49 | +/elixir-compile --verbose |
| 50 | + |
| 51 | +# Skip dependency compilation |
| 52 | +/elixir-compile --no-deps |
| 53 | + |
| 54 | +# Show compilation statistics |
| 55 | +/elixir-compile --stats |
| 56 | + |
| 57 | +# Output JSON results |
| 58 | +/elixir-compile --json |
| 59 | +``` |
| 60 | + |
| 61 | +## Compilation Process |
| 62 | + |
| 63 | +### 1. Dependency Resolution |
| 64 | + |
| 65 | +- Checks and fetches dependencies from Hex |
| 66 | +- Verifies dependency versions |
| 67 | +- Downloads missing dependencies |
| 68 | + |
| 69 | +### 2. Compilation |
| 70 | + |
| 71 | +- Compiles Elixir source files (.ex, .exs) |
| 72 | +- Handles module dependencies |
| 73 | +- Generates BEAM bytecode |
| 74 | +- Performs protocol consolidation |
| 75 | + |
| 76 | +### 3. Error Handling |
| 77 | + |
| 78 | +- Detailed error messages with line numbers |
| 79 | +- Warning categorization |
| 80 | +- Dependency conflict resolution |
| 81 | +- Missing module detection |
| 82 | + |
| 83 | +## Common Compilation Issues |
| 84 | + |
| 85 | +### Dependency Problems |
| 86 | + |
| 87 | +```bash |
| 88 | +# Missing dependencies |
| 89 | +mix deps.get |
| 90 | + |
| 91 | +# Outdated dependencies |
| 92 | +mix deps.update --all |
| 93 | + |
| 94 | +# Lock file issues |
| 95 | +rm mix.lock && mix deps.get |
| 96 | +``` |
| 97 | + |
| 98 | +### Compilation Errors |
| 99 | + |
| 100 | +- Syntax errors with line numbers |
| 101 | +- Undefined functions |
| 102 | +- Module name conflicts |
| 103 | +- Protocol implementation issues |
| 104 | +- Macro expansion problems |
| 105 | + |
| 106 | +### Warnings |
| 107 | + |
| 108 | +- Unused variables |
| 109 | +- Deprecated functions |
| 110 | +- Pattern match coverage |
| 111 | +- Type specification issues |
| 112 | + |
| 113 | +## Configuration |
| 114 | + |
| 115 | +### mix.exs Settings |
| 116 | + |
| 117 | +```elixir |
| 118 | +def project do |
| 119 | + [ |
| 120 | + # Compilation options |
| 121 | + elixir: "~> 1.14", |
| 122 | + build_embedded: Mix.env() == :prod, |
| 123 | + start_permanent: Mix.env() == :prod, |
| 124 | + |
| 125 | + # Compiler options |
| 126 | + compilers: [:gettext, :phoenix] ++ Mix.compilers(), |
| 127 | + elixirc_paths: elixirc_paths(Mix.env()), |
| 128 | + |
| 129 | + # Warning options |
| 130 | + warnings_as_errors: false, |
| 131 | + dialyzer: [ |
| 132 | + plt_file: {:no_warn, "priv/plts/dialyzer.plt"} |
| 133 | + ] |
| 134 | + ] |
| 135 | +end |
| 136 | +``` |
| 137 | + |
| 138 | +### Environment Variables |
| 139 | + |
| 140 | +- `MIX_ENV` - Mix environment (default: `dev`) |
| 141 | +- `MIX_QUIET` - Suppress Mix output |
| 142 | +- `MIX_DEBUG` - Enable debug output |
| 143 | +- `ERL_AFLAGS` - Erlang compiler flags |
| 144 | + |
| 145 | +## Performance Tips |
| 146 | + |
| 147 | +### Incremental Compilation |
| 148 | + |
| 149 | +- Mix caches compilation results |
| 150 | +- Only recompiles changed files |
| 151 | +- Use `--all` sparingly |
| 152 | + |
| 153 | +### Dependency Management |
| 154 | + |
| 155 | +- Keep dependencies up to date |
| 156 | +- Use specific version constraints |
| 157 | +- Clean unused dependencies regularly |
| 158 | + |
| 159 | +### Protocol Consolidation |
| 160 | + |
| 161 | +- Consolidates protocols for performance |
| 162 | +- Required for production deployments |
| 163 | +- Can be disabled with `--no-protocol-consolidation` |
| 164 | + |
| 165 | +## Related Commands |
| 166 | + |
| 167 | +- `/elixir-deps` - Manage dependencies |
| 168 | +- `/elixir-test` - Run tests after compilation |
| 169 | +- `/elixir-setup` - Project configuration |
| 170 | +- `/elixir-lint` - Code quality checks |
| 171 | + |
| 172 | +## Notes |
| 173 | + |
| 174 | +- Requires Elixir and Mix to be installed |
| 175 | +- First compilation may be slow due to dependency fetching |
| 176 | +- Protocol consolidation is automatic in production |
| 177 | +- Warnings can be treated as errors in CI environments |
| 178 | +- Compilation results are cached in `_build/` directory |
0 commit comments