Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hooks-server-assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: include `hooks.server` and `hooks.universal` as explicit Vite build inputs to ensure assets imported by hooks files are correctly discovered
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function find_server_assets(build_data, routes) {
*/
const used_nodes = new Set([0, 1]);

// TODO add hooks.server.js asset imports
/** @type {Set<string>} */
const server_assets = new Set();

Expand Down Expand Up @@ -49,5 +48,9 @@ export function find_server_assets(build_data, routes) {
add_assets(build_data.manifest_data.hooks.server);
}

if (build_data.manifest_data.hooks.universal) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this wasn't referenced here... but if it runs on the server, it's possible it could import foo from 'bar?url' right? In which case we would want to add the assets from it?

add_assets(build_data.manifest_data.hooks.universal);
}

return Array.from(server_assets);
}
8 changes: 8 additions & 0 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,14 @@ async function kit({ svelte_config }) {
input[name] = path.resolve(file);
});

// ...and the hooks files
if (manifest_data.hooks.server) {
input['entries/hooks.server'] = path.resolve(manifest_data.hooks.server);
}
if (manifest_data.hooks.universal) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same q as above. If we're not adding assets from here anyway, we don't need it as an entrypoint

input['entries/hooks.universal'] = path.resolve(manifest_data.hooks.universal);
}

// ...and the server instrumentation file
const server_instrumentation = resolve_entry(
path.join(kit.files.src, 'instrumentation.server')
Expand Down
Loading