Skip to content

Parametric compile options #12415

Open
Open
@Rich-Harris

Description

@Rich-Harris

Describe the problem

It's often useful to have different compiler options for different files. For example, you might want to enforce that all your first-party components are in runes mode, while continuing to use non-runes components in node_modules, or you might want to programmatically define custom element names rather than manually specifying them with <svelte:options> in each component.

Today, this is possible using dynamicCompileOptions in vite-plugin-svelte, but it has drawbacks:

  • you have to be using vite-plugin-svelte
  • it's an extra thing you have to learn; it feels a bit weird
  • things like VSCode and svelte-check can't take advantage of it

Describe the proposed solution

For the options where it makes sense, allow functions to be specified instead of values:

// svelte.config.js
export default {
  compilerOptions: {
    css: ({ filename }) => filename.includes('/og-cards/') ? 'injected' : 'external',
    runes: ({ filename }) => filename.includes('/node_modules/') ? undefined : true
  }
};

Importance

nice to have

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions