GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — To not include lualib into bundle · Issue #1630 · TypeScriptToLua/TypeScriptToLua

To not include lualib into bundle #1630

New issue
Copy link
New issue
Copy link
Open
Open
To not include lualib into bundle#1630
Copy link
Labels
question

Description

@inklesspen1rus
inklesspen1rus
opened on May 8, 2025
Issue body actions

Hi! 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?

Activity

  1. Zamiell commented on May 8, 2025

    @Zamiell
    Zamiell
    on May 8, 2025
    Contributor
    More actions

    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.

  2. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    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

  3. Zamiell commented on May 8, 2025

    @Zamiell
    Zamiell
    on May 8, 2025
    Contributor
    More actions

    if you want to require it then can you set luaLibImport to require?

  4. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    No, then bundle includes lualib that's not that I'm trying to get

  5. Zamiell commented on May 8, 2025

    @Zamiell
    Zamiell
    on May 8, 2025
    Contributor
    More actions

    You can just delete the lualib file afterward though with a script, right? (Assuming you are not bundling to a single file.)

  6. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    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

  7. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    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;
  8. Perryvw commented on May 8, 2025

    @Perryvw
    Perryvw
    on May 8, 2025
    Member
    More actions

    What is the reason you don't want to include the lualib into your bundle?

  9. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    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.

  10. inklesspen1rus commented on May 8, 2025

    @inklesspen1rus
    inklesspen1rus
    on May 8, 2025
    Author
    More actions

    Also I want to distribute my programs easily, ideally just one file.

  11. Perryvw
    added
    question
    on May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.