Skip to content

Allow inclusion of global styles #1948

Closed
@ebeloded

Description

@ebeloded

Describe the problem

Currently the recommended way to include global styles is to add it to root __layout.svelte, as was suggested by Rich and supported with this PR (#726):

<!-- __layout.svelte -->
<script context="module">
import '../app.scss'
</script>

The issue is that these styles are not linked in rendered HTML (like start.css), but rather are included at runtime with JS.

This means that

  1. the styles are loaded with delay resulting in FOUC
  2. the app is completely unstyled when JS is disabled

Describe the proposed solution

  1. There could be a convention for including global styles from app.[scss|less|css] done by SvelteKit
- src
  - app.html
  - app.scss
  1. A more generalized solution would be to allow app.ts living alongside app.html, included by SvelteKit. This file may import global styles, but also some scripts, which wouldn't make sense to include in layouts.
- src
  - app.html
  - app.ts
// app.ts
import './lib/global.scss' // include global styles
import Sentry from '@sentry/browser' // run global scripts
Sentry.init()
  1. Make app.htmlsmarter (Parcel style), allowing it to include files in whatever format, which would then be compiled to js/css
<!-- app.html -->
<html>
<script src="./app.ts"></script>
<link rel="stylesheet" href="./app.scss">
</html>

Alternatives considered

An alternative is to compile CSS separately from SvelteKit and include hashed filename in app.html during build.

Importance

nice to have

Additional Information

Related issues:
#714

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions