Skip to content

Commit 5e82693

Browse files
authored
[fix] correctly use paths.base to import assets (#6769)
1 parent 55493cb commit 5e82693

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

.changeset/modern-books-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] error when using `paths.base` and `import` assets

packages/kit/src/exports/vite/build/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
147147
* @returns {string}
148148
*/
149149
export function assets_base(config) {
150-
return config.paths.assets + '/' || config.paths.base + '/' || './';
150+
return (config.paths.assets || config.paths.base || '.') + '/';
151151
}
152152

153153
const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import logo from './logo.svg';
3+
</script>
4+
5+
<img src={logo} alt="Svelte logo" />
Lines changed: 1 addition & 0 deletions
Loading

packages/kit/test/prerendering/paths-base/test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ test('prerenders /path-base/dynamic/foo', () => {
1818
assert.ok(content.includes('<h1>foo</h1>'));
1919
});
2020

21+
test('prerenders /path-base/assets', () => {
22+
const content = read('assets.html');
23+
assert.match(content, /<img[^>]+src="\/path-base\//u);
24+
});
25+
2126
test.run();

0 commit comments

Comments
 (0)