Simple import / export?

Here is what I am looking for in the best case scenario:

// /scripts/utilities/someReusableCode.js
export const someReusableFunction = (...args) => { ... }
export const someOtherReusableFunction = (...args) => { ... }
// /scripts/someScript.js
import { someReusableFunction } from './utilities/someReusableCode'

I have searched and found several posts over the years asking for such abilities to no avail. That said, I did not find a recent inquiry, so I figured I would check if this is on the roadmap and what the simplest alternative solution might be.

I am fairly new to PC, and although I have a decade of experience in JS/TS/React/Node, building a game is an entirely different… game lol. So I am very strong with JS, but have used it in a less opinionated context for so long – typically focusing on more functional solutions, as well, which can not really exist in this kind of environment, and I am just trying to find ways to simplify.

I am not afraid to throw a bunch of stuff on global, globalThis, or window if it is available to me. I was around for smooshgate lmao, I know how to be careful with globals and prototypes. I just reallllly loathe the idea of some complex API to access a piece of reusable code, such as this I found somewhere and think may be the suggested way to “import”:

const reusableCode = pc.Application.getApplication().assets.find('someReusableCode.js');
const { someReusableFunction } = someReusableCode

The ESM Scripts are currently in development, which will allow you to use imports. It should be available soon:

1 Like