Skip to content

Commit

Permalink
perf: only have Vite generate relative paths when required (#10287)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 6, 2023
1 parent 98506eb commit 9d8ad33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-dryers-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

perf: only have Vite generate relative paths when required
8 changes: 7 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,14 @@ function kit({ svelte_config }) {
// see the kit.output.preloadStrategy option for details on why we have multiple options here
const ext = kit.output.preloadStrategy === 'preload-mjs' ? 'mjs' : 'js';

// We could always use a relative asset base path here, but it's better for performance not to.
// E.g. Vite generates `new URL('/asset.png', import.meta).href` for a relative path vs just '/asset.png'.
// That's larger and takes longer to run and also causes an HTML diff between SSR and client
// causing us to do a more expensive hydration check.
const client_base = kit.paths.relative || kit.paths.assets ? './' : kit.paths.base || '/';

new_config = {
base: ssr ? assets_base(kit) : './',
base: ssr ? assets_base(kit) : client_base,
build: {
copyPublicDir: !ssr,
cssCodeSplit: true,
Expand Down

0 comments on commit 9d8ad33

Please sign in to comment.