Skip to content

Commit

Permalink
set Vite's option
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 21, 2022
1 parent 28419a3 commit 14c18e3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-jars-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/adapter-node': patch
'@sveltejs/kit': patch
---

set Vite's `publicDir` option
1 change: 0 additions & 1 deletion packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default function (opts = {}) {
if (precompress) {
builder.log.minor('Compressing assets');
await compress(`${out}/client`);
await compress(`${out}/static`);
await compress(`${out}/prerendered`);
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ export function create_builder({ config, build_data, prerendered, log }) {
},

writeClient(dest) {
return [
...copy(`${config.kit.outDir}/output/client`, dest),
...copy(config.kit.files.assets, dest)
];
return [...copy(`${config.kit.outDir}/output/client`, dest)];
},

writePrerendered(dest, { fallback } = {}) {
Expand Down
8 changes: 1 addition & 7 deletions packages/kit/src/core/adapt/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ test('copy files', () => {
builder.writeClient(dest);

assert.equal(
[
...glob('**', {
cwd: /** @type {import('types').ValidatedConfig} */ (mocked).kit.files.assets,
dot: true
}),
...glob('**', { cwd: `${outDir}/output/client`, dot: true })
],
glob('**', { cwd: `${outDir}/output/client`, dot: true }),
glob('**', { cwd: dest, dot: true })
);

Expand Down
4 changes: 1 addition & 3 deletions packages/kit/src/vite/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ export const get_default_config = function ({ config, input, ssr, outDir }) {
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
__SVELTEKIT_DEV__: 'false'
},
// prevent Vite copying the contents of `config.kit.files.assets`,
// if it happens to be 'public' instead of 'static'
publicDir: false,
publicDir: ssr ? false : config.kit.files.assets,
resolve: {
alias: get_aliases(config.kit)
},
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function kit() {
__SVELTEKIT_DEV__: 'true',
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
},
publicDir: svelte_config.kit.files.assets,
resolve: {
alias: get_aliases(svelte_config.kit)
},
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export async function preview(vite, config, protocol) {
// files in `static`
vite.middlewares.use(scoped(assets, mutable(config.kit.files.assets)));

// immutable generated client assets
// generated client assets
vite.middlewares.use(
scoped(
assets,
sirv(join(config.kit.outDir, 'output/client'), {
setHeaders: (res, pathname) => {
// only apply to build directory, not e.g. version.json
// only apply to immutable directory, not e.g. version.json
if (pathname.startsWith(`/${config.kit.appDir}/immutable`)) {
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
}
Expand Down

0 comments on commit 14c18e3

Please sign in to comment.