File Watchers - Output path to refresh - confusion

Hello,

I've spent almost half day tweaking parameters of File Watcher. The main struggle was filling the Output path to refresh parameter. I don't understand why it is necessary to add it by hand and it cannot be inferred by IDE in the first place. If it was an actual output path it shouldn't be difficult to have it infer automatically. But maybe I'm wrong...

Since it was not working from the beginning for my css minifier, I started googling and came across this older post:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/207038005-SCSS-file-watcher-output-directory

Here is an answers from JetBrains Team Member that it is necessary to use: $ProjectFileDir$/assets/css/$FileNameWithoutExtension$.css - which is a path to the newly generated file and not a path to the directory of the file(which is for me more natural...). So I used this solution and it works for lessc preprocessor, but not for csso minifier. With csso when I used whole path to the new file, it generated an empty file. When I removed the file name macro, it started to work.

So my questions are:

1. Cannot we avoid filling up this output directory for refresh? If not why.

2. What actually should be filled there?

0
3 comments

Hi there,

File Watcher is basically an External Tool that can be run on Save/file modification (as you type) + the ability to check specific file(s) for modifications after the tool is run.

 

2. What actually should be filled there?

A path(s) to the file(s) that you wish to refresh the file info that the IDE's VFS (virtual file system) knows about.

https://www.jetbrains.com/help/webstorm/using-file-watchers.html#transpilerBehaviour -- point #3.

 

1. Cannot we avoid filling up this output directory for refresh? If not why.

You should be able skip this field completely if you do not need it. Unless, perhaps, the tool is actually using the output. See #3 in https://www.jetbrains.com/help/webstorm/using-file-watchers.html#ws_filewatcher_advanced_options

 

Basically, after the File Watcher finishes running, the IDE will check such path(s) for any possible file modifications (by file size + timestamp AFAIK). This info can then be used for various things, like:

1

1. With filled option as in the picture -> style.min.css is empty.

I believe this is because you have the "Create output file from stdout" option enabled. If I remember correctly, when enabled the IDE takes the output of the tool (whatever it prints into stdout) and saves it into the "Output paths to refresh" file. It is mentioned in my links in the previous comment. And if the output is empty .. then the final file will be empty as well -- logical, right?

If your tool does not do that (which is the case, since you are using "-o ..." in the Arguments field) you should then disable this option.

2. When left empty -> IT WORKS.

That's because you have "-o $SourcepathEnrty$\css\..." in the Arguments field. Your CSSO saves the minified content right into that file. And when "Output paths to refresh" is empty .. then the "Create output file from stdout" option must be ignored.

3. Mysterious case - I cannot replicate any more -> minified styles were created one after another - style.min.min.css, style.min.min.min.css ...

That's expected behaviour actually. The thing is: file named styles.min.css also falls into the "Cascading Style Sheet" category (as it ends with .css). So the IDE sees the new styles.min.css file and runs the same file watcher on it again (which produces styles.min.min.css), and again...

In such cases you need to make your own custom scope and only include desired files (exclude already minified). An example: https://stackoverflow.com/a/24938053/783119

 

Also -- check here: the chained watchers work: https://stackoverflow.com/a/68718983/783119

Another alternative: make yourself a batch/bash script that will do the actual multi-step job (where you call your lessc and csso to compile into CSS first and then minify the result). And then use it as a File Watcher.

1

Thank you for you detailed answer!

So if I need to run lessc first and minify it witch csso afterwards, it would be just fine to trigger lessc by "auto-save" and csso by only "on external changes"? Please see my configs:

 

 

 

So I ended up with 3 different outcomes when I kept changing the output path to refresh in csso minification:

1. With filled option as in the picture -> style.min.css is empty.

2. When left empty -> IT WORKS.

3. Mysterious case - I cannot replicate any more -> minified styles were created one after another - style.min.min.css, style.min.min.min.css ...

Would you be so kind and revise my solution?

Thank you!

0

Please sign in to leave a comment.