grunt-contrib-concat
grunt-contrib-concat copied to clipboard
Make stripBanners smarter?
Right now it's a little simple. Maybe we can add more filtering options. Or something. Whatever.
Or maybe rename it to be more like grunt-contrib-uglify
Maybe we can just use uglifyjs under the hood to strip the banners.
+1 for using uglify
Has anyone taken a look at the uglifyjs API and found a way to do this? I did a basic attempt to implement a stripBanners option that passed the string through uglifyjs, but I couldn't find a (non-destructive) way to do it.
I'll admit that I didn't spend too much time going over the uglify API, but it looks to me like the only way to strip comments is by enabling the compressor which will alter the supplied code in some way no matter how many options you disable. It also only seems to support preserving banner comments, not removing them while keeping the other comments.
I've just released https://github.com/shama/uncommentify which uses falafel (esprima underneath) to remove comments. This method is robust as it walks the AST tree looking for comments rather than regexp.
The options are a little different than what is currently implemented here. @cowboy Would you be keen to changing the options to:
stripBanners: true: Removes the first/* block */or contiguous leading// linecomments but NOT/*! ... */or//!comments.stripBanners: {force: true}: Will remove/*! ... */and//!comments.stripBanners: {all: true}: Will remove ALL comments but not/*! ... */and//!comments.stripBanners: {line: false}: Will NOT remove// linecomments.stripBanners: {block: false}: Will NOT remove/* block */comments.
Otherwise if not, I can make it compatible with the current options. Thanks!
:+1: for uncommentify using new options
Now that source maps is about to happen (#59), we also need to think about source map support for this feature. Removing banners will break all line mappings after it. Using something esprima based is the way to go.
... unless, the feature is removed entirely, because I don’t understand how it is useful. Please enlighten me!
@lydell, the current solution we have in place is to make the options mutually exclusive. And though I wouldn't use the strip functionality myself, it seems like enough people do that we should probably keep it around.
I see. Thanks!
stripBanners: {
options: {
block: true,
line: true
}
}
line: true is not working for me. Its just remove block comments. Can you please suggest on this?