First of all, I know that Laravel is a PHP framework and has nothing to do with the front-end (JavaScript) of my application. But laravel offers the possibility to use webpack which can be used for node modules and other javascript stuff if I do it right..
What I've done so far:
Install ThreeJS using the command:
npm install three
Than execution
npm run dev
After that, I included the Library in the app.js file in the Laravel resources folder like this:
var THREE = require('three');
(I tried including it without assigning it to a variable, but that didn't seem to work, so I just did what some google research told me)
I ran npm run dev again and the library was included in the packaged app.js in the project's public/js/ path. Everything seems fine. I included the app.js file in the view and set the script attribute type to module. But now when I try to import Threejs via
import * as THREE from '三';
In my case it says the module cannot be found. I know I can copy the contents of ThreeJS in the node_modules folder to my public path JS folder, but I want to keep it as a node module. Any suggestions?
P粉6919581812024-03-29 12:36:03
I'm feeling super stupid right now, but adding a window.THREE
instead of var Three
somehow solved the problem.. Anyway, thanks for your help and time!