editor icon indicating copy to clipboard operation
editor copied to clipboard

ESM bundling

Open marklundin opened this issue 1 year ago • 4 comments

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
}

marklundin avatar Feb 29 '24 14:02 marklundin

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.

Can you please clarify this? Does it require creating a JSON asset by the user?

Maksims avatar Feb 29 '24 14:02 Maksims

Yep to override build options etc, otherwise it will just default to some predefined ones.

marklundin avatar Feb 29 '24 15:02 marklundin

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:

  1. Extra file loading.
  2. Discoverability - how to discover it is there, what options are supported, etc? UI solves it.
  3. Human factor - humans do type the wrong JSON.

Maksims avatar Feb 29 '24 15:02 Maksims

This work has now been completed.

marklundin avatar Aug 30 '24 11:08 marklundin