Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
linzb93 opened this issue Mar 9, 2024 · 4 comments
Open

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

linzb93 opened this issue Mar 9, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@linzb93
Copy link

linzb93 commented Mar 9, 2024

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

@linzb93 linzb93 added the help wanted Extra attention is needed label Mar 9, 2024
@subframe7536
Copy link

试试rollupOptions.external

external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),

@linzb93
Copy link
Author

linzb93 commented Mar 9, 2024

试试rollupOptions.external

external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),

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

@subframe7536
Copy link

@linzb93
Copy link
Author

linzb93 commented Mar 10, 2024

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'),
  ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants