I am writing a javascript app and implementing three.js. To use this I use the script tag in my html file:
<script src="./scene.js" type="module"></script>
I have my main index.js file that contains all of the parameters and functions for my main index.html page. In this index.js I have an array of objects which I would like to pass to scene.js
I do not know how to achieve this. My understanding is that to export functions/parameters, the js file needs to be a module (declared in html using type="module"). If this is not declared as a module, I get the error 'unexpected token 'export''
If I make this a module though, I cannot reference functions in my html file that are triggered by buttons.
My index.html has my two scripts defined as this:
<script src="./index" ></script>
<script src="./scene.js" type="module"></script>
My index.js I want to export one array:
export var myArray = []
My three.js file contains the following first few lines:
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r127/build/three.module.js';
import { myArray } from './index.js';
I am confused how to continue. I cannot have everything in the one js file, as I could not import my three module