Adding js‐modules - jackdarker/TwineTest GitHub Wiki
For example you have written some code in ThreeMod.js that makes use of Three.js.
Assuming you have copied ThreeMod.js to ./dist/ and three-module is located in ./dist/node_modules
TODO: why cant I add ThreeMod.js to src/scripts instead?
-
in head-content.html you have to add
<script type="importmap">{"imports": {"three": "./node_modules/three/build/three.module.js"}}</script><script type="module" src="ThreeMod.js"></script> -
in ThreeMod.js you can now use imports
import * as THREE from './node_modules/three/build/three.module.js'; -
in ThreeMod.js I add functionality to global windows
(function(){
window.three = window.three || {views:null,models:null,activeViews:null,clock:null};
window.three.init=function() {...}
...
})(window);