Search code examples
typescriptnpmgitignore

Include .gitignored files compiled from typescript in `npm install -g`


I'd like to ignore the JavaScript files compiled from TypeScript in my git repo. (That greatly simplifies merging, rebasing, partial commits etc.) The relevant parts of my setup look like this:

tsconfig.json

{
    "compilerOptions": {
      "outDir": "./dist"
    }
}

.gitignore

dist

When installing globally like this:

rm -rf dist
node_modules/.bin/tsc
sudo npm install -g

the gitignored dist folder is not installed. Is there any proper solution to this? The following ones aren't really satisfactory:

  • Comment/uncomment dist in .gitignore before and after sudo npm install -g
  • Cope with parallelly managing ts and js files

Solution

  • I solved the problem by putting the following into my package.json:

    "files": [
      "/dist"
    ],
    

    Now, only the dist folder and README.md are packaged/installed. Found out about this possibility from a post by Jeff Dickey.