Import Aliases in 4 minutes!

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

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

  • @lukecartwright613
    @lukecartwright613 10 месяцев назад +7

    Another super video!
    You can also add to your Vs code settings these lines:
    "typescript.updateImportsOnFileMove.enabled": "always"
    To get vs code to automatically update the file path. (Obviously replacing with JavaScript if your project isn't using ts)

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад +2

      Oh, cool! I know some of my extensions do that, but didn't know there was a VSCode setting. I'll add it! Thanks!

  • @TheAlphaGames
    @TheAlphaGames 10 месяцев назад +1

    The best way to also explain it is that import aliases changes your RELATIVE import declarations to ABSOLUTE imports so that way its always starting from the same point, which is why it works!

  • @CodinginPublic
    @CodinginPublic  10 месяцев назад

    And thanks to Dante for calling out my error in my previous video 🤦‍♂! I literally have like 20 projects right now on my computer using js imports and just had a brain fart last night when recording quickly since I've been using it in TS.

  • @zorua7017
    @zorua7017 10 месяцев назад +2

    You might want to look into using barrel files, that would simplify your import statements.
    Currently:
    import Heading from "@ui/Heading.astro":
    import Section from "@ui/Section.astro";
    Using barrel files:
    import { Heading, Section } from "@ui/index"

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад +1

      Yes! Great addition!

    • @pietro_dev_07
      @pietro_dev_07 10 месяцев назад

      you can put only:
      import { Header, Section } from "@ui"
      you can omit index!

  • @jjaimealeman
    @jjaimealeman 10 месяцев назад

    ooo, you gotta add this to your new Astro course 💥 🚀 😎 👍

  • @sonny5497
    @sonny5497 7 месяцев назад

    thanks this was exactly what i was looking for in astro as i was using path aliase in nextjs

  • @subhashgn1775
    @subhashgn1775 10 месяцев назад +1

    I have tried, this doesnt work with create-react-app. The reason may typescript has removed this support.
    Can you please confirm on this.

  • @chrishanthacosta4093
    @chrishanthacosta4093 7 месяцев назад

    Good work, I love your way of teaching!

  • @spacecoder0526
    @spacecoder0526 10 месяцев назад

    Could you make astro tutorial about how to render multiple array images in mdx and astro file with react component like passing images array to the component to render or something?

  • @leonardoroic8978
    @leonardoroic8978 10 месяцев назад

    Another useful video from Chris, no surprises here. :)

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

    Fantastic, thank you 🙏🏼

  • @szymon7932
    @szymon7932 10 месяцев назад

    nice! What is the theme u are using?

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад

      I think community material theme?

  • @rakib_bhai74
    @rakib_bhai74 Месяц назад

    Not working in express app with js

  • @aogunnaike
    @aogunnaike 10 месяцев назад

    Wow 😂 finally seeing your face for the first time this year 😂 you look beautiful 😍😅

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад +1

      lol um thanks? 💁‍♂️ 💅

  • @aryomuhammad8254
    @aryomuhammad8254 8 месяцев назад +1

    good one!

  • @kelsey_roy
    @kelsey_roy 10 месяцев назад

    What about unit tests?

    • @CodinginPublic
      @CodinginPublic  8 месяцев назад

      The aliases should still work? Are you having problems with them?

  • @kushalmondal618
    @kushalmondal618 10 месяцев назад

    Next js supports it out-of-box feature.....And Nust js don't need to import anything....how crazy is that🌰🌰🌰BTW your Vscode file icon themes seem cool in Astro Stack......🎉

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад +1

      Yep, Next asks you if it can just set it up out of the box. I would love for the Astro CLI to do this personally (or enable it with a flag?)

  • @siya.abc123
    @siya.abc123 10 месяцев назад

    Thanks man

  • @mohamedyamani8502
    @mohamedyamani8502 10 месяцев назад

    Aliases are cool, but they don't solve the issue you're talking about of moving a file, they're just another way to represent the same path, no?

    • @CodinginPublic
      @CodinginPublic  10 месяцев назад

      Because it’s always starting at the root path, it will be consistent. References to that file will need to be updated (which many IDEs will update automatically, but the big advantage is that when referencing other files, you don’t have to traverse and figure out what level everything us at. Components are always @components, for instance.