In my project I want to implement a custom npm package containing my typescript code (classes and interfaces). The interfaces inside the package should be used by different projects outside the package itself.
Right now my package contains following folders and files:
src/modules/TestClass.ts
class TestClass { ... }
_
src/modules/index.ts
import TestClass from "./TestClass";
export { TestClass };
_
src/types/index.d.ts
interface IMyInterface {
awesome: string;
}
In my package.json inside my script part I defined following script:
"scripts": { ... "build": "tsc", ... }
In my tsconfig.json I defined following compiler options:
{
"compilerOptions": {
"target": "es5",
"strict": true,
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "./dist",
"sourceMap": true,
"declaration": true,
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}
When I run my yarn build command I would expect to have the compiled .ts files in my dist and the interfaces in a *.d.ts file. However I only get the compiled files inside my modules folder.
Is there anything Im doing wrong and/or is there a better approach?