Skip to content

Commit

Permalink
prevent Vite from copying static assets if directory is called public (
Browse files Browse the repository at this point in the history
…#4214)

* prevent Vite from copying static assets if directory is called public - fixes #587

* add test
  • Loading branch information
Rich-Harris authored Mar 4, 2022
1 parent 4c5322a commit 2bd1ae2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brave-toys-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Prevent Vite from copying static assets if directory is called "public"
5 changes: 4 additions & 1 deletion packages/kit/src/core/build/build_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export async function build_client({
hydratable: !!config.kit.browser.hydrate
}
})
]
],
// prevent Vite copying the contents of `config.kit.files.assets`,
// if it happens to be 'public' instead of 'static'
publicDir: false
});

print_config_conflicts(conflicts, 'kit.vite.', 'build_client');
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/test/prerendering/options/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
4 changes: 4 additions & 0 deletions packages/kit/test/prerendering/options/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const config = {
}
},

files: {
assets: 'public'
},

paths: {
base: '/path-base',
assets: 'https://cdn.example.com/stuff'
Expand Down
4 changes: 4 additions & 0 deletions packages/kit/test/prerendering/options/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ test('adds CSP headers via meta tag', () => {
);
});

test('does not copy `public` into `_app`', () => {
assert.ok(!fs.existsSync(`${build}/_app/robots.txt`));
});

test.run();

0 comments on commit 2bd1ae2

Please sign in to comment.