… and also some get arounds to pass arrays from PHP to Javascript.
… okay that was a random bit that I'm just very excited to have found on the internet, I digress.
I'd preface this by saying my programming knowledge is pretty limited and if you think what I am going to do next is dumb or old, feel free to correct me, thanks.
So I wanted to use some npm packages (namely A-Frame and it's components), but since my company uses traditional-styled PHP, I had problems just say import package from "package"
or something like that. Therefore we would need some other way to use npm pacakges. I am not sure how other packages, say React, would react (ba dumb tsz) but for my limited usage the source placed up top seems to work.
However there are some revisions I would like to point out because the authors methods didn't work for me.
First create two files
index.html
node_packages/index.js
Go into the node_package/
(or whatever you want to name it) directory and npm init
and install some packages
Go into your packages.json
file and add the following lines
import pacakge from "package"
in the index.js
file. Run npm run build
and then attach the Javascript file onto index.html
with <script src="node_packages/dist/bundle.js">
and you could use npm pacakges in basic HTML.
If you'd like to fully follow along here's the full test code I have.
https://gitlab.com/imfulee/es6-html-demo