I'm using CodeKit to develop a WordPress theme. Of course I'd like to compress the LESS when it's compiled into CSS, but uglify.js removes all comments.
Does anyone know how to mark specific comments for preservation?
Edit: just wanted to add that after trying this in 2019 with CodeKit 3, the exclamation point trick works perfectly! (Allen Bargi's answer)
Half a year later, I hit the same issue and the exclamation mark trick did not "do the trick" for me. Neither any of the @preserve
or @license
options listed in uglify documentation.
What did work is providing a regex on the commandline, e.g.:
uglifyjs file.js -c -m --comments '/^!|@(?:license|preserve)/' > file.min.js
You can use this way: --comments '/foo|bar/' : will keep only comments that contain "foo" or "bar". See more : https://github.com/mishoo/UglifyJS2#keeping-copyright-notices-or-other-comments
You need to add either @preserve or @license to the comments you want to keep. It doesn't honour /*!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With