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.
Wow, Did not know about type:"module" , really useful !
Glad to hear that! Cheers Mark 😀
It's a good idea, making a custome node_module, i will try it
Go for it!
Now how would that work with types for typescript per module
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?
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.
"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