Last active
March 29, 2022 03:42
-
-
Save bluwy/5fc6f97768b7f065df4e2dbb1366db4c 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
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
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 }) | |
}, | |
})) | |
} |
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' | |
export default { | |
preprocess: sequence([sveltePreprocess(), otherPreprocessor()]), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I've updated the JS version with your jsdocs. Keeping the TS one in case that becomes useful.