Skip to content

Distribute Treeshakable ESM code #4127

Closed

Description

@b12f

Nature of issue?

  • Found a bug
  • Existing feature enhancement
  • New feature request

Most appropriate sub-area of p5.js?

  • Color
  • Core/Environment/Rendering
  • Data
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

New feature details:

The NPM p5 module currently ships a file that bundles all code into the commonjs format. This prevents treeshaking of unused code. Since the code itself is already written with the import/export syntax, distributing a treeshakable version should be as easy as providing a module key in the package.json and including the raw source, e.g. under p5/lib/esm/color or maybe even p5/color

Activity

  1. welcome commented on Nov 2, 2019

    @welcome

    Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

  2. limzykenneth commented on Nov 3, 2019

    @limzykenneth
    Member

    I think it is interesting to explore this but I think there may be too much side effects in the library for it to be able to be used effectively. I'm not sure though.

  3. b12f commented on Nov 4, 2019

    @b12f
    Author

    Yeah, at first I thought this would be easy, but after looking at the code it seems a bit harder. It should be possible however to ship the current esm code with a special sketch wrapper, and then a second wrapper for the cjs format, keeping all else the same.

  4. b12f commented on Nov 4, 2019

    @b12f
    Author

    The most immediate change would be to remove all usages of a direct import 'filename.js', and only import { whatever, is, being, used } from 'filename.js'

  5. limzykenneth commented on Nov 4, 2019

    @limzykenneth
    Member

    The most immediate change would be to remove all usages of a direct import 'filename.js', and only import { whatever, is, being, used } from 'filename.js'

    I think that's a good first step.

  6. lmccart commented on Dec 16, 2019

    @lmccart
    Member

    thanks @b12f. we're not able to prioritize this format right now but perhaps can revisit at a future date.

  7. CarstenHoyer commented on Dec 21, 2020

    @CarstenHoyer

    @lmccart - It's been a year. Perhaps it could be prioritized now? I would be interested in putting some work into it.

    In my mind, I think we would need a esm-init.js, that would abandon the global p5 instance approach.

    I think this would be wortwhile, because it:

    • would make the code tree shakeable
    • Would make p5 more usable in other libraries
    • make the bundle size for other modules smaller - ie a react renderer.
  8. huumpf commented on Jun 2, 2021

    @huumpf

    @lmccart I'd really love to seeing this happening as well!

    I'm one of those guys who p5 probably was made for. I'm a Designer/Visual Artist who's not really good enough in coding to contribute to the library itself but I'm loving p5 for what value and fun it brings me – even with my limited coding-skills!

    I've actually had a couple projects and moments, where I would have loved to contribute to production-code for websites etc. – Sadly it never happened bc the "real" devs refused to implement the complete giant library that is p5 (which btw. totally makes sense to me at this point).

    If there would be any way for people like me to realistically make use of the creative coding part in an actual public web-project, I would love you guys even more than I do already :-)

  9. limzykenneth commented on Jun 2, 2021

    @limzykenneth
    Member

    @huumpf You can open a new issue and fill in the relevant issue template, particularly the question about accessibility. Thanks.

  10. huumpf commented on Jun 2, 2021

    @huumpf

    @limzykenneth would that be your preffered way of addressing this topic (again) or give it more visibility? I thought sticking to an existing thread and just +1ing it would be way to go to avoid "this has already been discussed in #xyz".

    Anyway, I'm happy to do whatever is helpful. Tbh i could probably not think of a better way to phrase it than i've already done above. Also, I'm not sure what you mean with "question about accessibility".

  11. limzykenneth commented on Jun 3, 2021

    @limzykenneth
    Member

    @huumpf I would suggest opening a new issue to avoid pinging people who were previously in this thread but no longer want to be notified about this activity. Also we have new requirements for accepting new features which is reflected in an updated issue template that need to be filled in.

    In short the access requirement boils down to we will only accept feature requests that increases access, it does explain much on its own but do read more here, which means that for this particular feature, an argument for how it increases access of p5.js for people who may be excluded from the technology or p5.js community.

  12. davidbwaters commented on Jun 22, 2021

    @davidbwaters

    @lmccart I'd really love to seeing this happening as well!

    I'm one of those guys who p5 probably was made for. I'm a Designer/Visual Artist who's not really good enough in coding to contribute to the library itself but I'm loving p5 for what value and fun it brings me – even with my limited coding-skills!

    I've actually had a couple projects and moments, where I would have loved to contribute to production-code for websites etc. – Sadly it never happened bc the "real" devs refused to implement the complete giant library that is p5 (which btw. totally makes sense to me at this point).

    If there would be any way for people like me to realistically make use of the creative coding part in an actual public web-project, I would love you guys even more than I do already :-)

    Just FYI, I'm in the same boat and found https://github.com/LingDong-/q5xjs. It doesn't include 3d (yet), but might be useful in this situation.

  13. davidbwaters commented on Jun 22, 2021

    @davidbwaters

    And generally speaking, lowering the bundle size directly increases accessibility in areas where bandwidth and internet connection speeds are an issue. China seems to be a region affected by this and p5 seems to be popular with Chinese devs based on some cool demos I've seen on Twitter (search for p5 and you'll see a bunch). So as far as being good for the community and accessibility, it seems like a win. Also, ESM is a web standard and isn't going anywhere. Being able to optimize loading would offer the best experience for running processing in a browser.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions