From 6ecfde3ce686f6fd4c9346621bfe32d524d09c48 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 9 Aug 2023 18:01:47 +0800 Subject: [PATCH 1/2] copy server assets to client before adapt --- packages/kit/src/core/adapt/builder.js | 9 ++------- packages/kit/src/exports/vite/index.js | 7 ++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/kit/src/core/adapt/builder.js b/packages/kit/src/core/adapt/builder.js index 605382e9e587..eae0bd8b7ecf 100644 --- a/packages/kit/src/core/adapt/builder.js +++ b/packages/kit/src/core/adapt/builder.js @@ -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'; @@ -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) { diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 01625bdfe5bf..94f242a1e468 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -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'; @@ -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}`)); From 74a2183d229cf12021a6efd7c387f970df2e3663 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 9 Aug 2023 18:07:17 +0800 Subject: [PATCH 2/2] changeset --- .changeset/selfish-walls-rhyme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/selfish-walls-rhyme.md diff --git a/.changeset/selfish-walls-rhyme.md b/.changeset/selfish-walls-rhyme.md new file mode 100644 index 000000000000..42b487985093 --- /dev/null +++ b/.changeset/selfish-walls-rhyme.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: make server assets available during `vite preview`