terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
376 stars 30 forks source link

Allow async functions for minifyCSS and minifyJS #49

Closed abdonrd closed 3 years ago

abdonrd commented 4 years ago

Right now we can't use async functions for minifyCSS and minifyJS.

DanielRuf commented 4 years ago

I'm not sure I fully understand what you mean. Can you explain in detail what you mean?

abdonrd commented 4 years ago

Sure! Since Terser v5's minify function is asynchronous, I have tried to use it here: https://github.com/open-wc/open-wc/pull/1832#discussion_r486892866

But it doesn't work: https://app.circleci.com/pipelines/github/open-wc/open-wc/6693/workflows/0ab53976-0127-4ad0-aa37-87bd94861171/jobs/10546

It's the same error as:

Also related:

DanielRuf commented 4 years ago

Right, this is why we have to change and adapt code and properly test this. But I have not much time at the moment for working on this opensource project and more important things to work on.

PRs are very welcome. But afaik @evilebottnawi wanted to create a fork and push this forward (the migration to Terser 5).

DanielRuf commented 4 years ago

Not sure if we should use one of these or adjust the current code as needed.

abdonrd commented 4 years ago

@evilebottnawi where do you have a fork with the migration? Thanks in advance!

alexander-akait commented 4 years ago

@abdonrd no right now, we want to start implementation html-minimizer-webpack-plugin at the end of month, that's when i wanted to start creating fork

slorber commented 4 years ago

Hi,

We use this lib in Docusaurus (the doc site powering... Terser doc 🤪 ) and are affected by a weird bug where this lib tries to use Terser 5, only in yarn monorepo setups where another package use some other terser version (https://github.com/facebook/docusaurus/issues/3515#issuecomment-707119463).

(undefined) TypeError: Cannot read property 'replace' of undefined
    at Object.options.minifyJS (main:18614:28)
    at Object.chars (main:19102:24)
    at main:48074:19
    at String.replace (<anonymous>)
    at new HTMLParser (main:48066:19)
    at minify (main:18888:3)
    at module.exports.exports.minify (main:19249:16)
    at serverEntry_render (main:87667:38)

Probably not the fault of this lib (maybe a weird Yarn hoisting bug), but we'd appreciate the ability to use Terser v5 and ensure there's an await Terser.minify() to properly read the v5 promise, as that would probably solve our weird Yarn workspace issue + also allow to move to using only Terser v5 instead of a mix of v4 + v5.

Unfortunately can't dedicate time to help on this migration, but willing to be an early adopter as soon as there's a Terser v5 release :)

DanielRuf commented 3 years ago

html-minifier-terser v6.0.0 has been released now: https://www.npmjs.com/package/html-minifier-terser

If someone wants to help with the changelog, that would be great.

https://github.com/terser/html-minifier-terser/releases/tag/v6.0.0

slorber commented 3 years ago

shouldn't this issue be closed?

chrisspiegl commented 2 years ago

I just tried implementing CSS minification with remote importing of @import statements.

I found this issue and thought that minifyCSS should support async opperations.

But then also found that it does not?

The minifyJS does implement async?

https://github.com/terser/html-minifier-terser/blob/bec4bb1d093e2343d57e5d7273adca1d174323b4/src/htmlminifier.js#L697

The minifyCSS does not?

https://github.com/terser/html-minifier-terser/blob/bec4bb1d093e2343d57e5d7273adca1d174323b4/src/htmlminifier.js#L674

Am I missing something? Would this be a new issue to be opened?

sibiraj-s commented 2 years ago

Hi. Async function for minify-css is not implemented. clean-css is synchronous. A new issue can be opened to track async support for minify css.

chrisspiegl commented 2 years ago

@sibiraj-s I created a new issue since it would be useful for the functionality of importing remote @import css statements: https://github.com/terser/html-minifier-terser/issues/112