gulp-bundle-assets icon indicating copy to clipboard operation
gulp-bundle-assets copied to clipboard

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

Open clocked0ne opened this issue 10 years ago • 3 comments

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 avatar Jan 09 '15 19:01 clocked0ne

and once comments are removed:

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

clocked0ne avatar Jan 09 '15 19:01 clocked0ne

If you have time, would love a PR!

chmontgomery avatar Jan 23 '15 15:01 chmontgomery

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

clocked0ne avatar Jan 23 '15 17:01 clocked0ne