[RFC] Proposed Upgrade of Editor to ES6 build #6065
Replies: 4 comments 2 replies
-
Let's say I make a library MyLibrary that creates a new component system in a given application instance. I would want it to eventually work for both engine-only and Editor users. Could you please guide me through the path I would expect the users take to import my library and my bundling? Say, I don't support ES5 devices, would this be the flow: Editor user creates an // say my library is an asset script called `library.min.js` and inits via a promise
import { init } from 'library.min.js'; // or should it use a lib name instead of filename?
class MyClass {
async initialize() {
await init(this.app);
}
} Lets say my library is not using any of the PlayCanvas engine systems, but it wants to instantiate some defaults, like vectors. Today, it would be this way, if the lib is run in Launcher: function(a = pc.Vec3.ZERO) {} This assumes there is a import { Vec3 } from 'playcanvas';
function (a = Vec3.ZERO) {} But that will import the class into the library, which will increase its size. Or is there another way? |
Beta Was this translation helpful? Give feedback.
-
How will this affect existing PlayCanvas editor projects? Will they all need to be updated when this is deprecated? |
Beta Was this translation helpful? Give feedback.
-
Would we be able to define our own importmap entry? We'd like to export all related SDK classes in a single file and refer to it in importmaps. Then all game scripts can use some alias, like import { Animation } from 'SDK'; |
Beta Was this translation helpful? Give feedback.
-
Yep we have a ticket for this playcanvas/editor#1108 |
Beta Was this translation helpful? Give feedback.
-
Proposed Upgrade of Editor to ES6 build
ESM Script has now shipped #5764. Users should be able to use import playcanvas in their scripts like;
However the launch page and exported projects both use the older ES5/UMD build which cannot be imported using ES6 import syntax. Therefore we need to upgrade the editor to use the ES6 build in a way that is backwardly compatible with existing projects.
The PC global
One of the main distinctions is that the UMD build exports a global
pc
object namespace whereas the ES6 build does not. All existing project scripts depend upon this, and so it cannot be removed.Proposed Upgrade
From :
To:
Note: There is currently an issue with the engine build that prevents the UMD build parsing in non older browsers #6011.*
Should the UMD build deprecated?
As of Feb 24, ES modules stands at 97% support, and our UMD build adds less than 0.1% (TBC) more users. Legacy Scripts have been deprecated in projects.
Provide clear direction to developers
Even if we do continue to support an ES5 workflow, we should provide a consistent and ciherent recommended approach for using scripts
We Need Your Feedback
Your insights are crucial to ensure a smooth transition. Specifically, we're looking for feedback on:
Please share your thoughts directly in this thread. Your input will help us cover all bases and support everyone through these changes.
Beta Was this translation helpful? Give feedback.
All reactions