I used p5.js occasionally over the past 2 years for playing around and experimenting.
Now I want to use it for a more serious project - and one concern is the filesize of p5.min.js.
I am using the npm version, but it seems you are exactly getting the same minified js compared to downloading it on the p5 homepage.
So I was looking into the source code a bit and found out, that the file seems to contain the whole documentary - so a lot of long strings which are not needed for production.
My question is: Is there a more minimal version of p5.js / p5.min.js?
The original js file, the one the min.js file is generated from I think, starts with ~30k lines of data which just seems to be needed for the documentation.
for example something like this:
example: [
'\n<div><code>\nlet polySynth = new p5.PolySynth();\nlet pitches = ["G", "D", "G", "C"];\nlet octaves = [2, 3, 4];\n\nfunction mousePressed() {\n // play a chord: multiple notes at the same time\n for (let i = 0; i < 4; i++) {\n let note = random(pitches) + random(octaves);\n polySynth.noteAttack(note, 0.1);\n }\n}\n\nfunction mouseReleased() {\n // release all voices\n polySynth.noteRelease();\n}\n</code></div>'
],
In the file I downloaded from p5js.org (starting with: /*! p5.js v0.10.2 October 14, 2019 */, so I suppose the same @GoToLoop refers to as well) I do not see the string ârelease all voicesâ for instance.
Which version do you have?
I am on the same version. But it seems like the p5.min.js isnât a 1 to 1 build from the p5.js file.
But I still wonder why the p5.min.js is ~560kB large. Thatâs quite big for a minified javascript file imho.
Interesting. Maybe open this advice as issue on p5.js? Seems like a reasonable âhelp wantedâ / âfirst issueâ for someone who knows JS but is not familiar with the inner workings of p5.js
Given your specific requirements, have you considered creating your own npm package?
While minifying shader comments seems like it could be added to the pipeline if you opened an issue and suggested it, I suspect (I am not a core dev, so I donât know) that splitting out WEBGL et cetera is never going to happen â that kind of fine-grained use isnât part of the core audience / mission for p5.j.s, and it is more of a âbatteries includedâ project aimed at a very wide audience including entry-level.
Given your specific requirements, have you considered creating your own npm package?
yes, but sadly I havenât got the time right now.
I am now thinking about using the native Canvas 2D API because this would fulfill the needs of my current project.
But I still really think it would be awesome if we could have lightweight p5 modules.
e.g. if I only want to do canvas 2D stuff - I donât need WEBGL or shaders.
When I am doing WEBGL I donât need the canvas 2D stuff - and maybe I only want to use my own shaders, and so on.