Skip to content

Rework SvelteKit SDK build time API  #7787

@Lms24

Description

@Lms24

Problem Statement

Currently, in SvelteKit, we instruct users to wrap withSentryViteConfig around their vite config object, similarly to withSentryConfig in the NextJS SDK. There are a couple of concerns with this approach:

  1. Depending on other wrappers people might use, our current types for the wrapper would cause TS errors. This is fixable by using broad enough generics but should we (see other points)?
  2. We received feedback that such a generic wrapper around the entire config is a little opaque in what it actually does and why we don’t simply use a plugin instead. Fair enough then!

Solution Brainstorm

Vite's plugin system exposes the configure hook which we can use to modify users' vite configs within a plugin.

So we'll build a "meta" SentrySvelteKitPlugin which adjusts the user's vite config:

  • Inject the init injection plugin if necessary
    • adjust the allowed serve directories
    • This will be dropped as a feature in favour of using hooks.
  • Inject the source maps plugin (=Sentry Vite Plugin w/ a couple of modifications)
  • In the future, possibly inject other plugins for auto instrumentation

We believe this provides a more transparent API than wrapping the entire config. At the same time, we don't lose the freedom to introduce further modification of the config.
The SvelteKit build plugin itself also uses the configure hook to merge user config w/ Kit-internal config.

Tasks

- [ ] https://github.com/getsentry/sentry-javascript/pull/7788
- [ ] #7789
- [ ] #7791
- [ ] #7792

ref: #6692 #7669

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions