Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uglify-JS Error: Unexpected character '' when concatenating then minifying select2

I am concatenting select2 to my other javascript files like so:

cat scripts/jquery-timeago.js scripts/jquery-autosize.js scripts/select2.js > public/vendors.js
uglifyjs -nc -o public/vendors.min.js public/vendors.js

However, I found an issue where there would be an empty whitespace character prepended right before select2 only after concatenation, which then causes a parsing error in UglifyJS. If I go to the beginning of where select2 starts in the concatenated file and press backspace, an empty character is deleted and minification works fine.

What is going on? How can I fix this?

like image 908
Jonathan Ong Avatar asked Jul 16 '12 09:07

Jonathan Ong


2 Answers

Just opened issue #306 on this at select2 github repo.

select2.js is saved with UTF8 with BOM encoding. When select2.js is concatenated with other files and passed to uglifyjs, uglifyjs breaks when it comes to BOM bytes.

To fix this simply save file in UTF8 encoding (without BOM).

like image 104
mindeh Avatar answered Sep 28 '22 06:09

mindeh


I see that this has been marked as answered. I found another way, though.

I needed to send uglify two options: ascii_only and quote_keys. Set both to true. That also works

like image 26
vbullinger Avatar answered Sep 28 '22 07:09

vbullinger