3

I have an UglifyJS file watcher set up in IntelliJ IDEA, and it works great while I'm editing -- I modify the source js, the minified version gets created next to it automatically.

However, when I run an Ant build, and it copies the minified versions into the build working dir, the watcher "helpfully" creates doubly minified versions of them (*.min.min.js) in the build working dir, not ok.

I've set the Scope of the watcher to the 'src' module, but apparently that doesn't do what you'd think it would, because the doubles get created when Ant copies files into the 'build' module. Happens when I use IDEA to manually copy a single file from src to build too.

I don't see how to set this up to include *.js but exclude *.min.js, which is really the right thing. (Seems so sensible that Uglify should have it built in, but far as I can see it doesn't.)

Other than getting rid of the watcher and scripting the build do the minification, or copying only the original js versions and letting the watcher (re)create the minified ones, what's the best way to go here?

enigment
  • 3,316
  • 7
  • 30
  • 35
  • Does this answer your question? [Stop PhpStorm file watchers running recursively (with Autoprefixer)](https://stackoverflow.com/questions/24936401/stop-phpstorm-file-watchers-running-recursively-with-autoprefixer) – User Rebo Oct 16 '20 at 11:47

2 Answers2

10

Got this working, thanks to a helpful commenter on the IDEA forum. The key is setting up a custom Scope, which I tried to do before but failed.

Pattern I ended up with was this, for anyone with similar needs:

file[src]:*.js&&!file:*min.js*

Making the 'src' module current then opening the dlg and selecting it from the dropdown in the main watcher config window apparently doesn't actually filter by that module. Clicking the ... btn, then choosing it from the dlg that opens does, plus I added an explicit filename pattern to exclude already minified files too.

Works great now, far as I've tested (both a minimal Ant test and manually copying a file to 'build' in IDEA).

enigment
  • 3,316
  • 7
  • 30
  • 35
  • 1
    +1. This solution still works today. There are several interesting examples in the [phpStorm Scopes documentation](https://www.jetbrains.com/help/phpstorm/2021.2/settings-scopes.html#options). In this particular case, this alternative is proposed: `file:*js&&!file:*.min.*`- includes all JavaScript files except those generated by minification, which is indicated by the min extension. – Luismi Aug 19 '21 at 09:26
0

This is an old question, and perhaps the Watchers didn't have this functionality at the time.

Using JetBrains 'macro' codes makes the 'min.min.min.js' problem go away.

$FileNameWithoutAllExtensions$.js -m --source-map -o $ContentRoot$\prod\js\$FileNameWithoutAllExtensions$.min.js

I always set 'Scope' to 'Current File', too; why run uglify on files that haven't been altered? (I'm assuming that any 3rd party JS libraries are already minified).

GT.
  • 1,140
  • 13
  • 20