GeezerVison is showing github.com — To not include lualib into bundle · Issue #1630 · TypeScriptToLua/TypeScriptToLua
To not include lualib into bundle #1630DescriptionHi! Thank you for great project!
I'm trying to make bundle from project with a lot of files but with external lualib. But didn't find any possible way. Is it possible? ActivityZamiell commented on May 8, 2025 Hello!
I think you could set luaLibImport equal to none. See: https://typescripttolua.github.io/docs/configuration
Then, you could make sure that the things like __TS__Class and so on are set as global variables and defined elsewhere before your code runs.
However, I am not 100% sure if this is a good solution for your particular project though, I would need more context as to what you are trying to do. inklesspen1rus commented on May 8, 2025 Sadly but I can't predefine exports from lualib.
My ides is bundle which imports lualib from environment, i.e. require('lualib_bundle')
luaLibImport = none makes bundle do not require lualib at all
Zamiell commented on May 8, 2025 if you want to require it then can you set luaLibImport to require? inklesspen1rus commented on May 8, 2025 No, then bundle includes lualib that's not that I'm trying to get Zamiell commented on May 8, 2025 You can just delete the lualib file afterward though with a script, right? (Assuming you are not bundling to a single file.) inklesspen1rus commented on May 8, 2025 Probably I'm bad in english so you're misunderstanding me
I'll show example
Here is my test project:
project.zip
I want to get this bundle (with no lualib included but require('lualib') still exists:
good_bundle.txt
But TSTL produces me this (lualib included):
bad_bundle.txt inklesspen1rus commented on May 8, 2025 Well I resolved that for me with a small plugin
Looks not so good and it additionaly minifies bundle but that works
import * as ts from "typescript";
import * as tstl from "typescript-to-lua";
const luaparse = require('luaparse')
const luamin = require('luamin')
const plugin: tstl.Plugin = {
beforeEmit(program: ts.Program, options: tstl.CompilerOptions, emitHost: tstl.EmitHost, result: tstl.EmitFile[]) {
if (!options.luaBundle) return;
const file = result[0];
const ast = luaparse.parse(file.code, {
luaVersion: options.luaTarget,
scope: true
})
const modules = (ast.body as any[])
.filter(x => x.type == 'AssignmentStatement' && (x.variables as any[]).find(x => x.name == '____modules'))
const initIdx = (modules[0].variables as any[]).findIndex(x => x.name == '____modules')
const initFields = modules[0].init[initIdx].fields as { key: {raw: string} }[]
const lualibIdx = initFields.findIndex(x => x.key.raw == `"lualib_bundle"`)
initFields.splice(lualibIdx, 1)
file.code = luamin.minify(ast)
},
};
export default plugin;Perryvw commented on May 8, 2025 What is the reason you don't want to include the lualib into your bundle? inklesspen1rus commented on May 8, 2025 I'm developing programs for computers in minecraft with OpenComputers mod.
Hard drives and RAM there have very limited size (up to 4MB for hard drivers, up to 1.5MB for memory sticks)
Current bundle contains a copy of lualib which sizes ~80kb (and ~80kb in memory).
Each bundle, loaded in memory, contains it's own copy of luabundle. Loading 4 programs at once will consume ~320kb bcs of lualib included.
Removing lualib from bundle saved for me ~240kb bcs of sharing lualib between programs.
Also my plugin saved 50kb of space and 30kb of memory due to smaller variable names.
I want to run several programs at once so that change will save for me a lot of space and memory. inklesspen1rus commented on May 8, 2025 Also I want to distribute my programs easily, ideally just one file.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|