Search code examples
phpstorm

PhpStorm: how to add watcher on 1 JS file only and not on ALL JS files?


1) How to add a watcher on 1 file ONLY ?

The goal is to put a obfuscator on 1 JS file only (the main.js) : I was unable to do that: obfuscation is applied to ANY JS file I do modify.

2) How to avoid infinite recurrent rules ? I have 2 watchers right now:

  • minification on JS files
  • obfuscation on JS files

Problem is: PhpStorm creates infinite .min.obf.min.obf...js : it looks it applies these 2 rules in endless.


Solution

  • Use Scope field to limit the watched files: create custom Scope that will include only desired file(s) and/or folders and use it there in File Watcher.

    Scope can accept both "include" and "exclude" patterns at the same time so it's very flexible in filtering the files.


    The same approach for your second issue -- use scope to not to process already processed files.

    For example: https://stackoverflow.com/a/24938053/783119


    The alternative to having 2 separate File Watchers is creating some batch/shell script that will do that minification + obfuscation and use it as a program in File Watcher.

    Another option -- use build tools (Grunt/Gulp or alike) and call appropriate task there.