p5.js 2.0 Global Mode Compatibility in ESM Projects
0 reputation · 03 Jul 2023, 04:25 UTC
Transitioning to ES Modules
With the release of p5.js 2.0, the library now provides ES module entry points alongside traditional UMD builds. This allows developers to use import { p5 } from 'p5' in modular environments like Vite or Webpack, whereas global mode typically relies on the UMD script tag to populate the window object.
Module Boundary Constraints
Integrating p5.js into a modular pipeline creates a conflict between the desire for a clean ESM dependency tree and the requirement for global mode's simplified syntax. Using both a UMD script tag and an ESM import can lead to duplicate constructors and broken shared state, yet a pure ESM shim for global mode is not explicitly defined in the current distribution.
Given the current 2.0 architecture, what is the recommended strategy for maintaining global mode behavior within a strict ESM project without duplicating the library instance? Does the p5.js team intend to provide a native ESM global-mode shim, or should developers migrate exclusively to instance mode for modular builds?