electron-vite / electron-vite-vue

🥳 Really simple Electron + Vite + Vue boilerplate.
https://electron-vite.github.io
MIT License
3.98k stars 527 forks source link

[Help] mysql2这个npm包无法被排除构建 #471

Open linzb93 opened 4 months ago

linzb93 commented 4 months ago

我是在主进程中使用的,引入代码是import mysql from 'mysql2/promise'。运行npm run dev后,在dist-electron/main文件夹下发现打包后的文件很大,根据排查发现是mysql2这个包没法被排除构建,不能以import的方式引入。 然后我在vite.config.ts中设置,不管是defineConfig下面的,还是electron plugin里面的vite属性里面配置optimizeDeps.exclude: ['mysql2']都无效。 我引入的其他包,例如jsonwebtoken就没有问题,被排除在外了。

subframe7536 commented 4 months ago

试试rollupOptions.external https://github.com/electron-vite/electron-vite-vue/blob/af8aa6cf7c3bc65fa14ae53b0fa31094f0c9f5ea/vite.config.ts#L39

linzb93 commented 4 months ago

试试rollupOptions.external

https://github.com/electron-vite/electron-vite-vue/blob/af8aa6cf7c3bc65fa14ae53b0fa31094f0c9f5ea/vite.config.ts#L39

也试过了,mysql2就在dependencies里面,还是无效。

subframe7536 commented 4 months ago

这个试过吗 https://github.com/electron-vite/vite-plugin-electron/tree/main?tab=readme-ov-file#not-bundle

linzb93 commented 4 months ago

https://github.com/electron-vite/vite-plugin-electron/tree/main?tab=readme-ov-file#not-bundle

试了,但是TypeScript没通过,又撤回了。


plugins: [
    command === 'serve' && notBundle(filters: id => id == 'mysql2'),
  ],