Closed PossiblyAnEngineer closed 2 years ago
Hmm.... there was before, but it was switched to ESM. Guess it's really not ready for prime time yet. I'll change it back in the next version.
@richardtallent thanks for the plugin it helped me solve a headache.
@PossiblyAnEngineer I had the same problem using react so I converted Richard's solution to js instead of ts, then I imported it and added as a normal plugin.
Here is the import import { viteSingleFile } from "./single_file"
And here is the code for adding the plugin
plugins: [
react(),
viteSingleFile(),
createHtmlPlugin({
minify: true,
}),
],
Ahh, I see how it works. Since my Vite config file is also in typescript, I just copy-pasted Richard's code directly into my config, and it works fine now! So I can use that as a workaround. Thank you!
And yes, thank you for the plugin! It is very appreciated!
On a side note, you may want to run eslint on your code. On lines 33 and 38 you have regular expressions that contain [\./]
, and either the \
isn't escaped properly or you don't intend to escape .
. I'm guessing it's supposed be [\\./]
.
Encountered the same issue, can't add "type": "module"
to my project since it'll break other things.
Maybe having cjs
as default and adding mjs
as additional export via the exports
field in package.json
could be an option? https://nodejs.org/api/packages.html#conditional-exports
Please try 0.10.0-beta and let me know if it helps. It should allow use in both CommonJS and ESM environments.
Please try 0.10.0-beta and let me know if it helps. It should allow use in both CommonJS and ESM environments.
It works great for my use case at least! Thank you for the update!
In my project I currently use both Electron and Vite for different parts of my software, but they share a common
package.json
, and are ultimately built into a single executable. I tried using this plugin for the Vite side and got theERR_REQUIRE_ESM
error from #23. So, following the comments from that issue, I added"type": "module"
to mypackage.json
. Now I get this error from my electron build:Renaming that output file to
.cjs
worked, but it just leads to a bunch of other issues, which I'm currently trying to resolve. Is there a way to use this plugin without setting"type": "module"
inpackage.json
?