With this code I am able to successfully import / access variables and functions when they are individually exported, but I want to be able to export the entire file in a single declaration. I’ve tried a number of variations from here but cannot achieve this.
script.js
import * as testImport from './test.js';
console.log( testImport.testVar ); // Returns 'Test Variable'
console.log( testImport.testFunc() ); // Returns 'Test Function'
test.js
export let testVar = 'Test Variable';
export function testFunc() {
return 'Test Function';
}
desired ( without individual ‘exports’ )
let testVar = 'Test Variable';
function testFunc() {
return 'Test Function';
}
export * // ?
>Solution :
There is no such thing like you ask for, because it conflicts diametrically with the intention behind modules.
The whole point of modules is too keep all variables private to the module with the exception of making those explicitly exported available for importing.