Preprocessors Are The Most Powerful Svelte Feature No One Talks About

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 60

  • @lorissigrist
    @lorissigrist 6 месяцев назад +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 6 месяцев назад +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 6 месяцев назад +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  6 месяцев назад +6

      With great power comes great responsibility.

    • @shapelessed
      @shapelessed 6 месяцев назад +3

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

  • @SheeceGardazi
    @SheeceGardazi 6 месяцев назад +6

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

    • @BryanKlein
      @BryanKlein 6 месяцев назад

      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.

  • @stolinski
    @stolinski 4 месяца назад +1

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

  • @sistana
    @sistana 3 месяца назад

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

  • @newskybox
    @newskybox 6 месяцев назад +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

  • @Junietta.
    @Junietta. 6 месяцев назад

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

  • @pjc825
    @pjc825 6 месяцев назад +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  6 месяцев назад +2

      Looks interesting! 😄

    • @Wombosvideo
      @Wombosvideo 6 месяцев назад

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

    • @pjc825
      @pjc825 6 месяцев назад

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

  • @camoman1000
    @camoman1000 4 месяца назад

    @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...

  • @yobi3d
    @yobi3d 6 месяцев назад +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 :(

  • @kelvindecosta5350
    @kelvindecosta5350 6 месяцев назад +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  6 месяцев назад +1

      There's a Markdoc preprocessor.

  • @summerWTFE
    @summerWTFE 6 месяцев назад +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  6 месяцев назад +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.

  • @daviidon
    @daviidon 6 месяцев назад

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

  • @iulikdev
    @iulikdev 6 месяцев назад

    Awesome as always!

  • @sep1ol
    @sep1ol 6 месяцев назад

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

    • @daleryanaldover6545
      @daleryanaldover6545 6 месяцев назад +2

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

    • @sep1ol
      @sep1ol 6 месяцев назад

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

    • @JoyofCodeDev
      @JoyofCodeDev  6 месяцев назад

      I use Brave 🦁

  • @servertdot
    @servertdot 6 месяцев назад +1

    yooo, thats awesome 🔥

  • @efimgibsun7969
    @efimgibsun7969 6 месяцев назад

    Wow! Thats great 👍

  • @jjdevcode9635
    @jjdevcode9635 6 месяцев назад

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

    • @JoyofCodeDev
      @JoyofCodeDev  6 месяцев назад +1

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

    • @jjdevcode9635
      @jjdevcode9635 6 месяцев назад

      @@JoyofCodeDev Yes, I'm old

  • @nabeelparkar4364
    @nabeelparkar4364 6 месяцев назад

    “Programming is just concatenating strings together” 🤯

  • @MohammadAbdalrazzak
    @MohammadAbdalrazzak 6 месяцев назад

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

  • @MadeInJack
    @MadeInJack 6 месяцев назад

    Awesome!

  • @さらたべる
    @さらたべる 6 месяцев назад

    fantastic tuts

  • @babakfp
    @babakfp 6 месяцев назад

    Good shit 👍

  • @denisjean-bastien1253
    @denisjean-bastien1253 6 месяцев назад

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

    • @JoyofCodeDev
      @JoyofCodeDev  6 месяцев назад +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 6 месяцев назад

      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.

  • @dirtycrew666
    @dirtycrew666 6 месяцев назад

    what vscode theme is this?

    • @Mahfoudh94
      @Mahfoudh94 6 месяцев назад

      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  6 месяцев назад

      You can find the link in the description.

    • @dirtycrew666
      @dirtycrew666 6 месяцев назад

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

  • @keokawasaki7833
    @keokawasaki7833 6 месяцев назад

    I can hear the coffee speaking

  • @cyayla
    @cyayla 6 месяцев назад +1

    0:47 daily dose

  • @Александр-ч4п5ъ
    @Александр-ч4п5ъ 6 месяцев назад

    0:25 you are welcome

  • @Nodsaibot
    @Nodsaibot 4 месяца назад

    I HATE how markdown handles images and links

  • @Jonas-Seiler
    @Jonas-Seiler 5 месяцев назад

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

  • @learnidotapp
    @learnidotapp 6 месяцев назад

    hi friends!!!

  • @SRG-Learn-Code
    @SRG-Learn-Code 6 месяцев назад

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

  • @Hernan-Kza
    @Hernan-Kza 6 месяцев назад

    Muy falopa

  • @ducklingzpl46u36
    @ducklingzpl46u36 6 месяцев назад

    First