zoukankan      html  css  js  c++  java
  • elixir 使用mix umbrella 模块化项目

    备注:

       项目比较大, 模块比较多,一般使用mix 的方式是大家进行文件夹的划分,但是使用mix 的umbrella 可能会更方便

    1. 安装

    默认安装elixir 的时候已经包含了这个功能
    2. 基本使用
    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
    3. 子模块说明
    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
    4. 扩展
    一般来说我们在使用umbrella 的时候,同时会使用distillery && edeliver
    一个负责构建,一个负责部署,还是比较方便的
    5. 参考资料
    https://hex.pm/packages/edeliver
    https://hex.pm/packages/distillery
    https://hexdocs.pm/mix/Mix.html
    https://github.com/wojtekmach/acme_bank
  • 相关阅读:
    c++实验9 图及图的操作实验
    Html/CSS 示例演练 图书馆后台界面
    c++实验8 哈夫曼编码-译码器
    Html/CSS 初步介绍html和css部分重要标签
    c++实验7 二叉树
    JavaWeb -学生信息管理实践(JDBC+web+三层架构+DBUtil构造思路)
    java 实验6 图形用户界面设计试验(2)
    操作表与操作表数据行
    数据表操作练习
    数据库的介绍:
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/8743875.html
Copyright © 2011-2022 走看看