clean-css / clean-css-cli

The command line interface to clean-css CSS optimizer
MIT License
305 stars 17 forks source link

Specify --output parameter as a folder, when using --batch #65

Closed alexejibishvili closed 3 years ago

alexejibishvili commented 3 years ago

Hello!

Can I have --output parameter specified as a folder while --batch param is present? I want to get minified css files one by one (as --batch param does) in some other folder. But in default manner, minified files are generated at same path as source files. I'd like to run script with --batch param and have --output /some/folder (not file). I know I can just copy minified files to any other folder with another script, but maybe my point of view is not so bad?

Thanks in advance for your information, advices and opinions!

jakubpawlowicz commented 3 years ago

Hey @alexejibishvili - I think we could do this. Question: when --batch matches CSS files in subdirectories then in the output folder those subdirectories should be automatically created as well, right?

alexejibishvili commented 3 years ago

Hi @jakubpawlowicz

Glad to see your positive feedback.

You are right, in the output folder, source folders/subfolders should be created/copied accordingly. Moreover, the behavior or folder creation can be parametrized. For example, if we specify some new parameter like --repeat-folder-structure, folders must be created exactly how they are in source. If the parameter is not specified, then all minified css files should be created in the root of destination folder.

In my opinion, this upgrade will be helpful for users.

I'm a new user of clean-css-cli. Generally I work on backend, not frontend. The very first impression after usage of the cli was exactly what I'm talking about.

--batch compiling > GOOD --output as a single file > GOOD --output as a folder > Would love to see in next updates

This will be helpful in scenario, where I want to minify css with --batch param, but I don't want to merge all of it in one file, but copy to dist all one by one. In order to achieve this, now you need to have one more line of npm command for copying these files.

Hope my opinion is clear and logical. Ready to answer any other questions and discuss any subject around it!

jakubpawlowicz commented 3 years ago

It is, thanks for valuable input!

I wonder what's the more useful case here: make it repeat folder structure by default or not. If people have any relative URLs in CSS then repeating it makes sense to them. Thoughts?

alexejibishvili commented 3 years ago

@jakubpawlowicz

You are completely right about relative URLs. I didn't mention it. Exactly because of that, I think repeating folder structure by default will be better to avoid errors, while CSS files will look for each other.

jakubpawlowicz commented 3 years ago

Agreed.

Personally, would you use the option to output all files in a root folder specified by --output ?

My thinking is we should not have features people don't use, so if you won't, then I'd go implementing "repeating folder structure" under --output folder, and THEN if someone comes in and says "I need to output all files in root directory" then we add it.

jasonreiche commented 3 years ago

I was trying to do this exact same thing this morning. I would love to see this feature implemented. Thank you for considering it.

npx cleancss -o dist/ --batch source/**/*.css --batch-suffix ''

Intuitively I expected the command above to duplicate the entire folder structure (where CSS is found) of source/ to dist/

Sidenote When I run the command above currently under Windows 10 PS, using double or single quotes, I get this error:

error: option '--batch-suffix ' argument missing

Running it without --batch-suffix results in files being created in place under source/

jakubpawlowicz commented 3 years ago

@alexejibishvili @jasonreiche this feature is already on main branch, and I want to release it in version 5.3 later this week.

Also @jasonreiche - I'm opening your sidenote as a separate issue.