As await
can only be used inside an async function, the code below does not work.
const config_path = 'https://test.cdn.com/conf.' + location.hash.include('DEV')?'development.ts':'production.ts'
const promise = import(config_path)
export default config = await promise
So is there any way to export promise's result in es/ts module?
The deno
can support top-level await
:
await Promise.resolve(console.log('🎉'));
const strings = await import(`/i18n/${navigator.language}`);
And this feature for v8/chrome is in developing: https://v8.dev/features/top-level-await.