Rebar3各种自定义配置

编译

  • 编译器选项可以使用erl_opts配置,具体选项跟compile:file一样
{erl_opts, []}.
  • 可声明需要首先编译的模块
{erl_first_files, ["srcipt/mymodule.erl", "src/mymodule.erl"]}.

发布

  • 依赖
{deps, [
    %% log
     {lager, "3.9.2"}
    ,{goldrush, "0.1.9"}
    
    %% HTTP Server
    ,{cowboy, "2.9.0"}
    ,{cowlib, "2.11.0"}
    ,{ranch, "1.8.0"}
]}.
  • 依赖下载CDN
{rebar_packages_cdn, "https://hexpm.upyun.com"}.
  • relx发布配置
{relx, [
  {release, {moyu, "0.1.0"}, [{app, none}, sasl]}, % 发布的app名以及项目内的app
  {check_for_undefined_functions, false}, % 检查没定义的函数
  {sys_config_src, "./args/sys.config.src"}, % 自定义的sys.config.src目录
  {vm_args_src, "./args/vm.args.src"}, % 自定义的环境变量目录
  {overlay, [ %% 对于项目内其他非app目录的做法:复制
        {copy, "yctl", "./"},
        {copy, "script", "./"},
        {copy, "args", "./"},
        {copy, "setting", "./"},
        {copy, "config", "./"},
        {copy, "update", "./"}
    ]}
]}.
  • 多环境发布profiles配置使用时需要使用rebar3 as prod release -o 发布目录 来使用不同模式
{profiles, [
    {dev, [ % dev模式下的一些覆盖配置
        {relx, [
            {dev_mode, false}
        ]}
    ]},
    {prod, [ % prod模式下的覆盖配置
        {erl_opts, [no_debug_info]},
        {overrides, [
            {del, [{erl_opts, [{d,'TEST',true}]}]}
        ]},
        {relx, [
            {dev_mode, false}
        ]}
    ]}
]}.
  • Makefile简单调用profiles的做法外部命令为:make PROFILE=prod release
# 编译erl文件
erl: erl_compile
erl_compile: init_make make_pre
  @echo "make erl"
ifndef PROFILE
  @(rebar3 compile)
else
  @(rebar3 as $(PROFILE) compile)
endif

release: compile_pre
  @echo "make release"
ifndef PROFILE
  @(rebar3 release -o $(RELEASE_BASE))
else
  @(rebar3 as $(PROFILE) release -o $(RELEASE_BASE))
endif

Rebar3各种自定义配置
https://qiil.github.io/2021/05/26/Rebar3各种自定义配置/
作者
QSY
发布于
2021年5月26日
许可协议