Reputation: 764
I have a new Svelte app using Sveltekit, skeleton project. I create a component with a single div and attempt to set a background image. I am using adapter-static to generate a static site on build. If inline the css on the div, it works fine. If I create a class in the <style>
block of the component then the styles do not load.
<div class="foo-test"
style="width: 500px; height: 500px; background-image: url('circle.png');">
</div>
npm run build
. files created:<style>
block:<div class="foo-test"></div>
<style>
.foo-test {
width: 500px;
height: 500px;
border: 2px solid black;
background-image: url("circle.png");
}
</style>
My svelte.config.js
:
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
prerender: {
default: true
}
}
};
export default config;
Am I missing a step to the process? New to Svelte. TIA
Edits:
app.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="" />
<link rel="icon" href="%svelte.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%svelte.head%
</head>
<body>
<div>%svelte.body%</div>
</body>
</html>
Edit2: I should note, it works correctly then running in dev npm run dev
and launch browser to http://localhost:3000/
. only the index.html file generated from the adapter-static is not working properly when I open the file in the browser file:///C:/Repos/foo/foo/build/index.html
Upvotes: 4
Views: 2018
Reputation: 2569
It is possible that you are deploying to Github Pages and you have not included a .nojekyll
file. I saw this behaviour and resolved it by adding .nojekyll
in the /static
directory.
It appears that Jekyll does not recognise the directories with a leading underscore.
If using gh-pages
to deploy, you also need to use the --dotfiles
options to ensure that the file is pushed.
Note: I still don't see that loading the built files directly works locally, but I am not sure that that would be expected behaviour.
Upvotes: 0