-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Milestone
Description
The current PlayCanvas script format was introduced in July 2016. PlayCanvas scripts are snippets of JavaScript that are (asynchronously) loaded and then, once loaded, immediately executed in global application scope.
The current PlayCanvas script format has a number of problems:
- The current default script template is still generated based on the ES5 feature set of JavaScript. This is looking increasingly antiquated in a world where ES Modules have become dominant. JavaScript has moved on considerably over the last 10 or so years.
- Developers want to leverage tree shaking to generate an application bundle that only includes the code necessary to execute the application. The current script format is not compatible with tree shaking because it does not specify the specific symbols on which the code relies. ESM does this with the
import
statement. - Developers want to be able to run a build system (like Rollup, Webpack etc). This would allow them to run transpilers (e.g. Babel), minifiers (e.g. Terser) and so on. These build tools (or bundlers) tend to take ES Modules as input. Our current script format does not play nice with these bundlers.
- While you can run PlayCanvas in Node if you use the ES5 build of the engine, the current script system cannot be used with the module build (or if you run the source directly in Node, as with our engine unit tests). When the scripts are loaded (by doing a dynamic
import
call), thepc
namespace doesn't exist. The script would need to import what it needs. - Intellisense in VS Code (or the Code Editor's Monaco) does not work too well with
ScriptType
-based scripts. For example, attributes don't resolve correctly. An ES Module containing a class might be a better approach.
So I propose that we investigate the development of a new script format that:
- Is based on ES Module format.
- Is based on ES6 class syntax.
- Supports dynamic loading (say when running the Launch tab from the PlayCanvas Editor).
- Supports easy-to-use hot reloading.
- Supports being built into a bundle (by the likes of Rollup etc).
- Supports Intellisense well in VS Code/Monaco.
- Can be run in Node when running the engine as a module or from source modules (this is critical for unit testing in Node, say).
- Is compatible with TypeScript.
I welcome comments from the community on this proposal.
quantizor, marklundin and awulkanmvaligursky, querielo, knownasilya, yaustar, christinakal and 18 moremarklundin and LocalStarlight
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done