IntelliJ IDEA 2017.3 Help

New Watcher Dialog

File | Settings | Tools | File Watchers - New Watcher for Windows and Linux
IntelliJ IDEA | Preferences | Tools | File Watchers - New Watcher for macOS
Ctrl+Alt+S settings


The dialog opens when you click the Add new.png or Edit edit1 button on the File Watchers page. Use the dialog box to create a project File Watcher based on a predefined IntelliJ IDEA File Watcher template or to edit an existing project File Watcher.

Each template contains the settings that are optimal for the selected compiler. So in most cases, all you need is specify the path to the compiler executable.

Name

NameIn this text box, type the name of the File Watcher. By default, IntelliJ IDEA suggests the name of the selected predefined template.

Files to watch

File typeUse this drop-down list to specify the expected type of input files. The File Watcher will consider only files of this type as subject for analyzing and processing. File types are recognised based on associations between file types and file extensions.

By default, the field shows the file type in accordance with the chosen predefined template.

ScopeUse this drop-down list to define the range of files the File Watcher can be applied to. Changes in these files will invoke the File Watcher either immediately or upon save or frame deactivation, depending on the status of the Auto-save edited files to trigger the watcher checkbox.

Choose one of the predefined scopes from the drop-down list or click browseButton and configure a custom scope in the Scopes dialog that opens.

See Scope for details.

Track only root files

When the File Watcher is invoked in a file, IntelliJ IDEA detects all the files where it is included. For each of the detected files, in its turn, IntelliJ IDEA again detects the containing files. This operation is repeated recursively until IntelliJ IDEA reaches the files that are not included anywhere within the specified scope. These files are referred to as root files (do not confuse with content roots).

  • When this checkbox is selected, the File Watcher runs only against the root files.
  • When the checkbox is cleared, the File Watcher runs against the file from which it is invoked and against all the files in which this file is included recursively within the specified scope.
Note that the Scope setting overrides the Track only root files checkbox setting: if a dependency is outside the specified scope, the File Watcher is not applied to it.

This option is available only for Babel, Closure Compiler, Compass, Jade, Less, Sass/SCSS, Stylus, UglifyJS, and YUI Compressor JS.

Tool to run on changes

In this area, configure interaction with the compiler: specify the executable file to use, the arguments to pass to it, and customize the default template settings for input and output.

ProgramIn this text box, specify the path to the executable file of the compiler (.exe, .cmd, .bat, or other depending on the specific tool.)

.jar archives are also acceptable but defining PATH variables for them is not supported.

ArgumentsIn this text box, define the arguments to pass to the compiler and thus influence its behaviour.
  • To change the default output location, specify a custom location for the compiler to store the generated files. Note that if you re-define the default output location here you need to clear the Create output file from stdout checkbox in the Advanced Options area because otherwise the content of your generated file will be overwritten by the compiler's output stream.
  • Suppose, an action affects several files watched by the same File Watcher. As a result, the File Watcher wakes up on each changed file. However, running several tasks is redundant because the File Watcher processes all the watched files during the first run. To tell IntelliJ IDEA that running File Watcher just once in enough, even if several files have been changed, make sure there is no file-specific macro, such as $FileNameWithoutExtension$, in the Arguments field.

When specifying the arguments, follow these rules:

  • Use spaces as separators.
  • If an argument contains spaces, enclose them or the entire argument in double quotes: some" "arg or "some arg".
  • If an argument contains double quotes, use backslashes to escape them: -Dmy.prop=\"quoted_value"\.

Output paths to refreshIn this text box, specify the files where the compiler stores its output: the resulting source code, source maps, and dependencies. In other words, tell IntelliJ IDEA where it should search for the files generated through compilation.
Please note, that changing the value in this text box does not make the compiler store its output in another location. To do that, specify the desired output location in the Arguments text box: type the output paths using colons as separators or click the Insert Macro button to open the Macros dialog box and select the desired pattern from the list.

Working Directory and Environment Variables

Working directoryIn this text box, specify the directory to which the compiler will be applied. Because the tool is always invoked in the context of a file, the default working directory is the directory of the current file. The default working directory is specified in all predefined templates through a $FileDir$ macros. To specify a custom working directory, type the path to it in the text box, or click browseButton and choose the directory in the Select Path dialog box, or click Insert Macro and select the desired macro from the list in the Macros dialog box.

