Simplify auto preprocessing #424
                  
                    
                      kaisermann
                    
                  
                
                  started this conversation in
                Ideas
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the
automode is a single preprocessor that calls the necessary transformers given a certain svelte file. I've been wanting to refactor it for quite some time; the code feels convoluted, there are some hacky workarounds for handling options overrides, for enqueueing more than one transformer and for much more. Scenarios wherebabelorpostcssare needed alongside some other language, like TS or SCSS, are basically hard-coded. My initial thoughts were to implement some kind of "queue" mechanism, so we could streamline the code a bit.However, that brings me to my current way of thinking that is: we already have a queue mechanism, the one the
svelte.preprocessAPI provides. The core ofsvelte-preprocesswas born in 2018 when Svelte didn't have support for a queue of preprocessors yet (I may be wrong here 😅). Since we already have each transformer as a standalone preprocessor (src/processors), we could enqueue all of them in the appropriate order (babelandpostcssat the end i.e). This would left theautomode only responsible for setting default options, turning on/off settings etc.If I'm not forgetting something and we move forward with this idea, this can be implemented in three ways:
sveltePreprocess()returns the array of preprocessors with the appropriate options set. This is a breaking change for people who usesvelte-preprocessinside an array of preprocessors already.// svelte.config.js export default { - preprocess: [someOtherPreprocessor(), sveltePreprocess()] + preprocess: [someOtherPreprocessor(), ...sveltePreprocess()] }However, for the common use-case this shouldn't require any refactor:
// svelte.config.js export default { preprocess: sveltePreprocess() // returns an array of preprocessors now, instead of a single one }sveltePreprocess()will executesvelte.preprocessinside of itself. This isn't a breaking-change and not completely novel, but it's strange nevertheless.Wait for the Preprocess API RFC to go through and see what we can do after that.
Beta Was this translation helpful? Give feedback.
All reactions