dowjones / gulp-bundle-assets

Create static asset (js, css) bundles from a config file: a common interface to combining, minifying, revisioning and more
MIT License
133 stars 36 forks source link

JS files with comment blocks are ignored/added to sourcemap instead of bundle #40

Open clocked0ne opened 9 years ago

clocked0ne commented 9 years ago

For example, jQuery Cookie always has the author comment block at the top of the file, even in the minified version.

When this is passed to the bundler it seems to misinterpret this and output the file as a source file instead in the source mapping:

{"version":3,"sources":["src/jquery.cookie.js","?"] ...

and further down:

"file":"main-eff34b73.js","sourceRoot":"/source/","sourcesContent":["
/**\n * Cookie plugin\n *\n * Copyright (c) 2006 Klaus Hartl (stilbuero.de)\n * Dual licensed under the MIT an
d GPL licenses:\n * http://www.opensource.org/licenses/mit-license.php\n * http://www.gnu.org/licenses/gpl.htm
l\n *\n */\n\njQuery.cookie = function(name, value, options) {\n    if (typeof value != 'undefined') { // name
 and value given, set cookie\n        options = options || {};\n        if (value === null) {\n            val
ue = '';\n            options.expires = -1;\n        }\n        var expires = '';\n        if (options.expires
 && (typeof options.expires == 'number' || options.expires.toUTCString)) {\n            var date;\n           
 if (typeof options.expires == 'number') {\n                date = new Date();\n                date.setTime(d
ate.getTime() + (options.expires * 24 * 60 * 60 * 1000));\n            } else {\n                date = option
s.expires;\n            }\n            expires = '; expires=' + date.toUTCString(); // use expires attribute, 
max-age is not supported by IE\n        }\n        // CAUTION: Needed to parenthesize options.path and options
.domain\n        // in the following expressions, otherwise they evaluate to undefined\n        // in the pack
ed version for some reason...\n        var path = options.path ? '; path=' + (options.path) : '';\n        var
 domain = options.domain ? '; domain=' + (options.domain) : '';\n        var secure = options.secure ? '; secu
re' : '';\n        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].joi
n('');\n    } else { // only name given, get cookie\n        var cookieValue = null;\n        if (document.coo
kie && document.cookie != '') {\n            var cookies = document.cookie.split(';');\n            for (var i
 = 0; i < cookies.length; i++) {\n                var cookie = jQuery.trim(cookies[i]);\n                // Do
es this cookie string begin with the name we want?\n                if (cookie.substring(0, name.length + 1) =
= (name + '=')) {\n                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\n 
                   break;\n                }\n            }\n        }\n        return cookieValue;\n    }\n};
"]}

My temporary solution is to make a copy of the file and remove the comments, which works, but is obviously not ideal.

clocked0ne commented 9 years ago

and once comments are removed:

{"version":3,"sources":["?"]
"file":"main-c2a2dd4a.js","sourceRoot":"/source/","sourcesContent":[]}
chmontgomery commented 9 years ago

If you have time, would love a PR!

clocked0ne commented 9 years ago

I don't at the moment unfortunately, though I would guess that the issue is with the uglify component handling these comment blocks badly.