-
Notifications
You must be signed in to change notification settings - Fork 34
feature(minify) add ability to pass options to HTML minifier via JS api #52
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
feature(minify) add ability to pass options to HTML minifier via JS api #52
Conversation
|
This is a very good idea, but would be great to have ability to configure all
So example would look like this: const html = {
removeAttributeQuotes: false,
removeOptionalTags: false
};
const options = {
html,
};
const result = await minify('./client.js', options)
console.log(result);What do you think about such |
|
Sounds reasonable enough. I think I'll have time to do this tomorrow. |
|
Updates made. I was able to locally validate that HTML, CSS, and JS options worked. My particular use-case doesn't have any images its passing through, but it works the same, so it should work. |
|
That's amazing :), could you please add a couple tests for this? |
|
I considered that, but hesitated. Given that minify's only job in this regard is to pass the options to other tools, and that the APIs are defined entirely by the other tools, it makes sense that minify would not want to fail any particular test due to one of its dependencies changing their API. So the only thing minify would want to test is whether another one of the tools successfully received the options, right? And I'm not exactly sure how to test that. Maybe I'm overthinking it. Could use some brainstorming. |
|
The simplest way to test things, would be to pass options into |
…correct tests that were double-minifying items; update naming conventions in tests
|
I've added unit tests following this direction, and also added a |
|
I also noticed that some of the existing tests were passing minify's output into terser/css-clean (effectively re-minifying items) instead of testing the output of the original input into both, so I fixed that. Hopefully I've correctly understood the intention. |
|
That's amazing, thank you :)! |
|
Landed in v5.1.0 🎉 |
I am using this package to minify code that will be copy/pasted into a custom template in a CMS. This CMS has stipulations for what it considers valid, and I therefore needed to turn off certain options so that the resulting file passes the CMS's tests. In particular, it was necessary to keep attribute quotes and keep the closing
bodyandhtmltags intact.This PR allows options to be passed in via the JavaScript API. The user's options are then combined with the default options before being passed to the HTML minifier.
This also resolves #37, which was already closed, but was looking for the same sort of feature. It might resolve #24 as well.