In P5.js, how to use ES6’s import in top of sketch.js?
1 Like
Do you mean JS’ native ECMAScript Modules (ESM) by the way:
ExploringJS.com/es6/ch_modules.html
Unfortunately, p5js library isn’t yet natively “importable” by JS newest import
keyword, nor by its corresponding builtin import() function:
Actually, even very famous libraries/frameworks like React aren’t compatible w/ it yet w/o relying on some other 3rd-party solutions:
However, even though p5js isn’t itself compatible w/ this latest JS feature, we can still split our own sketches as ES modules, like I did once for my sketch “Ball-in-the-Chamber”:
1 Like