Skip to content

Instantly share code, notes, and snippets.

@bluwy
Last active March 29, 2022 03:42
Show Gist options
  • Save bluwy/5fc6f97768b7f065df4e2dbb1366db4c to your computer and use it in GitHub Desktop.
Save bluwy/5fc6f97768b7f065df4e2dbb1366db4c to your computer and use it in GitHub Desktop.
Run Svelte preprocessors in the sequence they are declared
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 })
},
}))
}
import { preprocess } from 'svelte/compiler'
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess'
export function sequence(preprocessors: PreprocessorGroup[]): PreprocessorGroup[] {
return preprocessors.map((preprocessor) => ({
markup({ content, filename }) {
return preprocess(content, preprocessor, { filename })
},
}))
}
// Example usage
import { sequence } from './sequence'
export default {
preprocess: sequence([sveltePreprocess(), otherPreprocessor()]),
}
@bluwy
Copy link
Author

bluwy commented Feb 11, 2022

Thanks! I've updated the JS version with your jsdocs. Keeping the TS one in case that becomes useful.

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