As a newbie in creating npm packages using TypeScript, I've encountered some issues that I believe stem from misinterpreting the documentation. Currently, I am working with Node 16.16.0 and npm 8.13.2.
Here is the structure of my project:
src/
├─ module1/
│ ├─ index.ts
├─ module2/
│ ├─ index.ts
package.json
tsconfig.json
tsconfig.json
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"esModuleInterop": true,
"declaration": true,
"outDir": "./lib",
"strict": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}
package.json
{
"name": "@owner/mypackage",
"version": "v1.0.0",
...
"files": [
"lib/**/*"
],
"type": "module",
"exports": {
"./module1": "./lib/module1/index.js",
"./module2": "./lib/module2/index.js",
"./package.json": "./package.json"
}
}
After publishing the module, the generated structure is as follows:
lib/
├─ module1/
│ ├─ index.js
├─ module2/
│ ├─ index.js
package.json
This leads to an import structure like this:
import {Foo} from "@owner/mypackage/lib/module1";
However, I desire the import structure to be like this:
import {Foo} from "@owner/mypackage/module1";
Is it possible to achieve this pattern? And are there any suggestions for improvement or following best practices?