Skip to content

Commit

Permalink
Adding mix slides.
Browse files Browse the repository at this point in the history
  • Loading branch information
algogrit committed Mar 20, 2024
1 parent 9d4e768 commit c9f3c16
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions docs/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,123 @@ Exceptions in the `else` block are not caught. If no pattern inside the `else` b
---
class: center, middle

## Mix

---
class: center, middle

Mix is a build tool that ships with Elixir that provides tasks for creating, compiling, testing your application, managing its dependencies and much more...

---
class: center, middle

```bash
mix new <app_name>
```

---
class: center, middle

```bash
elixir/app/hello $ tree
.
├── README.md
├── lib
│   └── hello.ex
├── mix.exs
└── test
├── hello_test.exs
└── test_helper.exs

3 directories, 5 files
```

---
class: center, middle

Peeking into the `mix.exs` file

---

- Configures the project using `def project`

- `def application`, which is used to generate an application file.

- a private function named `deps`, which is invoked from the project function, that defines our project dependencies

---
class: center, middle

This structure is enough to compile our project:

```bash
mix compile
```

---
class: center, middle

Once the project is compiled, you can start a iex session inside the project.

```bash
iex -S mix
```

---
class: center, middle

The `-S mix` is necessary to load the project in the interactive shell.

---

While you may start a new session whenever there are changes to the project source code, you can also recompile the project from within iex with the recompile helper, like this:

```elixir
recompile()
```

---

### Other Features

- Auto code formatting via `.formatter.exs` using `mix format`.

- Environment management. By default, Mix understands three environments:

`:dev` — the one in which Mix tasks (like compile) run by default
`:test` — used by mix test
`:prod` — the one you will use to run your project in production

- ...

---
class: center, middle

```elixir
def project do
[
...,
start_permanent: Mix.env() == :prod,
...
]
end
```

---
class: center, middle

When true, the :start_permanent option starts your application in permanent mode, which means the Erlang VM will crash if your application's supervision tree shuts down.

---
class: center, middle

```bash
MIX_ENV=prod mix compile
```

---
class: center, middle

Code
https://github.com/AgarwalConsulting/elixir_training

Expand Down

0 comments on commit c9f3c16

Please sign in to comment.