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

Is externalizeDepsPlugin taking modules dependencies into accounts ? #71

Closed
4 tasks done
michael-dm opened this issue Dec 10, 2022 · 5 comments
Closed
4 tasks done
Labels
question Further information is requested

Comments

@michael-dm
Copy link

Describe the bug

I might just misunderstand how the plugin works but I find that dependencies in package.json are correctly externalised, but not their dependencies, forcing me to add each and every one of them to my package.json.

Is it intended behaviour ?

Electron-Vite Version

1.0.15

Electron Version

22.0.0

Vite Version

3.2.5

Validations

@michael-dm michael-dm added the bug Something isn't working label Dec 10, 2022
@alex8088
Copy link
Owner

@michael-dm

For the main process and preload scripts, the best practice is to externalize dependencies and only bundle our own code.
So the externalizeDepsPlugin is designed to externalize all dependencies in package.json and we need to install the dependencies required by the app into the dependencies of package.json. When packaging the app, these dependencies will also be packaged together, such as electron-builder. Don't worry about them being lost. On the other hand, devDependencies will not be packaged.

It is important to note that some modules that only support ESM, we should not externalize it. We should let electron-vite bundle it into a CJS standard module to support Electron.

For renderers, it is usually fully bundle, so dependencies are best installed in devDependencies. This makes the final package more smaller.

@alex8088 alex8088 added question Further information is requested and removed bug Something isn't working labels Dec 10, 2022
@michael-dm
Copy link
Author

So that I understand, but what about dependencies of dependencies ? When bundling my app I found that they were not packaged by electron-builder.

Current workaround is adding them manually to the root package.json but this is inconvenient.

@alex8088
Copy link
Owner

electron-builder will also automatically resolve dependencies of dependencies. It may be a configuration problem of electron-builder. How the files attribute is configured?

@michael-dm
Copy link
Author

You were right this is because I use pnpm and there is currently a bug : electron-userland/electron-builder#6792 (comment)

Thank you.

@alex8088
Copy link
Owner

@michael-dm

If you want to use pnpm package manager, you can add .npmrc file with shamefully-hoist=true in root and reinstall deps.
Also, if you use pnpm create @quick-start/electron to scaffold your project, these will be added automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants