Hey there!
I downloaded p5 via npm locally in one of my projects. Now how do I import it to the index.html
file?
Is doing this worth it? Or should I rather abandon this idea and use the CDN instead?
Hey there!
I downloaded p5 via npm locally in one of my projects. Now how do I import it to the index.html
file?
Is doing this worth it? Or should I rather abandon this idea and use the CDN instead?
'use strict';
function setup() {
createCanvas(800, 600).mousePressed(redraw);
noLoop();
}
function draw() {
background('#' + hex(~~random(0x1000), 3));
}
<script defer src=node_modules/p5/lib/p5.js></script>
<script defer src=sketch.js></script>
<script defer src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=sketch.js></script>
Thank you @GoToLoop.
I have another question: I have my project inside a long path of sub-folders. So is there a way I can lead the path
variable staright to the root repository and then into the node modules?
You can use ../
in order to go up to the parent folder of the current folder.
You can also begin from the base folder by starting the path w/ /
:
<script defer src=/node_modules/p5/lib/p5.js></script>