Transforming ES modules to Commonjs for Electron and Node
See original GitHub issueIs your feature request related to a problem? Please describe.
Can Vite add support for transforming ES modules to CommonJS for Electron and Node?
For these two environments, ES modules are not supported (or do not have first-class support like the browsers). For that reason, the output code should use require
and exports
instead of using import
and export
.
For the dev mode, this transformation is necessary.
For the production model, if Rollup is able to bundle everything, it will be less of an issue, but there are still situations that the code uses dynamic require
s which Rollup has issues bundling.
Describe the solution you’d like Adding a transformer that converts import/exports back to commonjs in the last step.
Describe alternatives you’ve considered
Additional context
As the owner of atom-community I was planning to use Vite for the Atom packages in our organization. But the issue is that for Atom packages, we need to use commonjs
because Electron doesn’t support import/exports
.
There was a similar issue here (#2218), but the solution mentioned there isn’t general because we need to list all the modules that use require
manually.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hey @aminya for dynamic require(), try this:
patch-vite.ts
Vite
is determined to screw your codes withrequire
. After all the major focus ofVite
is to “promote” esm. Not possible to compact with the thing that you are trying to replace, let it BURN