Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a better way to handle global CSS #4852

Closed
felixsanz opened this issue May 8, 2022 · 1 comment
Closed

Have a better way to handle global CSS #4852

felixsanz opened this issue May 8, 2022 · 1 comment

Comments

@felixsanz
Copy link

felixsanz commented May 8, 2022

Describe the problem

People usually (if not always) import global CSS inside __layout.svelte, but that doesn't make sense because global CSS is usually page/app related things, like CSS resets, custom properties / variables, etc. I think of it like this:

<html>
  <body>
    <Layout>
      <main>

Why are we setting CSS for <html> and <body> inside <Layout>?

Also, if you have __error.svelte, you need to import the global CSS file there too! And now with the new Named Layouts feature is also worse because if you have 10 different layouts that share the same CSS resets... you have to import it 10 times. Even if the output CSS is not duplicated and file is only imported once... it doesn't make sense as Layouts shouldn't be responsible for this!

A layout is a visual representation of a page, it shouldn't be responsible for setting variables or resetting css among other things.

Describe the proposed solution

I think we need an entrypoint for global CSS that is outside of layouts, for example an option inside svelte.config.js like:

const config = {
  kit: {
    'globalCss or cssEntrypoint': 'src/lib/styles/index.css',
  }
}

Alternatives considered

I tried using prependData inside postcss with svelte-preprocess but that's worse because the variables get added over and over again.

Having <style> or <link> inside app.html doesn't let you process those files with postcss or any other preprocessor, so not really a solution.

Importance

would make my life easier

Additional Information

No response

@mrkishi
Copy link
Member

mrkishi commented May 8, 2022

Thanks, but the discussion on global styles (and scripts, for that matter) is happening on #3127.

For what it's worth, with named layouts you can have a root layout that all other layouts inherit from, so you'd only need to add it once (well, twice, pending #4582 for __error@layout).

@mrkishi mrkishi closed this as completed May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants