美文网首页1024Web前端之路Vue.js
解决 vite build打包报错Top-level await

解决 vite build打包报错Top-level await

作者: 圆梦人生 | 来源:发表于2023-03-29 09:55 被阅读0次

一、错误原因
最高层中不让使用 await
二、解决方案
1.引入vite-plugin-top-level-await

npm install vite-plugin-top-level-await -D

2.在vite.config.js配置此插件

import topLevelAwait from 'vite-plugin-top-level-await'

export default defineConfig({
  plugins: [
    topLevelAwait({
      // The export name of top-level await promise for each chunk module
      promiseExportName: '__tla',
      // The function to generate import names of top-level await promise in each chunk module
      promiseImportName: i => `__tla_${i}`
    })
  ]
});

来源:https://www.jianshu.com/p/fb1ad30fd743

相关文章

网友评论

    本文标题:解决 vite build打包报错Top-level await

    本文链接:https://www.haomeiwen.com/subject/fjkfddtx.html