editor icon indicating copy to clipboard operation
editor copied to clipboard

Import 'playcanvas' in ESM Scripts

Open marklundin opened this issue 1 year ago • 2 comments

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 playcanvas to 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 playcanvas to 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.

marklundin avatar Mar 04 '24 14:03 marklundin

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).

slimbuck avatar Mar 08 '24 08:03 slimbuck

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.

marklundin avatar Mar 08 '24 09:03 marklundin

This has been completed.

marklundin avatar May 13 '24 10:05 marklundin