I have recently been working in p5.js in the Atom ide and have been trying to use a local p5.js library downloaded from their website. As a minimal example, I have tried to execute a basic sketch.js file using the atom online web server package (atom-live-server-plus) and by referring to the p5.js library which is positioned in the parent folder of the atom project. This way I only need one copy of the p5.js library and all my numerous p5.js projects can refer to the same library without it needing to be repeated. The issue: I have been unable to execute the code since an issue occurs when I specify the p5.js library location in the .html file using '..' syntax. Example:
<script src="..\libraries\p5.js"></script>.
Through tests I have managed identify this as an issue by finding two alternative methods to get the sketch.js file to work: A) insert the p5.js library file into the root directory, ie the project folder (test_1) and call it directly in the .html file. Example:
<script src="p5.js"></script>
B) Call an online http: website version of the p5.js library in the.html file. Example:
<script src=https://Unpkg.com/p5></script>
In both cases the sketch.js file loads on the online server as expected. However, I would like to understand why the syntax '..' to describe the path to a parent folder does not work especially as I have recently downloaded the Generative Design book code examples (https://github.com/generative-design/Code-Package-p5.js) which require an extensive set of libraries to run each code's own sketch.js file and therefore it is in my best interests to use the local library folder and keep it in the parent folder rather than copy it into each individual code project's directory. I, therefore, need to find a way to refer to a parent folder library in the .html file. Please could you provide any insight into my issue?
Minimal Example Code Structure:
p5_work
|
+-- libraries
| |
| +-- p5.sound.js
| |
| +-- p5.js
|
+-- test_1 (Atom project)
|
+-- index.html
|
+-- sketch.js
index.html Code:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>p5.js test_1 example</title>
<style>
body {
padding: 0;
margin: 0;
}
</style>
<script src="..\libraries\p5.js"></script>
<script src="sketch.js"></script>
</head>
<body>
<main>
</main>
</body>
</html>
sketch.js Code:
function setup() {
createCanvas(720, 400);
background(0);
}
function draw() {
fill(255,0,0)
ellipse(50, 50, 80, 80);
}