Skip to content

[file_packager.py] Add --export-es6 to file_packager.py #24737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

lkwinta
Copy link

@lkwinta lkwinta commented Jul 18, 2025

I have added modularize option flag to file_packager.py script, like in main js generator - related to issue#24504

I think it will be helpful since in modern world of react it is inconvinent to add generated files as <script/> tags.
This pull request introduces a new --export-es6 option to the file_packager.py tool, enabling the generation of modularized JavaScript output. It enables to import generated JS loading stub into ES6 environment. The main module which will take effect of script execution is now passed as script argument.

Use scenario:

emcc -s MODULARIZE -s EXPORT_NAME=MainModule ...
file_packager.py --export-es6 ...
import MainModule from 'main_module_wasm'

// two datafiles that will be loaded at runtime with module
import { default as loadDataFile_specialName } from 'data_file_preload' 
import loadDataFile from `data_file_preload2`

var preMod = {
   // i. e. locateFile
}

var mod = MainModule(preMod)
mod.then(async (module) =>  {
    await loadDataFile(module);
    await loadDataFile_specialName(module;

    // module has now loaded data file in VFS
});

closes: #24504

@lkwinta lkwinta force-pushed the file_packager_modularize branch from c4a662f to deac6ec Compare July 22, 2025 20:00
@grzanka
Copy link

grzanka commented Jul 22, 2025

@sbc100 could you please take a look ?

@sbc100 sbc100 changed the title [file_packager.py] Add modularize to file_packager.py [file_packager.py] Add --modularize to file_packager.py Jul 22, 2025
@sbc100
Copy link
Collaborator

sbc100 commented Jul 22, 2025

Can you explain a little more in the PR description exactly what --modularize is doing here? It looks like its generating an ES6 module from the data files, is that right? How is the generated module supposed to interact with the program into which the files are to be loaded?

@lkwinta lkwinta requested a review from sbc100 July 22, 2025 21:29
@lkwinta
Copy link
Author

lkwinta commented Jul 22, 2025

Can you explain a little more in the PR description exactly what --modularize is doing here? It looks like its generating an ES6 module from the data files, is that right? How is the generated module supposed to interact with the program into which the files are to be loaded?

I have added some use case description.

As described in the related issue we are just trying to make the dynamic loading of large necessary dependencies inside web workers run from react application. Together with XHR lazy loading this seems to be only valid solution to our problem that might solve our problem.

@lkwinta lkwinta requested a review from sbc100 July 23, 2025 11:58
@lkwinta lkwinta force-pushed the file_packager_modularize branch 2 times, most recently from 1b74c3e to 05f9693 Compare July 23, 2025 21:41
@lkwinta
Copy link
Author

lkwinta commented Aug 2, 2025

@sbc100 what do you think about it now?

@lkwinta lkwinta force-pushed the file_packager_modularize branch from 47dcb43 to e2b3fc9 Compare August 2, 2025 09:56
@lkwinta lkwinta force-pushed the file_packager_modularize branch from a83bbfe to 58e06be Compare August 4, 2025 19:34
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we still need a test for this.

And might be worth adding to the changelog.

Otherwise lgtm.

@lkwinta lkwinta force-pushed the file_packager_modularize branch from 38f054e to 0a72d80 Compare August 4, 2025 21:08
@lkwinta
Copy link
Author

lkwinta commented Aug 4, 2025

Looks like we still need a test for this.

And might be worth adding to the changelog.

Otherwise lgtm.

I have added two simple tests - from what I have seen file_packager.py tests aren't really extensive.

@lkwinta lkwinta force-pushed the file_packager_modularize branch from 1e7790c to 149e8b3 Compare August 4, 2025 22:28
@lkwinta lkwinta force-pushed the file_packager_modularize branch 3 times, most recently from b011fb3 to fb98269 Compare August 5, 2025 11:58
@lkwinta lkwinta force-pushed the file_packager_modularize branch 3 times, most recently from e59ffa9 to 6f10cbb Compare August 8, 2025 13:56
@lkwinta lkwinta requested a review from sbc100 August 8, 2025 14:40
@lkwinta lkwinta force-pushed the file_packager_modularize branch from daa7616 to fd1ff56 Compare August 8, 2025 21:26
@lkwinta lkwinta force-pushed the file_packager_modularize branch from c08fbb5 to ad3b54c Compare August 8, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using standalone file_packager
3 participants