Skip to content

Support multiple compiler & preprocess options #773

Closed
@milkbump

Description

@milkbump

This is a reiteration of sveltejs/language-tools#410 but in the context of svelte-kit.

Is your feature request related to a problem? Please describe.
Currently, the svelte.config.js assumes one config for your entire directory. However, it's not uncommon to want to compile some components to web component and others to vanilla Svelte. Some components may need one CSS, Markdown, Language (TS)...etc. preprocess and others another one, especially when using an external Svelte library.

Describe the solution you'd like
When using Rollup, I solve this using the exclude/include options and multiple instances of the Svelte plugin. (Not very elegant)

// rollup.config.js
import svelte from "rollup-plugin-svelte";


const WEB_COMPONENT_POSTFIX = `**/*.wc.svelte`
// Omitted for brevity
// const TS_COMPONENT_POSTFIX = "**/*.ts.svelte";
// const DOC_COMPONENT_POSTFIX = "**/*.doc.svelte"; // preprocessed for MdSvex etc.

export default {
    ...
    svelte({
        preprocess: regularSveltePreprocess,
        exclude: WEB_COMPONENT_POSTFIX,
    }),
    svelte({
        customElement: true,
        preprocess: webComponentPreprocess,
        include: WEB_COMPONENT_POSTFIX,
    }),
    ...
}

My current suggestion is to accept an array of compilerOptions and preprocessOptions.

// svelte.config.cjs

// set up `webComponentsPreprocess` && `vanillaPreprocess`
module.exports = {
	  preprocess: [
		    {
		       preprocess: webComponentsPreprocess,
		       include: "**/*.wc.svelte",
		    },
		    {
		       preprocess: vanillaPreprocess,
		       include: "**/*.svelte",
		       exclude: ["**/*.wc.svelte", "**/*.ts.svelte"],
		    }
	  ],
	  compilerOptions: [
		{...},
		{...}
	 ]
},

Describe alternatives you've considered
I haven't found an alternative in the context of the svelte-kit. Suggestion for workarounds are welcome.

How important is this feature to you?
This is critical to different projects I work on, (particularly those using some web components and an external Svelte component library). It's a blocker to migrating from Rollup.

Additional context
The solution implementation for this issue would be far-reaching. It may need some consensus from several Svelte tools using svelte.config.cjs.

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