由于await
只能在异步函数中使用,因此下面的代码不起作用。
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
那么有什么方法可以将promise的结果导出到es/ts模块中吗?
最佳答案
deno
可以支持顶级等待
:
await Promise.resolve(console.log('🎉'));
const strings = await import(`/i18n/${navigator.language}`);
v8/chrome 的此功能正在开发中:https://v8.dev/features/top-level-await .
关于javascript - 有没有办法在es模块中导出promise的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59766731/