Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

586
Views
How can I correctly configure my tsconfig.json so only the files necessary are required when using npm run build?

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

  1. Should src be showing??
  2. How can I remove jest.config.js?

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

  1. 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.

  2. You can add a files array to your package.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 ...

about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!