Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ES Modules in p5.js-web-editor #3358

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

takshittt
Copy link

Fixes #3304

Changes: Implemented support for import/export ESM standard modules.

Description:
Screenshot 2025-03-04 at 4 31 37 AM
This pull request adds support for import/export ESM (ECMAScript Modules) standard modules.

I have verified that this pull request:

  • [yes ] has no linting errors (npm run lint)
  • [ yes] has no test errors (npm run test)
  • [ yes] is from a uniquely-named feature branch and is up to date with the develop branch.
  • [yes ] is descriptively named and links to an issue number, i.e. Fixes #3304

Copy link

welcome bot commented Mar 3, 2025

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

@takshittt takshittt closed this Mar 5, 2025
@takshittt takshittt reopened this Mar 5, 2025
@dipamsen
Copy link
Contributor

This is an interesting idea.

I do think supporting ES Modules is a good idea since modules it is a perfectly valid way to write a p5 sketch, and sometimes has advantages over traditional scripts. However, I believe this is not how most users use/will use p5.js, due to many reasons: most p5.js tutorials use scripts instead of modules; p5.js itself is a UMD library - it doesn't expose a ESM distribution (by nature, it will be very hard if not impossible for it to do so).

I have the following questions:

  1. Is it needed to have duplicated option for 'New Project' just for projects using ES Modules? I think someone who wants to use ESM to write their code has the know-how to change 3 lines of code from the default starter sketch, to get a 'ESM project'. I don't think this feature has enough benefit, but instead may be confusing to beginners.
  2. Your isModule check should just be from whether it is linked as type="module" or not, checking whether import or export exists is a weak condition to know whether a file is a module. (eg. the word may match within comments and strings, or in a module there may be no imports or exports)
  3. does this work on all types of imports and exports? (ref: import, export)
  4. Does it suffice to just replace the import path with the blob url? If so, a lot of code duplication can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add import and export as ESM Modules
3 participants