I have a project that I developed using TypeScript and compiled to JavaScript before publishing it as a CLI tool through npm. However, I am facing an issue where the TypeScript source code is being included in the npm package, along with other random .ts files.
While I don't mind having the TypeScript files in the package, it adds unnecessary bytes for the end user who won't need them.
I have tried to exclude the TypeScript files using various methods, but they still end up in the package.
Here is a simplified setup:
{
"name": "example",
"version": "1.0.0",
"main": "readme.js"
}
Despite trying to ignore all .ts files in the project using a .npmignore file, the readme.ts
file still gets included.
To reproduce the issue, I created a few source code files:
touch readme.ts
touch readme.js
When generating the npm package, the readme.ts
file is included, even though only readme.js
is referenced in the package.json
file.
I am puzzled as to why this is happening, since I have specifically excluded all .ts files and only specified readme.js
in the package.json.
$ npm --version
6.13.1