I still trying to get p5.js library working. In this case, I want to install the library by hand instead yarn procedure.
-
First, I’ve checked the library (
p5.min.js
) in a simple HTML file, importing it in the<head>
with<script src="../p5.min.js"></script>
. It works perfectly outside Sage! -
Then, I put
p5.min.js
insideresources/assets/scripts/
. -
I create
.eslintignore
file to avoid linting ofp5.min.js
with this content:
resources/assets/scripts/p5.min.js
. -
I add the arrays to
entry
inresources/assets/config.json
as follows:
"p5.min": [
"./scripts/p5.min.js"
],
"p5.dom.min": [
"./scripts/p5.dom.min.js"
]
- I’ve
enqueued script at app/setup.php
as follows:
wp_enqueue_script('sage/p5.min.js', asset_path('scripts/p5.min.js'), [], null, true);
- After
yarn build
, all files seems to be in their place: Webpack have created its filep5.js.min
atdist/scripts/
and the script is enqueued at the end of the body:
<script type="text/javascript" src="//localhost:3000/app/themes/tlm/dist/scripts/p5.min.js"></script>
Problem
When I init the library using routing, for example, at script/routes/commons.js
(with instantiation mode to avoid scope problems):
var sketch = function(p) {
p.setup = function () {
p.createCanvas(500, 500);
p.background(200);
};
};
new p5(sketch);
I get an eslint error: error ‘p5’ is not defined no-undef.
I’ve checked it for hours and I can’t detect the cause. What is wrong in these steps? is a specific problem with this library? Any help appreciated!