Preprocessors Are The Most Powerful Svelte Feature No One Talks About

Поділитися
Вставка
  • Опубліковано 22 лис 2024

КОМЕНТАРІ •

  • @lorissigrist
    @lorissigrist 7 місяців тому +20

    Svelte Preprocessors are awesome & more people should learn about them! Thanks for making this video.
    We used one for auto-localising links in the Paraglide SvelteKit Adapter. Incredible how well that just works.
    A few things I learned while building it:
    - If you're publishing a preprocessor make sure to make svelte a peerDependency so you're using the same version as the app you're processing
    - There are some unexpected differences in the Svelte 4 and 5 ASTs. Make sure to test in both versions
    - Use a package like `magic-string` for string-manipulation & return a source-map alongside the preprocessed code.
    - Parsing the code into an AST is expensive, especially if you start stacking preprocessors. Do some quick & dirty checks to see if you really need to. (string.includes etc.)
    - You can register a preprocessor from a vite-plugin by setting it on the `api.sveltePreprocess` property of the vite-plugin.
    The only other framework that comes close to the level of flexibility preprocessors offer is Astro with it's integrations API.

  • @rogerpence
    @rogerpence 7 місяців тому +5

    This is a solid gold video! You just answered about 25 questions I've had for a very long time. Thank you!

  • @shapelessed
    @shapelessed 7 місяців тому +12

    I love how this could extend svelte to use with things like different JS and CSS supersets, but I have a bad feeling how this could possibly make some parts of development a pain, just like macros in C++ make your life a living hell.

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +6

      With great power comes great responsibility.

    • @shapelessed
      @shapelessed 7 місяців тому +3

      ​@@JoyofCodeDev I would rather have a little less power but know what to expect.

  • @stolinski
    @stolinski 5 місяців тому +1

    I just wrote one today to import html as demos. Def underrated.

  • @Junietta.
    @Junietta. 7 місяців тому

    This just took rapid webapp testing to the next level! Thank you so much

  • @sistana
    @sistana 4 місяці тому

    Very kind!!! Thank you so much, dear friend. Why hasn't Svelte included this by default?

  • @newskybox
    @newskybox 7 місяців тому +1

    Astro has something similar out of the box if you're really into static site generation or using different frameworks together on one page, but this is hella awesome

  • @kelvindecosta5350
    @kelvindecosta5350 7 місяців тому +1

    While this is super cool, it requires a lot of manual configuration. The alternative is mdsvex or markdoc which, again, requires a lot of fine tuning to make work properly.
    One of SvelteKit's pain point is that there is no officially supported method to easily build a blog based on markdown/markdown extended files.
    On the other hand, Astro has official support for both Svelte and MDX with two commands.
    Much more convenient than setting up preprocessors to get this behaviour.
    For a blog, Astro is the way to go.

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +1

      There's a Markdoc preprocessor.

  • @camoman1000
    @camoman1000 5 місяців тому

    @JoyofCodeDev, great idea would be to make a preprocessor that can take dataloading/ functions and hoist them to server call and inline data into html template...

  • @SheeceGardazi
    @SheeceGardazi 7 місяців тому +6

    Just a random thing: preprocessors only work during the build-time step; they are not available during runtime!

    • @BryanKlein
      @BryanKlein 7 місяців тому

      They are used to process files in the routes directory. The video linked in my comment here shows another way to process AsciiDoc source files as routes in addition to using a pre-processor.

  • @pjc825
    @pjc825 7 місяців тому +3

    Can you please do a video about using Svelte Flow (The Node-Based UI for Svelte), it looks amazing and creating custom nodes with it etc... 🙏👍

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +2

      Looks interesting! 😄

    • @Wombosvideo
      @Wombosvideo 7 місяців тому

      Grid snapping would be interesting there too, which is what is keeping me from using it

    • @pjc825
      @pjc825 7 місяців тому

      @@Wombosvideo Helper Lines is available in the React Flow Pro version which is sort of like what you want 😃

  • @yobi3d
    @yobi3d 7 місяців тому +1

    It's a pity, but it seems there will be glitches due to emoji, the first thing I noticed is that vscode does not show props from the imported component. Looks like need some fixes for svelte extension, emoji in code it's fun, but errors in vscode :(

  • @iulikdev
    @iulikdev 7 місяців тому

    Awesome as always!

  • @servertdot
    @servertdot 7 місяців тому +1

    yooo, thats awesome 🔥

  • @efimgibsun7969
    @efimgibsun7969 7 місяців тому

    Wow! Thats great 👍

  • @daviidon
    @daviidon 7 місяців тому

    Nice, I'm going to try to make one for imba css.

  • @summerWTFE
    @summerWTFE 7 місяців тому +1

    Thank you for this. I didn't know about this feature. The only thing I found a little weird was that you now have a .svelte file called .md. which will probably mess up how the editor reads the file, no?

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +1

      Not if you write Markdown but you can also associate random file types with anything for example `.svx` could be treated as either a Markdown or Svelte file.

  • @nabeelparkar4364
    @nabeelparkar4364 7 місяців тому

    “Programming is just concatenating strings together” 🤯

  • @jjdevcode9635
    @jjdevcode9635 7 місяців тому

    Like Gulp with plugins or pipes, like Webpack with modules, like Vite with plugins?

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +1

      That's a name I haven't heard in years.

    • @jjdevcode9635
      @jjdevcode9635 7 місяців тому

      @@JoyofCodeDev Yes, I'm old

  • @MadeInJack
    @MadeInJack 7 місяців тому

    Awesome!

  • @sep1ol
    @sep1ol 7 місяців тому

    what is that web browser you're using? seems clean

    • @daleryanaldover6545
      @daleryanaldover6545 7 місяців тому +2

      he just mentioned people would probably ask so he explained where he got it, try watching again

    • @sep1ol
      @sep1ol 7 місяців тому

      @@daleryanaldover6545 i meant the one with the documentation opened, not the one from vscode!

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому

      I use Brave 🦁

  • @MohammadAbdalrazzak
    @MohammadAbdalrazzak 7 місяців тому

    Hey i really like your channel can you keep it up?
    greetings from syria

  • @babakfp
    @babakfp 7 місяців тому

    Good shit 👍

  • @さらたべる
    @さらたべる 7 місяців тому

    fantastic tuts

  • @Александр-ч4п5ъ
    @Александр-ч4п5ъ 7 місяців тому

    0:25 you are welcome

  • @keokawasaki7833
    @keokawasaki7833 7 місяців тому

    I can hear the coffee speaking

  • @cyayla
    @cyayla 7 місяців тому +1

    0:47 daily dose

  • @dirtycrew666
    @dirtycrew666 7 місяців тому

    what vscode theme is this?

    • @Mahfoudh94
      @Mahfoudh94 7 місяців тому

      truly amazing theme and icon pack, I started using after watching his videos.
      I forgot the names but they are on his site in description

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому

      You can find the link in the description.

    • @dirtycrew666
      @dirtycrew666 7 місяців тому

      @@JoyofCodeDev Thanks mate! I've gone ahead and installed it. What a beautiful theme!

  • @learnidotapp
    @learnidotapp 7 місяців тому

    hi friends!!!

  • @SRG-Learn-Code
    @SRG-Learn-Code 7 місяців тому

    🔥🔥❤‍🔥❤‍🔥🔥🔥❤‍🔥❤‍🔥🔥🔥❤‍🔥❤‍🔥

  • @denisjean-bastien1253
    @denisjean-bastien1253 7 місяців тому

    Someone can explain me why it's useful? I don't get it on what I can do with it =/

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +1

      A preprocessor is useful because it can transform your code to reduce boilerplate, or transform one thing to another before Svelte compiles it.
      You could make a slides preprocessor to turn Markdown sections into slides, or a Markdoc preprocessor to take care of any setup and transform `.markdoc` files into regular HTML.
      They are for more advanced use cases and most people aren't going to have a need for writing a preprocessor.

    • @SilvestreVivo
      @SilvestreVivo 7 місяців тому

      You could use your own custom markdown system in a website builder to spread data among the component tree in a very useful and efficient way. Let's say is a way to use variables wherever you are ( like root in css ). This video is gold.

  • @ducklingzpl46u36
    @ducklingzpl46u36 7 місяців тому

    First

  • @Nodsaibot
    @Nodsaibot 5 місяців тому

    I HATE how markdown handles images and links

  • @Jonas-Seiler
    @Jonas-Seiler 6 місяців тому

    pretty cool, but absolutely horrendous for production code in business settings, so no thanks

  • @Hernan-Kza
    @Hernan-Kza 7 місяців тому

    Muy falopa