Skip to content

Commit

Permalink
fix: SvelteKit dev build is not working (#206)
Browse files Browse the repository at this point in the history
* fix: Do not inject code into html files while ssr builds

* fix: Correct htmlFilePath detection

* fix: Dev mode is not working in SvelteKit

---------

Co-authored-by: Robin Bomkamp <[email protected]>
  • Loading branch information
RobinBomkamp and Robin Bomkamp authored Dec 2, 2024
1 parent 9cfdc5a commit 4e6898f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/plugins/pluginAddEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ const addEntry = ({
)}></script>`
);
},
transform(code, id) {
if (id.includes('node_modules') || inject !== 'html' || htmlFilePath) {
return;
}

if (id.includes('.svelte-kit') && id.includes('internal.js')) {
const src = devEntryPath.replace(/.+?\:([/\\])[/\\]?/, '$1').replace(/\\\\?/g, '/');
return code.replace(
/<head>/g,
'<head><script type=\\"module\\" src=\\"' + src + '\\"></script>'
);
}
},
},
{
name: 'add-entry',
Expand Down

0 comments on commit 4e6898f

Please sign in to comment.