最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jul 16, 2012 at 9:14 Jonathan OngJonathan Ong 20.4k18 gold badges82 silver badges118 bronze badges 2
  • 1 Try starting your own scripts with a semi-colon so that any trailing lines left by previous scripts when you concatenate them are terminated properly. That could be causing a problem in your instance? – Purpletoucan Commented Jul 16, 2012 at 9:24
  • none of these scripts are "my scripts" – Jonathan Ong Commented Aug 8, 2012 at 0:10
Add a ment  | 

2 Answers 2

Reset to default 7

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 es to BOM bytes.

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

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

发布评论

评论列表(0)

  1. 暂无评论