Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] allow Vite plugins to output mutable assets #5416

Merged
merged 11 commits into from
Jul 8, 2022
5 changes: 5 additions & 0 deletions .changeset/yellow-years-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] allow Vite plugins to output mutable assets
14 changes: 7 additions & 7 deletions packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ function kit() {
function create_client_config() {
/** @type {Record<string, string>} */
const input = {
start: `${get_runtime_path(svelte_config.kit)}/client/start.js`
'immutable/start': `${get_runtime_path(svelte_config.kit)}/client/start.js`
benmccann marked this conversation as resolved.
Show resolved Hide resolved
};

// This step is optional — Vite/Rollup will create the necessary chunks
// for everything regardless — but it means that entry chunks reflect
// their location in the source code, which is helpful for debugging
// Put unchanging assets in immutable directory. We don't set that in the outDir so that other
// plugins can add mutable assets to the bundle. Also have the entry chunks reflect their
// location in the source code, which is helpful for debugging
benmccann marked this conversation as resolved.
Show resolved Hide resolved
manifest_data.components.forEach((file) => {
const resolved = path.resolve(cwd, file);
const relative = path.relative(svelte_config.kit.files.routes, resolved);

const name = relative.startsWith('..')
? path.basename(file)
: posixify(path.join('pages', relative));
input[name] = resolved;
input[`immutable/${name}`] = resolved;
});

return get_default_config({
config: svelte_config,
input,
ssr: false,
outDir: `${paths.client_out_dir}/immutable`
outDir: `${paths.client_out_dir}`
});
}

Expand Down Expand Up @@ -225,7 +225,7 @@ function kit() {

/** @type {import('vite').Manifest} */
const vite_manifest = JSON.parse(
fs.readFileSync(`${paths.client_out_dir}/immutable/manifest.json`, 'utf-8')
fs.readFileSync(`${paths.client_out_dir}/manifest.json`, 'utf-8')
);

const entry_id = posixify(
Expand Down