nvs build --compile
nvs build --compile <file> writes one executable file that contains your program.
The file is a copy of the nvs binary with the source of the program added. It contains the entry file and every file that the program loads with require. The program is compiled when the executable starts, as with nvs run. -o <path> sets the output path. The default is the name of the entry file without its extension, in the current directory.
All arguments of the executable go to your program. The executable does not read run, check or --help as nvs commands.
Good to know: the executable reads ./nvs.toml from the directory where it runs. Files that the program finds only through autoload at run time, or opens with Core\IO, are not in the executable.
Examples
A tool you copy to another machine
<?nvs// Shows a small tool that you give to a colleague as one file.// `nvs build --compile 01-a-tool-you-copy-to-another-machine.nvs -o disk-report` writes the program `disk-report`.// Your colleague runs `disk-report` directly. They do not need to install `nvs`.
array<string> $folders = ['uploads', 'logs', 'backups'];array<uint> $megabytes = [420, 35, 1800];
uint $total = 0;uint $i = 0;foreach ($folders as string $folder) { echo $folder, ': ', $megabytes[$i], " MB\n"; $total = $total + $megabytes[$i]; $i = $i + 1;}// This prints `total: 2255 MB`. The program prints the same lines with `nvs run` and as a built file.echo 'total: ', $total, " MB\n";uploads: 420 MBlogs: 35 MBbackups: 1800 MBtotal: 2255 MB