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
2 changes: 1 addition & 1 deletion packages/kit/src/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Server {
manifest,
method_override: ${s(config.kit.methodOverride)},
paths: { base, assets },
prefix: assets + '/${config.kit.appDir}/immutable/',
prefix: assets + '/${config.kit.appDir}/',
prerender: {
default: ${config.kit.prerender.default},
enabled: ${config.kit.prerender.enabled}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/vite/build/build_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function build_service_worker(

export const build = [
${Array.from(build)
.map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/immutable/${file}`)}`)
.map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
.join(',\n\t\t\t\t')}
];

Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/vite/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
input,
output: {
format: 'esm',
entryFileNames: ssr ? '[name].js' : '[name]-[hash].js',
chunkFileNames: 'chunks/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash][extname]'
entryFileNames: ssr ? '[name].js' : 'immutable/[name]-[hash].js',
benmccann marked this conversation as resolved.
Show resolved Hide resolved
chunkFileNames: 'immutable/chunks/[name]-[hash].js',
assetFileNames: 'immutable/assets/[name]-[hash][extname]'
},
preserveEntrySignatures: 'strict'
},
Expand Down Expand Up @@ -134,7 +134,7 @@ export function assets_base(config) {
// during `svelte-kit preview`, because we use a local asset path. This
// may be fixed in Vite 3: https://github.com/vitejs/vite/issues/2009
const { base, assets } = config.paths;
return `${assets || base}/${config.appDir}/immutable/`;
return `${assets || base}/${config.appDir}/`;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function kit() {
function create_client_config() {
/** @type {Record<string, string>} */
const input = {
// 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
start: `${get_runtime_path(svelte_config.kit)}/client/start.js`
};

Expand All @@ -113,7 +115,7 @@ function kit() {
config: svelte_config,
input,
ssr: false,
outDir: `${paths.client_out_dir}/immutable`
outDir: `${paths.client_out_dir}`
});
}

Expand Down Expand Up @@ -225,7 +227,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 Expand Up @@ -278,8 +280,8 @@ function kit() {

const files = new Set([
...static_files,
...chunks.map((chunk) => `${svelte_config.kit.appDir}/immutable/${chunk.fileName}`),
...assets.map((chunk) => `${svelte_config.kit.appDir}/immutable/${chunk.fileName}`)
...chunks.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`),
...assets.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`)
]);

// TODO is this right?
Expand Down