Lua Pack
A Rust-based tool for bundling and minifying Lua scripts into monolithic releases.
Features
- Bundling: Combine multiple Lua modules into a single file
- Minification: Reduce file size by removing whitespace and shortening identifiers
- LZ4 Compression: Optional compression support (requires external decompressor)
- Dynamic Requires: Support for runtime module loading (with the
dynamicfeature) - Lua Compatibility: Supports Lua 5.1-5.4, LuaU, and CfxLua syntax
Installation
Either cargo install luapack or cargo binstall luapack depending on which is available. Read the Cargo.toml for compilation options.
Usage
Options
-p, --prefix <PREFIX> An optional prefix file that will be added to the output
-s, --suffix <SUFFIX> An optional suffix file that will be added to the output
-o, --output <OUTPUT> Output file path
-f, --file <FILE> Input file path
-B, --bundle Bundle modules (entry point resolution)
-P, --pack Minify the output
-l, --lz4 Compress output with LZ4
-h, --help Print help
-V, --version Print version
Examples
Default (bundle + pack):
Bundle only:
Pack only (minify existing file):
Bundle, pack, and compress:
With a prefix and suffix:
How It Works
Bundling
The bundler resolves require() statements and combines all dependencies into a single file with a custom module loader. Modules are stored in a table and loaded on-demand.
Input:
-- main.lua
local utils = require
utils.
-- utils.lua
return
Output:
require =
__M=
local utils = require
utils.
Dynamic Requires
With the dynamic feature enabled, all .lua files in your project directory are automatically included in the bundle, allowing runtime defined dependencies. If you want to exclude a certain Lua file then add -- ignore as its first line. Keep in mind that paths are relative to the parent of the first .git directory it can find.
Packing (Minification)
Just removes whitespaces (wherever possible) and shortens variable names.
LZ4 Compression
Compresses output using the lz4 algorithm.
Limitations
- LZ4 decompressor not included - use
-pand-sto add your own - Dynamic requires increase bundle size significantly
- Requires Git repository for dynamic feature
Maintenance
This project is minimally maintained - updates will be made if it breaks with new Lua versions or dependencies.
License
MPLv2