Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import 'playcanvas' in ESM Scripts #1118

Closed
5 tasks done
marklundin opened this issue Mar 4, 2024 · 3 comments
Closed
5 tasks done

Import 'playcanvas' in ESM Scripts #1118

marklundin opened this issue Mar 4, 2024 · 3 comments
Assignees

Comments

@marklundin
Copy link
Member

marklundin commented Mar 4, 2024

Support importing playcanvas in ESM Scripts

As per playcanvas/engine#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
exported projects
  • Upgrade the exported projects to use the ES6 build.
  • 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 marklundin self-assigned this Mar 4, 2024
@marklundin marklundin moved this to In progress in ESM Scripts Mar 4, 2024
@slimbuck
Copy link
Member

slimbuck commented Mar 8, 2024

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

@marklundin
Copy link
Member Author

marklundin commented Mar 8, 2024

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
Copy link
Member Author

This has been completed.

@github-project-automation github-project-automation bot moved this from In progress to Done in ESM Scripts May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants