Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recursive option to command line #323

Closed
mathpere opened this issue Jan 4, 2015 · 10 comments · Fixed by #432
Closed

Add recursive option to command line #323

mathpere opened this issue Jan 4, 2015 · 10 comments · Fixed by #432
Labels

Comments

@mathpere
Copy link

mathpere commented Jan 4, 2015

Hello,

Is there any plan to add recursive option to command line options + output dir option?
(in order to process multiple files inside subdirectories)

html-minifier src dest

This command would process all *.html files inside src directory and output would be written in dest directory.

@kangax
Copy link
Owner

kangax commented Jan 4, 2015

Good idea. I'd love to have this so please feel free to send a PR.

@kangax kangax added the feature label Jan 4, 2015
@davidhund
Copy link

This would be awesome. At the moment I'm trying to watch ./src/*.html and have something like: html-minifier -o ./dist/* <STDIN>

If html-minifier picks up STDOUT from some other process (such as watch) adding an output-folder would be enough, no?

Anyway: 'globs' would be awesome: html-minifier ./src/**/*.html ./dest

@simonewebdesign
Copy link

I'm writing an npm script and I tried doing something like:

html-minifier -o dist/* source/*.html

But it's not producing anything. Would be great indeed to have a output-folder flag.

@vinyanalista
Copy link

+1 for that feature! html-minifier seems to be the best HTML compressor out there!

@kangax
Copy link
Owner

kangax commented Jul 23, 2015

Damn right, it is! :)

Sent from my iPhone

On 22 Jul 2015, at 20:06, Antônio Vinícius Menezes Medeiros notifications@github.com wrote:

+1 for that feature! html-minifier seems to be the best HTML compressor out there!


Reply to this email directly or view it on GitHub.

@vinyanalista
Copy link

I know almost nothing about Node.js, but I know a little about Shell Script, so I made this script to minify HTML files from a folder and its subfolders:

#!/bin/bash
# minify_html.sh
if test $# -ne 2
then
    echo "usage: sh minify_html.sh sourcedir destdir";
    exit 1;
fi

set -xv

for FOLDER in `find $1 -type d`
do
    mkdir -p "$2/${FOLDER#$1}";
done

for HTML_FILE in `find $1 -type f -name "*.html"`
do
    html-minifier --remove-comments -o "$2/${HTML_FILE#$1}" "$HTML_FILE";
done

for ASSET in `find $1 -type f ! -name "*.html"`
do
    cp "$ASSET" "$2/${ASSET#$1}";
done

How to use it:

sh minify_html.sh sourcedir destdir

What it does in those three for loops:

  1. Replicate the folder structure
  2. Minify all the HTML files found
  3. Copy all the other files

But it does not seem to work... =/ I'm trying to minify my personal website, and it seems like the html-minifier command crashes for the second file found in the second for loop, which is /blog/2012/index.html. The first and the third for loops work as expected.

Am I doing something wrong? Did I forget something?

@vinyanalista
Copy link

--remove-comments is just an example. Do I need to tell html-minifier everything I want it to do? Or there is something like a default config? I realized that if I pass it only the input and the output files, it seems actually to just copy the file. What if I want it to perform exactly like the online version?

vinyanalista added a commit to vinyanalista/vinyanalista-website that referenced this issue Jul 25, 2015
genintho pushed a commit to genintho/html-minifier that referenced this issue Nov 10, 2015
@ramonck
Copy link
Contributor

ramonck commented Jul 1, 2016

Created a pull request to fix this, was generating a pain for me, hope this helps others as well, the idea is to use a --file-ext html, so you only parse what you want.

#680

Best Regards,

@fulldecent
Copy link

"(libuv) kqueue(): Too many open files"

@Geczy
Copy link

Geczy commented Dec 6, 2020

I solved it by doing this. It will run for every html file in the directory you run it in

find . -name *.html -type f -exec html-minifier -o {} {} --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true --file-ext html \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants