備註:html
項目比較大, 模塊比較多,通常使用mix 的方式是你們進行文件夾的劃分,可是使用mix 的umbrella 可能會更方便git
1. 安裝github
默認安裝elixir 的時候已經包含了這個功能
a. 建立根項目 mix new <projectname> --umbrella 生成的項目以下: * creating README.md * creating .formatter.exs * creating .gitignore * creating mix.exs * creating apps * creating config * creating config/config.exs Your umbrella project was created successfully. Inside your project, you will find an apps/ directory where you can create and host many apps: cd opsplatform cd apps mix new my_app Commands like "mix compile" and "mix test" when executed in the umbrella project root will automatically run for each application in the apps/ directory. b. 添加子項目 cd <projectname>/apps 個人是opsplatform cd opsplatform/apps/ mix new platformuserlogin mix new platformrunnuer mix new platformdao 項目代碼結構以下: ├── apps │ ├── platformdao │ │ ├── config │ │ ├── lib │ │ └── test │ ├── platformrunnuer │ │ ├── config │ │ ├── lib │ │ └── test │ └── platformuserlogin │ ├── config │ ├── lib │ └── test └── config d. 編譯 mix compile # 根項目,進入子模塊進行編譯也是能夠的 e. 模塊引用(好比platformrunnuer 須要platformdao) 進入platformrunnuer 編輯 mix.exs defp deps do [ # {:dep_from_hexpm, "~> 0.3.0"}, {:platformdao, in_umbrella: true} # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, # {:sibling_app_in_umbrella, in_umbrella: true}, ] end
mix.exs defmodule Platformdao.MixProject do use Mix.Project # 處理引用的是根目錄的,對於配置信息以及依賴能夠方便的共享 def project do [ app: :platformdao, version: "0.1.0", build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", lockfile: "../../mix.lock", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps() ] end # Run "mix help compile.app" to learn about applications. def application do [ extra_applications: [:logger] ] end # Run "mix help deps" to learn about dependencies. defp deps do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, # {:sibling_app_in_umbrella, in_umbrella: true}, ] end end
通常來講咱們在使用umbrella 的時候,同時會使用distillery && edeliver 一個負責構建,一個負責部署,仍是比較方便的
https://hex.pm/packages/edeliver https://hex.pm/packages/distillery https://hexdocs.pm/mix/Mix.html https://github.com/wojtekmach/acme_bank