> 1.2",
escript: escript, # 追加 escript 配置
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
def escript do # 追加 escript 函数,其中设置 main_module
[main_module: Sample]
end
编译二进制:
$ mix escript.build
Compiled lib/sample.ex
Generated sample app
Consolidated List.Chars
Consolidated Collectable
Consolidated String.Chars
Consolidated Enumerable
Consolidated IEx.Info
Consolidated Inspect
Generated escript sample with MIX_ENV=dev
$ ls -l
total 4824
-rw-r--r-- 1 xxxxxx staff 399 2 17 22:08 README.md
drwxr-xr-x 4 xxxxxx staff 136 2 17 23:08 _build
drwxr-xr-x 3 xxxxxx staff 102 2 17 22:08 config
drwxr-xr-x 3 xxxxxx staff 102 2 17 23:31 lib
-rw-r--r-- 1 xxxxxx staff 738 2 17 23:28 mix.exs
-rwxr-xr-x 1 xxxxxx staff 2460249 2 17 23:28 sample # 此为二进制文件
drwxr-xr-x 4 xxxxxx staff 136 2 17 23:09 test
$ ./sample
hello
$ ./sample "Elixir"
hello
Elixir
|