Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

telling uglify to keep certain comments (using CodeKit)

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)

like image 927
rgb_life Avatar asked Apr 28 '12 04:04

rgb_life


3 Answers

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
like image 110
soquel Avatar answered Jan 01 '23 11:01

soquel


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

like image 22
anemone928 Avatar answered Jan 01 '23 11:01

anemone928


You need to add either @preserve or @license to the comments you want to keep. It doesn't honour /*!

like image 39
texelate Avatar answered Jan 01 '23 10:01

texelate