打包报错如下
问题所在
因为做动态配置IP及端口,打包后随时改随时生效 ,代码使用了let baseURL = await axios.get(‘./config.json’);
处理办法
1、下载插件
cnpm install vite-plugin-top-level-await -D
2、vite.config.js配置
import topLevelAwait from 'vite-plugin-top-level-await';
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}`
})
],
然后就搞定了。我也是参照了网上其他博主的方法,这里只是做个人项目踩坑记录。物喜勿喷!!!!