Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore .js files made from TypeScript

Tags:

git

gitignore

I Have the following files:

  • ActiveTask.ts
  • ActiveTask.js
  • Controller.ts
  • Controller.js
  • _config.js
  • otherFile.js

And I want to commit only:

  • ActiveTask.ts
  • Controller.ts
  • _config.js
  • otherFile.js

How to ignore .js files that are the same name as the .ts files?

like image 593
Humberd Avatar asked Sep 24 '16 18:09

Humberd


People also ask

What type of file should .gitignore be?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

Do you commit a .gitignore file?

There is no explicit git ignore command: instead the .gitignore file must be edited and committed by hand when you have new files that you wish to ignore. . gitignore files contain patterns that are matched against file names in your repository to determine whether or not they should be ignored.


2 Answers

  1. Change the outDir entry of your tsconfig.json file. This is conventionally called build but you can name it whatever you'd like.
// tsconfig.json (mine is in the root directory of my project)
{
    "compilerOptions": {  
      ...
      "outDir": "myAwesomeSuperCoolBuildDirectoryThatIPromiseToChangeAndNotJustCopyBlindlyFromStackOverflowBecauseThatWouldBeBad",  
      "sourceMap": true,  
      ...
    }
}
  1. Add outDir followed by a forward slash --> / to your .gitignore file
// .gitignore (mine is in the root directory of my project)
myAwesomeSuperCoolBuildDirectoryThatIPromiseToChangeAndNotJustCopyBlindlyFromStackOverflowBecauseThatWouldBeBad/
  1. Delete old js.map and js files generated by TypeScript and build them again. This time, they will be built in the specified directory and will be ignored by git.
like image 155
stack_overflow_user Avatar answered Oct 23 '22 04:10

stack_overflow_user


For your particular case, I suggest:

In .gitignore

*.js
!_*.js

This will ignore all js files except what starting with underscore.

like image 34
Jeon Avatar answered Oct 23 '22 05:10

Jeon