I need to import hundreds of global variables from global.js to the main.js.
Does JavaScript have an efficient method to import all exports from that file at once, without importing them one-by-one?
I could import them all as a large object e.g. g
and address them like g.myVar1
, but I prefer to avoid that.
Even importing one-by-one esbuild gave me the error: "imports are immutable in JS" so only global constants can be imported, not variables. So apparently there is no solution to this question...
if you're using nodejs then this is an option.
global variables are implicitly declared when imported as long as they were not declared with var, const or let
e.g.
//global.js
myGlobalVariable = 'my value'
//app.js
require('./global.js')
console.log(myGlobalVariable) //output - 'my value'