ESM bundling
Support for ESM bundling
This is a WIP progress ticket to track and discuss bundling for ESM based projects
As the engine and editor will soon support ES Modules https://github.com/playcanvas/engine/issues/4767, users should be able to export bundled versions of projects with ESM Scripts. This can improve network load by providing optimised builds that end users have control over.
Potential Features
- Treeshaking / deduplication - Unused dead code is removed
- Code splitting - Allow lazy loading of non essential code.
- Transformations - Lowering to required ES* version
- Minifcation
- Symbol removal - swap out sensitive development symbols at build time
This can be specified using a simple build.json in the root of the project, if none are found we use a pre-defined set of options.
build.json
{
"minify": true,
"treeShaking": true,
"target": [ "es2020", "edge16", "firefox57"],
}
Additionally users can define a debug.build.json used in the launcher. This will allow user to configure different environments depending on the environment.
debug.build.json
{
"minify": false,
"treeShaking": false
}
This can be specified using a simple
build.jsonin the root of the project, if none are found we use a pre-defined set of options.
Can you please clarify this? Does it require creating a JSON asset by the user?
Yep to override build options etc, otherwise it will just default to some predefined ones.
Yep to override build options etc, otherwise it will just default to some predefined ones.
As the Editor has the benefits of having UI, this is better to be implemented as UI elements. Otherwise, there are a couple of issues:
- Extra file loading.
- Discoverability - how to discover it is there, what options are supported, etc? UI solves it.
- Human factor - humans do type the wrong JSON.
This work has now been completed.