Package JSON Demystified - The 'Exports' Keyword

Поделиться
HTML-код
  • Опубликовано: 23 авг 2024
  • In this Javascript tutorial on NPM Package.JSON we look at the 'EXPORTS' keyword and how it helps us expose and also encapsulate the functionality contained within out NPM package.
    So by default Node uses the MAIN keyword to acomplish this, but there are limitations to this keyword and that is where the EXPORTS keyword can help us out. With EXPORTS we can expose subpaths, encapsulate and also conditionally exprt based on the environment we are running under even.
    We look at each of these possibilities with a simple Add function in a Calc app that is created locally and then imported into a consumer application MyApp.

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

  • @xerxius5446
    @xerxius5446 2 года назад +2

    Wow, Did not know about type:"module" , really useful !

    • @Ashotofcode
      @Ashotofcode  2 года назад

      Glad to hear that! Cheers Mark 😀

  • @dailymeow3283
    @dailymeow3283 3 года назад +2

    It's a good idea, making a custome node_module, i will try it

  • @SanderCokart
    @SanderCokart 11 месяцев назад +1

    Now how would that work with types for typescript per module

  • @russelldriver6394
    @russelldriver6394 3 года назад +4

    Very interesting. I didnt realise just by adding type module means you can use the import keyword in node. Does this mean require keyword will start fading away, or do they both have their best use cases?

    • @Ashotofcode
      @Ashotofcode  3 года назад +3

      Hi Russell, require will slowly die out I would think yes, import is the way to go in terms of consistency with the browser and a standards based approach for sure. Cheers Mark.

  • @Ajay-ss7ws
    @Ajay-ss7ws 4 месяца назад

    "exports": {
    "./package.json": "./package.json",
    ".": {
    "types": {
    "import": "./index.d.mts",
    "default": "./index.d.ts"
    }
    }
    },
    I want to import "./index.d.ts" and want to pass it to monaco editor for IntelliSense. How I can do that. This export is inside package.Json file of mustache package and I want to add intellisense for mustache inside monaco editor