Michael_Scharf
Michael_Scharf

Reputation: 34498

In WebStorm, how do I exclude js files generated from ts/tsx?

When I use Enable Typescript Compiler, the TypeScript compiler generates a .js file for every .ts and .tsx file.

Enable Typescript Compiler

When doing code completion, WebStorm does not know that the files were generated and therefore it suggests completion from the generated files as well as from the TypeScript files. To prevent this, I have to go to every generated .js file and right click and Mark as Plain Text:

Mark as Plain Text

However, when I do a text search, I still get the hits from the generated JavaScript files:

enter image description here

Is there a simple way to exclude the generated files the way it is possible to exclude directories (except for creating a scope that excludes all the generated files)?

Upvotes: 9

Views: 2433

Answers (2)

user600838
user600838

Reputation:

  1. Open WebStorm Preferences (,) and then select the TypeScript options.
  2. Check the box for Use output path, and enter a directory name (relative to project directory). For example, build/$FileDirRelativeToProjectRoot$ -- the variable is important to avoid potential naming conflicts. It's best to use a build output directory that is excluded by .gitignore (assuming Git repo).

enter image description here

  1. Exclude the directory from indexing by right-clicking it from the Project pane, and choosing Mark Directory As > Excluded.

(Tested with WebStorm 2016.1.1 on OS X El Capitan)

Upvotes: 1

lena
lena

Reputation: 93728

Text search supports scopes. I'd suggest adding a custom scope in Preferences | Appearance & Behavior | Scopes with your generated files excluded and using this scope in the Find in Path dialog as the custom scope.

Upvotes: 3

Related Questions