Skip to content

Adding js‐modules

jackdarker edited this page Apr 2, 2024 · 1 revision

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);

Clone this wiki locally