Skip to content

Instantly share code, notes, and snippets.

@shynome
Forked from bluwy/sequence.js
Last active July 7, 2022 17:34
Show Gist options
  • Save shynome/601c74deeab113b2063eea58ef5d73d8 to your computer and use it in GitHub Desktop.
Save shynome/601c74deeab113b2063eea58ef5d73d8 to your computer and use it in GitHub Desktop.
Run Svelte preprocessors in the sequence they are declared
// Example usage
import { sequence } from './sequence.mjs'
import cssModules from "svelte-preprocess-cssmodules";
export default {
preprocess: sequence([sveltePreprocess(), cssModules()]),
}
import { preprocess } from 'svelte/compiler'
/**
*
* @typedef {import("svelte/types/compiler/preprocess").PreprocessorGroup} PreprocessorGroup
* @param {PreprocessorGroup[]} preprocessors
* @returns {PreprocessorGroup[]}
*/
export function sequence(preprocessors) {
return preprocessors.map((preprocessor) => ({
markup({ content, filename }) {
return preprocess(content, preprocessor, { filename })
},
}))
}
<script>
import App from "./_app.svelte";
</script>
<App class="xxx" />
<style module>
.xxx {
color: red;
}
</style>
<script lang="ts">
let klass: string = "";
export { klass as class };
</script>
<div class={klass}>hello</div>
@JackLeEmmerdeur
Copy link

I don't understand at all what you're doing in the first two scripts, but I want to wholeheartly thank you for this hack/workaround/solution.
It works exceptionally well and it let's us pass class attributes to components in a clean way.
Thank you very much for this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment