Skip to content

Ability to have code included across multiple layouts #1530

Closed
@ghost

Description

Is your feature request related to a problem? Please describe.
Sometimes, a library or a small code snippet has to be injected globally so its available everywhere in the app. For example, here's how PurgeIcons recommends to inject its generated code into a Vue app:

import { createApp } from 'vue'
import App from './App.vue'

import '@purge-icons/generated' // <-- This

createApp(App).mount('#app')

In Sapper, I could do something similar in the src/client.js file:

import * as sapper from '@sapper/app';

import '@purge-icons/generated'

sapper.start({
  target: document.querySelector('#app'),
 });

AFAIK, there's no straight-forward way of doing this in SvelteKit currently.

Describe the solution you'd like
Perhaps adding a file somewhere in src/ which would allow to inject global code could solve this problem.

Describe alternatives you've considered
I believe it would also be possible to import the code in the __layout.svelte file, but this isn't truly global, as the layout file can be overridden. Additionally, this approach feels convoluted because really, the layout file should be used for layout, not for importing global code.

How important is this feature to you?
It's pretty important to me because I'd like to start using SvelteKit with my favorite libraries and existing code snippets I have, but I can't find a way to reliably write globally-scoped code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions