Skip to content

Commit

Permalink
fix: make server assets accessible during vite preview (#10511)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltigerchino authored Aug 9, 2023
1 parent f396f77 commit 0595e92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-walls-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: make server assets available during `vite preview`
9 changes: 2 additions & 7 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, statSync, createReadStream, createWriteStream } from 'node:fs';
import { extname, join, resolve } from 'node:path';
import { extname, resolve } from 'node:path';
import { pipeline } from 'node:stream';
import { promisify } from 'node:util';
import zlib from 'node:zlib';
Expand Down Expand Up @@ -181,12 +181,7 @@ export function create_builder({
},

writeClient(dest) {
const server_assets = copy(
`${config.kit.outDir}/output/server/${config.kit.appDir}/immutable/assets`,
join(dest, config.kit.appDir, 'immutable/assets')
).map((filename) => join(config.kit.appDir, 'immutable/assets', filename));
const client_assets = copy(`${config.kit.outDir}/output/client`, dest);
return Array.from(new Set([...server_assets, ...client_assets]));
return copy(`${config.kit.outDir}/output/client`, dest);
},

writePrerendered(dest) {
Expand Down
7 changes: 6 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
import colors from 'kleur';
import * as vite from 'vite';

import { mkdirp, posixify, read, resolve_entry, rimraf } from '../../utils/filesystem.js';
import { copy, mkdirp, posixify, read, resolve_entry, rimraf } from '../../utils/filesystem.js';
import { create_static_module, create_dynamic_module } from '../../core/env.js';
import * as sync from '../../core/sync/sync.js';
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
Expand Down Expand Up @@ -720,6 +720,11 @@ function kit({ svelte_config }) {
})
);

copy(
`${out}/server/${kit.appDir}/immutable/assets`,
`${out}/client/${kit.appDir}/immutable/assets`
);

/** @type {import('vite').Manifest} */
const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`));

Expand Down

0 comments on commit 0595e92

Please sign in to comment.