grunt-contrib-concat icon indicating copy to clipboard operation
grunt-contrib-concat copied to clipboard

Make stripBanners smarter?

Open cowboy opened this issue 12 years ago • 9 comments

Right now it's a little simple. Maybe we can add more filtering options. Or something. Whatever.

cowboy avatar Nov 23 '12 16:11 cowboy

Or maybe rename it to be more like grunt-contrib-uglify

Maybe we can just use uglifyjs under the hood to strip the banners.

cowboy avatar Dec 05 '12 22:12 cowboy

+1 for using uglify

pjnovas avatar Feb 06 '13 23:02 pjnovas

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.

stevenbenner avatar Mar 27 '13 17:03 stevenbenner

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 // line comments 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 // line comments.
  • stripBanners: {block: false}: Will NOT remove /* block */ comments.

Otherwise if not, I can make it compatible with the current options. Thanks!

shama avatar Jul 12 '13 05:07 shama

:+1: for uncommentify using new options

jamesplease avatar Feb 20 '14 12:02 jamesplease

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 avatar Mar 06 '14 17:03 lydell

@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.

jamesplease avatar Mar 06 '14 17:03 jamesplease

I see. Thanks!

lydell avatar Mar 06 '14 18:03 lydell

stripBanners: {
                    options: {
                        block: true,
                        line: true
                    }
                }

line: true is not working for me. Its just remove block comments. Can you please suggest on this?

Napster2210 avatar May 09 '16 07:05 Napster2210