Build to commonjs #5523
|
Hey there, I was on an adventure to make myself a svelte-kit electron app, and while browsing premade templates, I noticed that all of them are using the static adapter. That makes no sense to me, electron ships a node + chromium runtime, so why not just simply use the node adapter? Well turns out It's impossible to import the esm modules produced by the svelte-kit(now vite) build command into electron (since electron uses only commonjs). I tried some stupid stuff with Any advice? |
Replies: 1 comment 1 reply
|
Solved this thanks to GHOST. The solution is to esbuild the const esbuild = require('esbuild');
const join = require('path').join;
esbuild.build({
entryPoints: [join(__dirname, '../build/svelte/handler.js')],
outfile: join(__dirname, '../build/svelte/handler.cjs'),
platform: 'node',
format: 'cjs',
bundle: true,
define: {
'import.meta.url': 'importMetaUrl'
},
inject: [join(__dirname, './shims.js')]
});And here is the injected export const importMetaUrl = /* @__PURE__ */ new URL(
'file:' + __filename
).href; |
Solved this thanks to GHOST.
The solution is to esbuild the
handler.jsoutput file ofvite buildwhen usingadapter node.Here is the script
And here is the injected
shim.jsfile