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

Feat build rollup external #1

Merged
merged 3 commits into from
Apr 11, 2022
Merged

Feat build rollup external #1

merged 3 commits into from
Apr 11, 2022

Conversation

magicdawn
Copy link
Contributor

we can use build.rollupOptions.external to externalize built in modules & electron.

the node_modules/.vite-plugin-electron-renderer/fs.js glue code work when dev (esbuild).
but can cause problem when build (rollup)

like fs-extra > graceful-fs package, without rollup external
will cause error
image

because

  • raw `require('fs')
  • map to node_modules/.vite-plugin-electron-renderer/fs.js esmodule
  • rollup/plugin-commonjs default use var require$$0$7 = /* @__PURE__ */ getAugmentedNamespace(fs$o);
  • the getAugmentedNamespace define a getter close on fs
  • so when graceful-fs try to overwrite fs.close, cause the error present by the image

the error can be prevented by set { requireReturnsDefault: 'prefer' / 'auto' } options of @rollup/plugin-commonjs to get rid of Object.defineProperty
but it's better to external these modules.

AND background:
magicdawn/magicdawn#132 (comment)

@caoxiemeihao
Copy link
Member

This is really a problem. Thank you for your PR 😄

@caoxiemeihao caoxiemeihao merged commit 35d1be7 into electron-vite:main Apr 11, 2022
caoxiemeihao pushed a commit that referenced this pull request Oct 31, 2023
@caoxiemeihao caoxiemeihao mentioned this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants