-
Notifications
You must be signed in to change notification settings - Fork 3
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
NPM module doesn't export #10
Comments
Hey @gridsystem! Thanks for reaching out and making me aware of this. I have never tried those use-cases in particular, was hoping the recent release, including instance mode support, would handle all those cases. I'll try to look into this more this weekend hopefully and will give an update. Thanks again, happy to improve on the library, so everybody is able to use it within his/her favorite environment. |
Hey again @gridsystem, I looked into this now. Unfortunately that's out of reach for me currently. I've set up a I was able to generally import Within this Also, functions that Are there any other My only idea would be to not rely on those hooks and require the user to do certain calls in |
Hey man. It’s late here so I’ll have a proper dig through this tomorrow. But I wanted to get a quick reply to you while it’s still fresh in your mind! I imagine the reason P5.asciify isn’t playing nicely with P5 in that setup is that they are each in their own separate module namespace. Usually when you’re publishing something to NPM, it would be packaged as a nodejs module, so that it can be installed with If the module you’re installing has a dependency, so in your case P5, P5 would be marked as a dependency in This is really different to the I’m not teaching you to suck eggs here - just want to make sure we’re on the same page with terminology etc.
What I’m not sure about though, is if you set that up in Rollup, how you would publish a script that can be imported via |
Hey @humanbydefinition ! I've had a play with the code today and found some examples from other p5 library authors. My suggestion from last night was useless because your code then adds the methods to a different instance of I have worked out how to package the module for use in browser via script tags and for use as an I've also included a reference, which has done the same thing, and a few notes about how. The reason I'm keen to get this working as an ES module is that so many sites and apps are built with Vue, React, or other frameworks that are built around modules, which don't make it easy to just add I'm not going to submit a full pull request, but here is what I've done with some comments:
So with this setup, I can
But there would definitely be some changes to make so that it works when As you've said, in an ES module environment, Here is a library, p5.brush, which works as an ES module and as a browser In their instance mode example, they run This isn't necessary with the
So yes there is a little bit of work to do to make that happen, but it seems pretty achievable. Let me know if that helps! |
Hey again @gridsystem, sorry for coming back to you so late. I really appreciate the effort you put in, and I hope and am a little confident to soon provide a solution to the problem. When I initially tested it and wasn't able to find a solution, I was a bit discouraged and worked on other things. Since I was made aware of another person with a similar report recently, I gave it another go today with better results. :) I haven't done deeper testing yet, but once I did, I'm happy to release another update to finally fix this issue. I've pushed a commit to the main-branch already, which I'll test more in the coming days: cd1baff I'm bundling the library now also via The library files in the Cheers! |
Hey again @gridsystem, hope you are doing well! I've just released a new update that hopefully fixes the issue with the library not working when imported via npm. I've tested it as you've described in a dummy Vite project and hope it'll work universally now when imported via npm. https://github.com/humanbydefinition/p5.asciify/releases/tag/v0.3.0 I'd love to get feedback by another person in to confirm. Then, i'd be able to confidently close this issue for now. :) |
After installing
p5.asciify
from npm, it's not possible to import the module into an app, as it doesn't export anything.I think it just loads itself into the global namespace?
Importing into a (very fast to set up) Vite.js app as an example,
Results in
The text was updated successfully, but these errors were encountered: