Currently, I am in the process of creating an npm package to be used by other developers within my company. While most aspects are functioning smoothly, I am facing challenges with getting the declarations right.
I have experimented with various methods for generating the file, but when it comes down to producing declaration files with tsc, I encounter two options:
- Generating a single output file
- Creating multiple files that mimic the folder structure of my source code.
Unfortunately, both of these formats do not align well with my client application. When I generate a single file, the client app raises issues stating that the file is "not a module." On the other hand, if I generate multiple files, the absence of an "index.d.ts
" top-level file leads to complaints from the client app. How should I go about resolving this dilemma?
The npm commands I am using are:
"prebuild": "rm -rf ./dist",
"build": "rollup -c",
"postbuild": "tsc --project tsconfig.dts.json"
This is what my rollup configuration looks like:
(Rollup configuration content)
Here is a snippet from my tsconfig.json
:
(Snippet from tsconfig.json)
Finally, here's a portion of the output generated by tsc
(for the scenario involving a single index.d.ts
):
(Sample output from tsc)
If anyone has any advice or guidance on how to navigate through this, it would truly be a lifesaver!