P
P
parse-g2022-02-19 20:23:34
typescript
parse-g, 2022-02-19 20:23:34

How to create an npm package with typescript?

I already tried to create npm on typescript package but I still don't understand:
- Where to put typescript and javascript files?
Why do you need to create a folder dist?
- Which file to specify in package.json, .tsor .js?
- Do I need to create .d.tsfiles?
- Add "type": "module"to package.json?
- Use exportor module.exports?
- Is it necessary to create @types/проект, and if so, what should be done there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2022-02-19
@Leathi

- Where to put typescript and javascript files?
Where is it convenient for you
- Why do you need to create a dist folder?
Usually you write your sources in TS. Therefore, you compile it to JS and publish the JS. Usually the compiled js is in the dist folder.
- Which file to specify in package.json, .ts or .js?
js.
- Do I need to create .d.ts files?
Yes
- Should I add "type": "module" to package.json?
- Use export or module.exports?
Depends on what format you compile your JS into
- Do I need to create an @types/project, and if so what should I do there?
No. This is only needed if your d.ts files are not included in the package itself.
And the internet is full of guides.
https://itnext.io/step-by-step-building-and-publis...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question