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
385 stars 32 forks source link

[Bug]: Can't be used in the browser #160

Closed ffxsam closed 1 year ago

ffxsam commented 1 year ago

What happened?

I'm trying to use this in a Vite app, but this package seems to depend on clean-css which is a Node.js package (as it refers to process).

Version

v7.2.0

What browsers are you seeing the problem on?

Chrome

Link to reproduce

No response

Relevant log output

ReferenceError: process is not defined
    at node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/reader/rewrite-url.js (rewrite-url.js:19:17)
    at __require2 (chunk-FOWDQQBS.js?v=2c8b8fd9:19:50)
    at node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/reader/rebase.js (rebase.js:3:18)
    at __require2 (chunk-FOWDQQBS.js?v=2c8b8fd9:19:50)
    at node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/reader/read-sources.js (read-sources.js:9:14)
    at __require2 (chunk-FOWDQQBS.js?v=2c8b8fd9:19:50)
    at node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/lib/clean.js (clean.js:24:19)
    at __require2 (chunk-FOWDQQBS.js?v=2c8b8fd9:19:50)
    at node_modules/.pnpm/clean-css@5.3.2/node_modules/clean-css/index.js (index.js:1:18)
    at __require2 (chunk-FOWDQQBS.js?v=2c8b8fd9:19:50)
    at htmlminifier.js:1:22

Willing to submit a PR?

None

ffxsam commented 1 year ago

I suppose this is by design. I'm having a heck of a time finding an HTML minifier that works in a browser environment, for some reason.

sibiraj-s commented 1 year ago

hi @ffxsam You can make this work on browser. See https://github.com/terser/html-minifier-terser/blob/master/vite.config.js

And, You can see the working example here https://terser.org/html-minifier-terser/