antvis/G6

VITE5 packs vue3 + antv G6v5 and returns an error after it goes online #6472

afenkar posted onGitHub

Describe the bug / 问题描述

打包时没有错误,上线使用时会报错。 报错内容 要么是 Uncaught SyntaxError: Invalid or unexpected token 要么是 Uncaught SyntaxError: Unexpected end of input 版本信息如下vite和g6都是目前最新 image 目前怀疑是版本问题,因为以前使用过vite5和g6 v4是没问题的,但是个人感觉g6 v5方便许多,希望进一步改善

No response

Steps to Reproduce the Bug or Issue / 重现步骤

No response

G6 Version / G6 版本

🆕 5.x

Operating System / 操作系统

Windows

Browser / 浏览器

Chrome

Additional context / 补充说明

No response


麻烦发下完整的错误截图

posted by Aarebecca 6 months ago

麻烦发下完整的错误截图 报错整体是 Uncaught SyntaxError: Invalid or unexpected token (at index-BfVYHK2N. js:587:4446)

posted by afenkar 6 months ago

麻烦发下完整的错误截图

屏幕截图 2024-11-04 144807

posted by afenkar 6 months ago

你需要进一步进到源码,查看具体导致错误的 token 是什么

posted by Aarebecca 6 months ago

你需要进一步进到源码,查看具体导致错误的 token 是什么

定位字符在这里 <img width="908" alt="屏幕截图 2024-11-05 105725" src="https://github.com/user-attachments/assets/f0122563-c5ec-41ad-ab08-328f6a1d3d29">

posted by afenkar 6 months ago

已解决

在打包时发现提示: (!) Some chunks are larger than 500 kB after minification. Consider: - Using dynamic import() to code-split the application - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks

于是,在vite.config.js中设置: build: { chunkSizeWarningLimit: 1500, // 调整为1500kB或更大 rollupOptions: { output: { manualChunks(id) { if (id.includes('node_modules')) { const arr=id.toString().split('node_modules/')[1].split('/') switch (arr[0]){ //除了axios和 vue-router 不能单独打包,其他全部依赖 case '@antv/g6': case 'ant-design-vue': case 'geolib': case 'js-cookie': case 'js-md5': case 'pinia': case 'vue': case 'vue-i18n': return '_' + arr[0] break default: return '_vendor' break } } },
}, } }

打包上线可以正常使用了

posted by afenkar 6 months ago

Fund this Issue

$0.00
Funded

Pull requests