-
-
Save shynome/601c74deeab113b2063eea58ef5d73d8 to your computer and use it in GitHub Desktop.
Run Svelte preprocessors in the sequence they are declared
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example usage | |
import { sequence } from './sequence.mjs' | |
import cssModules from "svelte-preprocess-cssmodules"; | |
export default { | |
preprocess: sequence([sveltePreprocess(), cssModules()]), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
}, | |
})) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import App from "./_app.svelte"; | |
</script> | |
<App class="xxx" /> | |
<style module> | |
.xxx { | |
color: red; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
let klass: string = ""; | |
export { klass as class }; | |
</script> | |
<div class={klass}>hello</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.