Import 'playcanvas' in ESM Scripts
Support importing playcanvas in ESM Scripts
As per https://github.com/playcanvas/engine/issues/4767, users should be able to import playcanvas code in ESM Scripts without using the pc global.
import { Vec3, ScriptType } from 'playcanvas'
class Rotator extends ScriptType {
initialize(){
this.dir = new Vec3(1, 0, 0);
}
}
This requires a number of changes to launcher and to exported projects.
Launcher
- [x] Export a bundled ES6 playcanvas build https://github.com/playcanvas/engine/pull/6073
- [x] Upgrade the launch page to use the ES6 build.
- [x] Add
playcanvasto the global import map. Depends upon https://github.com/playcanvas/editor/issues/1108
exported projects
- [x] Upgrade the exported projects to use the ES6 build.
- [x] Add
playcanvasto the exported projects import map
Considerations
- Users often mutate the global pc object to hold state etc. Any changes made, should not break existing projects
- Upgrading to the ES6 build in the launcher force a minimum browser version. Again this should be done without breaking projects.
Users often mutate the global pc object to hold state etc. Any changes made, should not break existing projects
Do you foresee much work for this one? I'm not convinced this is something we explicitly want support. If users are mutating engine they should probably have the option of providing their own (modified) engine instead (or something like that).
This is more like if users are currently mutating the pc global in a project. If we don't provide a mutable global, then current projects will break. End goal is to migrate away from this, but there needs to be a transition period.
This has been completed.