yui / yuicompressor

YUI Compressor
http://yui.github.com/yuicompressor/
Other
3.01k stars 662 forks source link

Multiple compress, batch explanation. #305

Closed Anatolich closed 6 years ago

Anatolich commented 6 years ago

Please give me an explanation, in my problem. I want to compress multiple css files or js, by given following bash:

sudo find /path/to/css/ -type f -name '*.css' -not -name '*.min.css' -exec yui-compressor {} -o '.css$:.min.css' \;

But this isn't work, he create a .css$:.min.css file, in root folder by default.

Ok fine, now get a trick:

sudo find /path/to/css/ -type f -name '*.css' -not -name '*.min.css' -exec yui-compressor /path/to/css/batch_css_1.css /path/to/css/batch_css_2.css /path/to/css/batch_css_3.css -o '.css$:.min.css' \;

And this code work fine.

What the difference in input param?

Anatolich commented 6 years ago

Problem solved.

This behavior is due to the peculiarities of the find command, in a bunch with the specified exec parameter in the example {} \;

In this case, output result of the find, processed as though if in a cycle, submitting the results one by one, executing the command specified in exec every time, for each item.

For us, it is necessary to accumulate the result and submit him, in to the input yuicompressor.

A special parameter must be specified in the format {} + and not {} to transfer a single accumulated parameter.

Working variant for the given example:

sudo find /path/to/css/ -type f -name '*.css' -not -name '*.min.css' -exec yui-compressor -o '.css$:.min.css' {} +