After creating a typescript module named moduleA
, I am ready to publish this package and make it accessible from another typescript project.
Currently, for testing purposes, I have installed 'moduleA' using 'npm install ../moduleA'. The file structure looks like this:
B
node_modules
moduleA
dist
index.ts
In the root directory of moduleA
, there is a folder named dist
containing the index.ts
file that I want to import using typescript as follows: import A from 'moduleA';
If the index.ts
was directly inside the moduleA folder, importing would work seamlessly. I could also specify it as the main
property in the package.json if it were a Javascript file.
However, in this scenario, my preference is to use typescript directly without moving the index.ts
out of the dist folder.
I do not wish to create another index.ts file like this:
import d from './dist/index';
export default d;
This is because my dist folder contains several subdirectories, which I intend to reference from projects dependent on moduleA
.
Is there an optimal way to specify the default typescript file of a package?