How to js import into other scripts

In Javascript I am able to:

// helper.js
export const convert = function(data){
    // function logic
}
// some other file.js
import {convert} from '../helper.js'
convert(data)

Am I able to do this in Playcanvas?

The Editor workflow doesn’t support imports and relies on expose classes/variables/functions globally.

It effectively just adds all the JS files to the HTML page with <script> tags in the loading order defined here: Loading Order | Learn PlayCanvas

1 Like

For anyone landing on this topic, we are actively working on native ES Modules support, you can track progress in the Github PR below.

2 Likes

official support beyond a year. dope.

1 Like