Skip to content
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

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

Open
clocked0ne opened this issue Jan 9, 2015 · 3 comments
Labels
Milestone

Comments

@clocked0ne
Copy link

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
Copy link
Author

and once comments are removed:

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

@chmontgomery
Copy link
Contributor

If you have time, would love a PR!

@clocked0ne
Copy link
Author

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

@chmontgomery chmontgomery added this to the Ice Box milestone May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants