Overview
I have a helper function library that I want to import into my projects.
Question
How can I correctly configure my tsconfig.json so only the files necessary are required when using npm run build? I don't want any extra files in to be included.
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"declaration": true,
"checkJs": true,
"sourceMap": true,
"outDir": "./dist",
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
},
"include": ["src/**/*"],
"compileOnSave": false,
"buildOnSave": false
}
Included in package.json
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
What's showing in node_modules
when imported into a project
- Should
src
be showing?? - How can I remove
jest.config.js
?
CodePudding user response:
The tsconfig.json
file doesn't have anything to do with what ends up in the final npm package. Per default (more or less) everything that is contained in your project directory will also be added into your package (except the node_modules
folder).
There are two ways to control the contents of your package
Create a file named
.npmignore
and add every file/folder you want to be excluded from your package. This works similar to the.gitignore
file. See the docs for details.You can add a
files
array to yourpackage.json
and add all files/folders you want to be included in your package. See docs for details.
What files need to be in your package, depends on the functionality your package provides. The test configuration probably isn't required for the final package, neither is the source ...
CodePudding user response:
If you want to exclude some files from your NPM package specify list of them in .npmignore
file. This way when you publish a new version of the package excluded file will disappear from you node_modules.
Also, if you use yarn, you can specify the list of files you want to remove after installing packages in the .yarnclean
file. But this way files will be deleted from all packages in node_modules.
If you haven't publish your package and use it with npm link
or yarn link
, you can't remove file from node_modules.
In fact, you can specify all the files in the package except dist
, package.json
and REAMDE.md