-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source maps are not usable when the banner option is used #22
Comments
Uglification (and this task) supports the retention of certain style comments which are often used for licenses, but the banner option is appended after uglification which bypasses that. If you're prepending a license as a comment starting with a bang ( yourTask : {
files : {
'dest.js' : ['src/license','src/**/*.js']
options : {
preserveComments : 'some'
}
}
} (with all your sourcemap options, obviously) Not sure what the best route is, whether this should be something handle by Uglify, whether this task should be smarter, or if this option should be the recommended route. |
@jsoverson - if you include the license that way can you still use Grunt tags in it? For example:
|
Oh, I could easily create that license file in another task. |
Hit this issue too, confusing as all get out until I disabled banners. |
jQuery ran afoul of this as reported at http://bugs.jquery.com/ticket/13776. My thoughts: a fully general fix may not be possible, but (as a workaround while waiting for an upstream fix) you could avoid requiring |
Thank you for writing about this issue. It helped me a lot after hours of fiddling with code! |
Another thank you for writing up this mystifying issue. This should really be in the docs! |
For what it's worth, we're workarounding this issue in jQuery currently: https://github.com/jquery/jquery/blob/master/build/tasks/uglify.js |
Related to Polymer/polymer#307 Root cause is gruntjs/grunt-contrib-uglify#22
An alternative here would be to modify the source map to add in padding for the length of the banner lines. Luckily this is actually a straightforward operation: Eg: {
mappings: "AABC,CCDD"
} -> {
mappings: ";;;;AABC,CCDD"
} Where the banner is 4 lines long. Could be an option if this isn't supported by uglify. |
👍 to this bug. It reaaaaaally needs a fix. For the time being, I've moved banner to footer: "\n" + banner |
Added a warning. This task shouldn't have any extra logic to support this, though uglifyjs itself may find it useful to add. Uglify supports keeping license comments in the source while maintaining sourcemap integrity, that just means adding the banner to a separate file and using that file as input to grunt-contrib-uglify. This seems like common practice, right? Having unminned files with the same banner and then uglifying that file? |
@jsoverson Not necessarily. Many projects, like jQuery, use simpler banners for minified source; compare http://code.jquery.com/jquery-2.1.0-beta1.js and http://code.jquery.com/jquery-2.1.0-beta1.min.js. |
Ok, makes sense. Opened up mishoo/UglifyJS#335 to see if that could be brought in there. Without that, I may need to dive into Uglify and submit a PR (others very welcome) |
@mishoo added the Thanks to everyone involved. |
…with source maps. The issue was fixed in grunt-contrib-uglify: gruntjs/grunt-contrib-uglify#22
…with source maps. (cherry-picked from d0fadbb) The issue was fixed in grunt-contrib-uglify: gruntjs/grunt-contrib-uglify#22
Issue gruntjs/grunt-contrib-uglify#22 resolved in 0.2.7
- Removed License hack due to gruntjs/grunt-contrib-uglify#22
…with source maps. (cherry-picked from d0fadbb) The issue was fixed in grunt-contrib-uglify: gruntjs/grunt-contrib-uglify#22
The banner option appends lines to the file which change the line numbering that was used by the source map module. This results in unusable source maps.
I'm not sure what the right fix is, here are some thoughts:
Note: I haven't researched the Uglify side of things to see if maybe there is an Uglify option for this already that we should be using.
The text was updated successfully, but these errors were encountered: