Skip to content

Commit

Permalink
[fix] allow Vite plugins to output mutable assets (#5416)
Browse files Browse the repository at this point in the history
* [fix] allow Vite plugins to output mutable assets

* Update packages/kit/src/vite/index.js

Co-authored-by: Rich Harris <[email protected]>

* Update packages/kit/src/vite/index.js

Co-authored-by: Rich Harris <[email protected]>

* remove immutable from prefix

* remove debug line

* fix (i think)

* update service worker

* ok i think we got it now

* typo

* try reverting a portion of recent changes

* Revert "try reverting a portion of recent changes"

This reverts commit 7136010.

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
3 people authored Jul 8, 2022
1 parent a7abf22 commit a9cbb4c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
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',
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 @@ -223,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 Expand Up @@ -276,8 +278,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

0 comments on commit a9cbb4c

Please sign in to comment.