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]: Error Minimizing JSON File #175

Open cemalgnlts opened 11 months ago

cemalgnlts commented 11 months ago

What happened?

I tried to minimize this JSON file:

{
  "match": "(?<![_$[:alnum:]])(?:(?<=\\.\\.\\.)|(?<!\\.))(catch|finally|throw|try)(?![_$[:alnum:]])(?:(?=\\.\\.\\.)|(?!\\.))"
}

The error I received: Error: Parse Error: <![$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(catch|finally|throw|try)(?![$[:alnum:]])(?:(?=\.\.\.)|(?!\.))" }

You can go to https://terser.org/html-minifier-terser/ and paste the JSON content and examine it.

Version

latest

What browsers are you seeing the problem on?

Chrome

Link to reproduce

No response

Relevant log output

No response

Willing to submit a PR?

None

TaiYouWeb commented 10 months ago

About

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
DanielRuf commented 3 weeks ago

It's called html-minifier for a reason.

Try wrapping it in <script> like you can see in the screenshot:

image

To only minimize pure json, there are other tools that you can use. For example jq. https://remarkablemark.org/blog/2021/09/30/jq-minify-json/