Luaubundler
Luaubundler is a command-line interface (CLI) tool designed for bundling Luau code, specifically tailored for the Roblox ecosystem. It processes an input Luau file, recursively resolves `require` statements by inlining the content of required files (including support for absolute paths), and outputs a single, consolidated Luau file. Key features include code minification, automatic renaming of local and global variables to reduce file size and obfuscate code, and support for special build macros like `LBN_METADATA` for injecting metadata into the bundle. The current stable version is 1.1.6. While the project shows a consistent update cadence through bug fixes and feature additions, its development is largely driven by community feedback. A key differentiator is its specific optimization capabilities for Luau, making it well-suited for Roblox game development. The project internally leverages `luamin.js` for minification and `luaparse` for parsing Luau code.
Common errors
-
'luaubundler' is not recognized as an internal or external command, operable program or batch file.
cause The `luaubundler` package is not installed globally, or `npx` cannot locate it within your project's `node_modules`.fixEnsure `luaubundler` is installed either locally (`npm install luaubundler`) or globally (`npm install -g luaubundler`), or always run it via `npx luaubundler ...` to ensure the correct version is found and executed. -
Error: Input file not found at path: <your/input/file.luau>
cause The path provided to the `-i` (input file) argument does not point to an existing Luau file.fixVerify that the path provided to the `-i` argument is correct, either relative to your current working directory or as an absolute path, and that the file actually exists and is readable. -
Error: Output directory does not exist: <your/output/directory>
cause The directory specified by the `-o` (output directory) argument does not exist, and `luaubundler` does not automatically create parent directories.fixBefore running the bundler, ensure the output directory exists by creating it manually (e.g., `mkdir -p dist` on Linux/macOS or `New-Item -ItemType Directory -Path dist` on PowerShell for Windows) or ensure the `-o` path points to an already existing directory.
Warnings
- gotcha The Luaubundler package is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License (CC BY-NC-ND 4.0). This license explicitly prohibits commercial use, sublicensing, inclusion in paid products, or redistribution as part of commercial packages or asset bundles, whether modified or unmodified. Users must carefully review these terms before integrating Luaubundler into any project that could be considered commercial.
Install
-
npm install luaubundler -
yarn add luaubundler -
pnpm add luaubundler
Imports
- CLI Execution
import { bundle } from 'luaubundler';npx luaubundler <arguments>
- Node.js Script
const bundler = require('luaubundler'); bundler.runBundling({...});"scripts": { "bundle-luau": "luaubundler -i src/main.luau -o dist -m -v" } - Configuration Types
import type { LuaubundlerOptions } from 'luaubundler';This package does not expose specific TypeScript types for its CLI configuration, as interaction is purely via command-line arguments.
Quickstart
# Create project directory and navigate into it
mkdir my-luau-project
cd my-luau-project
# Create a main Luau file with a module import and a macro
echo 'local MyModule = require("path/to/my/module")\nprint("Hello from Luau!")\nfunction LBN_METADATA() return { version = "1.0.0", env = "development" } end' > main.luau
# Create the nested directory for the module
mkdir -p path/to/my
# Create the required module file
echo 'return { message = "This is a required module data." }' > path/to/my/module.luau
# Create the output directory for the bundled file
mkdir dist
# Run the luaubundler CLI tool with minification, local and global variable renaming
npx luaubundler -i main.luau -o dist -n bundled.luau -m -v -g
# Display the content of the generated bundled file
cat dist/bundled.luau
# Expected output in dist/bundled.luau (variable names 'a' and 'b' are examples and may vary):
# --!native
# --[[ Luaubundler v1.1.6 ]]
# --[[ LBN_METADATA:{ "version": "1.0.0", "env": "development" } ]]
# local a = {message="This is a required module data."}
# print("Hello from Luau!")
# function b() return {version="1.0.0",env="development"} end