libcompile Plugin
Use xray16/plugins/libcompile when a game build imports runtime helpers from xray16/lib. It emits the library as a flat Lua module named xray_bundle.
Map xray16/lib to the package TypeScript source to let the inline plugin fold @inline helpers. TypeScriptToLua may still generate requires for non-inlined helpers such as round and range; this plugin makes those requires resolve at runtime.
Setup
Map xray16/lib to source and run libcompile after inline.
jsonc
{
"compilerOptions": {
"paths": {
"xray16/lib": ["../../node_modules/xray16/lib/index"],
},
},
"tstl": {
"luaPlugins": [{ "name": "xray16/plugins/inline" }, { "name": "xray16/plugins/libcompile" }],
},
}Node and Jest imports still resolve through package exports to lib/index.js.
Behavior
At emit time the plugin:
- Finds the
xray16/lib/index.tssource file in the TypeScript program. - Transpiles it with the standard TypeScriptToLua transform.
- Emits it at the output root as
xray_bundle.<extension>. - Rewrites generated
require("lua_modules.xray16.lib.index")calls torequire("xray_bundle"). - Removes the stray
lua_modules/xray16/lib/index.<extension>copy if TypeScriptToLua wrote one.
Example:
ts
import { clamp, round } from "xray16/lib";
export function normalize(value: number): number {
return clamp(round(value), 0, 100);
}With inline and libcompile enabled, clamp can be folded at the call site and round resolves from xray_bundle.
No-op Cases
The plugin does nothing when:
xray16/libis not part of the TypeScript program,outDiris not configured,- the bundle was already emitted by another plugin pass.
Limitations
- Only handles the
xray16/libentry. - Does not bundle arbitrary packages.
- Emits one flat root module. Internal
xray16/libfiles are expected to be bundled into that source entry before publish.