If you leave the field empty, IntelliJ IDEA uses the directory of the file where the File Watcher is invoked.

Environment variablesUse this text box to specify a the PATH variable for a tool that is required for starting the compiler but is not referenced in the path to it.

Advanced Options

Auto-save edited files to trigger the watcher
  • When this checkbox is selected, IntelliJ IDEA immediately saves a file as soon as you edit it so the File Watcher wakes up immediately.
  • When the checkbox is cleared, the File Watcher starts upon save (File | Save All) or when you move the focus from IntelliJ IDEA (on frame deactivation).
Trigger the watcher on external changes
  • When this checkbox is selected, the File Watcher wakes up on any changes to a file from its scope, including changes made outside IntelliJ IDEA or the changes after you checkout a branch in you version control system.
  • When the checkbox is cleared, the File Watcher starts only when a file from its scope is updated from IntelliJ IDEA and ignores other changes, for example, changes received from your version control system.

By default, the checkbox is selected.

Trigger watcher regardless of syntax errors
  • When the checkbox is selected, the File Watcher start regardless of the syntactical correctness of a file. The File Watcher will start upon update, save, or frame deactivation, depending on the status of the Auto-save edited files to trigger the watcher checkbox.
  • When this checkbox is cleared, the File Watcher ignores all triggers in files that are syntactically invalid and starts only in error-free files.
Create output file from stdout
  • When this checkbox is selected, IntelliJ IDEA reads the native compiler output (standard output stream (stdout)) and generates the resulting files from it.
  • When the checkbox is cleared, the compiler writes its output directly to the files specified in the Output paths to refresh field.

Some compilers generate a standard output stream (stdout) file, others do not, which may lead to errors. Therefore it is strongly recommended that you preserve the default setting.

Show console From this drop-down list, choose when you want the File Watcher to open the console.
  • Always: with this option, the console opens when the File Watcher starts.
  • Error: with this option, the File Watcher opens the console only if any errors occur during compilation.
  • Never: choose this option to suppress opening the console at all.
Output Filters In this text box, specify the filters to distinguish the output of the File Watcher from other output. These filters make the basis for:
  1. Displaying paths to the File Watcher output files as links in error and other messages and logs. When you click such link, the corresponding file is opened in the editor. For example, to get useful error messages displayed, specify the following expression in the Regular expression to match output field of the Add/Edit Filter Dialog:
    $FILE_PATH$:$LINE$ $MESSAGE$
  2. Error highlighting in the output files.

Examples of customizing the behaviour of a compiler

Any compiler is an external, third-party tool. Therefore the only way to influence a compiler is pass arguments to it just as if you were working in the command line mode. These arguments are specific for each tool. Below are two examples of customizing the default output location for the CoffeeScript compiler.

Suppose, you have a project with the following folder structure:

fileWatcherExampleImage1
By default, the generated files will be stored in the folder where the original file is. You can change this default location and have the generated files stored in the js folder. Moreover, you can have them stored in a flat list or arranged in the folder structure that repeats the original structure under the app node.

  • To have all the generated files stored in the output js folder without retaining the original folder structure under the app folder:
    1. In the Arguments text box, type:
      --output $ProjectFileDir$\js\ --compile --map $FileName$
    2. In the Output paths to refresh text box, type:
      $ProjectFileDir$\js\$FileNameWithoutExtension$.js:$ProjectFileDir$\js\$FileNameWithoutExtension$.map

    As a result, the project tree looks as follows:

    fileWatcherExampleImage2

  • To have the original folder structure under the app node retained in the output js folder:
    1. In the Arguments text box, type:
      --output $ProjectFileDir$\js\$FileDirRelativeToProjectRoot$\ --compile --map $FileName$
    2. In the Output paths to refresh text box, type:
      $ProjectFileDir$\js\$FileDirRelativeToProjectRoot$\$FileNameWithoutExtension$.js:$ProjectFileDir$\js\$FileDirRelativeToProjectRoot$\$FileNameWithoutExtension$.map

    As a result, the project tree looks as follows:

    fileWatcherExampleImage3

Last modified: 12 December 2017

See Also