### Project Structure Example Source: https://context7.com/axlisin/luabundler/llms.txt Illustrates a typical project structure including main script, utility modules, and the generated bundled output file. ```text my-project/ ├── main.lua ├── utils/ │ └── fancyprint.lua └── LuaBundler/ ├── config.json └── bundled.lua (generated) ``` -------------------------------- ### Install Lua Bundler Source: https://context7.com/axlisin/luabundler/llms.txt Install the luabundle CLI tool globally using Cargo. Verify the installation by checking the version. ```bash cargo install luabundle ``` ```bash luabundle --version ``` -------------------------------- ### Initialize Lua Bundler Project Source: https://context7.com/axlisin/luabundler/llms.txt Run `luabundle` in a new or existing project directory to initialize the configuration. The interactive setup prompts for essential project details like the require function name, entry file, and output path. ```bash cd my-lua-project luabundle ``` -------------------------------- ### CLI Help and Version Source: https://context7.com/axlisin/luabundler/llms.txt Display available command-line options and usage instructions with `luabundle --help`. Check the installed version using `luabundle --version`. ```bash # Show help luabundle --help ``` ```bash # Show version luabundle --version ``` -------------------------------- ### Minified Lua Output Example Source: https://context7.com/axlisin/luabundler/llms.txt A compact, minified version of the bundled Lua code, suitable for production. ```lua -- Minified output example local a=(function(...)local function a(b)print(b.." was printed with fancy text")end return a end)()a("Hello world!") ``` -------------------------------- ### Bundle Project Source: https://context7.com/axlisin/luabundler/llms.txt Execute the `luabundle` command without arguments to bundle the project based on the configuration in `LuaBundler/config.json`. The output indicates the time taken for bundling. ```bash # Bundle the project (uses LuaBundler/config.json) luabundle ``` -------------------------------- ### Main Lua Script Source: https://context7.com/axlisin/luabundler/llms.txt The main entry point script that loads and uses a utility function. ```lua -- main.lua local fancyprint = loadmodule("utils/fancyprint.lua") fancyprint("Hello world!") ``` -------------------------------- ### Minification Configuration Source: https://context7.com/axlisin/luabundler/llms.txt Configuration JSON to enable minification and disable beautification for compact output. ```json { "require_function": "loadmodule", "entry_file": "main.lua", "output_file": "LuaBundler/bundled.lua", "minify": true, "beautify": false } ``` -------------------------------- ### Require Module in main.lua Source: https://github.com/axlisin/luabundler/blob/main/README.md Demonstrates how to import a module using the loadmodule function within the entry file. ```lua local fancyprint = loadmodule("utils/fancyprint.lua") fancyprint("Hello world!") ``` -------------------------------- ### Filename Variable After Bundling Source: https://context7.com/axlisin/luabundler/llms.txt Shows how the `{{filename}}` placeholder is replaced with the actual filename after the bundling process. ```lua -- After bundling, {{filename}} becomes "logger.lua" local currentFile = "logger.lua" ``` -------------------------------- ### Active Bundling Mode Source: https://context7.com/axlisin/luabundler/llms.txt Enable watch mode using the `--active` flag. In this mode, the bundler automatically rebundles the project whenever the Enter key is pressed, facilitating continuous development. ```bash # Start active bundling mode luabundle --active ``` -------------------------------- ### Module Loading with Relative Paths Source: https://context7.com/axlisin/luabundler/llms.txt Use the configured require function (e.g., `loadmodule`) to import modules using relative paths. Modules are treated as scripts that return a value, and paths are resolved relative to the current file. ```lua -- main.lua (entry file) local utils = loadmodule("utils/helpers.lua") local config = loadmodule("config.lua") local result = utils.calculate(config.value) print(result) ``` ```lua -- utils/helpers.lua local function calculate(value) return value * 2 end return { calculate = calculate } ``` ```lua -- config.lua return { value = 42 } ``` -------------------------------- ### Filename Variable Usage Source: https://context7.com/axlisin/luabundler/llms.txt Demonstrates using the `{{filename}}` placeholder in Lua code to dynamically insert the current file's name. ```lua -- debug/logger.lua local currentFile = "{{filename}}" local function log(message) print(string.format("[%s] %s", currentFile, message)) end return log ``` -------------------------------- ### Lua Bundler Configuration File Source: https://context7.com/axlisin/luabundler/llms.txt The bundler's settings are stored in `LuaBundler/config.json`. This file defines the require function, entry and output files, and formatting options. ```json { "require_function": "loadmodule", "entry_file": "main.lua", "output_file": "LuaBundler/bundled.lua", "minify": false, "beautify": true } ``` -------------------------------- ### Define Module in fancyprint.lua Source: https://github.com/axlisin/luabundler/blob/main/README.md Shows the structure of a module script that exports a function for use by other files. ```lua local function fancyprint(text) print(text + " was printed with fancy text") end return fancyprint ``` -------------------------------- ### Generated Bundled Lua Output Source: https://context7.com/axlisin/luabundler/llms.txt The output of the Lua Bundler, showing how modules are inlined and functions are wrapped. ```lua -- LuaBundler/bundled.lua (generated output) -- Bundled with LuaBundle local fancyprint = (function(...) local function fancyprint(text) print(text .. " was printed with fancy text") end return fancyprint end)() fancyprint("Hello world!") ``` -------------------------------- ### Passing Arguments to Modules Source: https://context7.com/axlisin/luabundler/llms.txt Modules can receive arguments by including them after the file path in the `loadmodule` call. These arguments are accessible within the module via the `...` varargs. ```lua -- main.lua local configuredModule = loadmodule("module.lua", "arg1", 123, true) print(configuredModule.result) ``` ```lua -- module.lua local arg1, arg2, arg3 = ... return { result = string.format("Received: %s, %d, %s", arg1, arg2, tostring(arg3)) } ``` -------------------------------- ### Utility Function Script Source: https://context7.com/axlisin/luabundler/llms.txt A utility module that defines and returns a function for printing text with a custom message. ```lua -- utils/fancyprint.lua local function fancyprint(text) print(text .. " was printed with fancy text") end return fancyprint ``` -------------------------------- ### Absolute Path Imports with @ Symbol Source: https://context7.com/axlisin/luabundler/llms.txt Prefix module paths with the `@` symbol to resolve them relative to the project root, regardless of the current file's location. This is useful for importing shared configuration or utility modules. ```lua -- In any deeply nested file: src/features/auth/login.lua -- Import from project root using @ prefix local constants = loadmodule("@config/constants.lua") local utils = loadmodule("@lib/utils.lua") -- Without @, paths are relative to current file local helper = loadmodule("helper.lua") -- src/features/auth/helper.lua ``` -------------------------------- ### Force Absolute Path Resolution Source: https://context7.com/axlisin/luabundler/llms.txt Use the `[abs_path]` comment macro to explicitly force absolute path resolution for a `loadmodule` call. This achieves the same result as using the `@` symbol prefix. ```lua -- main.lua local module = loadmodule("deeply/nested/module.lua") --[abs_path] -- This is equivalent to using @ symbol: local module = loadmodule("@deeply/nested/module.lua") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.