I want to let users import from the subfolders of my TypeScript NPM package. For example, if the directory structure of the TypeScript code is as follows,
- lib
- src
- server
- react
users of my package should be able to import from subfolders as package-name/react
, package-name/server
etc.
My tsconfig.json is as follows.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true,
"jsx": "react",
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}
I could do this when "outDir" was set to the project root, but then the file structure is messy. Can someone point me a way out to do this (importing from submodules) while preserving "outDir": "./lib"
? Helpful answers are highly appreciated. Thanks in advance.
import {component} from 'package-name/server'
, I get error'package-name/server' is not found
, but when I import asimport {component} from 'package-name/lib/server
, I do not get such an error and everything work well. However, I want to get rid of that/lib
part and users to directly import fromserver
subfolder. – Sniggle