简体   繁体   English

JCSompress-处理JS文件中的特殊字符?

[英]JCSompress - dealing with special characters in JS files?

I'm in the initial stages of investigating JSCompress for MSBUILD : http://msbuildtasks.tigris.org/ 我正处于为MSBUILD研究JSCompress的初期阶段: http ://msbuildtasks.tigris.org/

For my initial testing I have a few JS files over which I am running this task, some of the files include already minified JS files (JQuery Library etc..) and some files contain Special characters. 对于我的初始测试,我有几个JS文件可用于运行此任务,其中一些文件包含已缩小的JS文件(JQuery库等),而某些文件包含特殊字符。

When the task runs everytime it encounters a special character in JS file it throws an error on the screen. 当任务每次运行时,在JS文件中遇到特殊字符时,都会在屏幕上引发错误。 How should I overcome this error so that it ignores special characters. 我应该如何克服此错误,以便忽略特殊字符。

I do not want to exclude any files on the basis of wildcard on filenames (eg **\\jquery*.js) since a developer can use the name as part of some other JS file which will then get excluded without minifying. 我不想基于文件名(例如** \\ jquery * .js)使用通配符排除任何文件,因为开发人员可以将该名称用作其他一些JS文件的一部分,然后将其排除在外而无需缩小。

Is there a way to achieve this or should I be looking at other tools ? 有没有办法实现这一目标,或者我应该考虑使用其他工具吗? Thanks ! 谢谢 !

Use the replace method to replace the special characters with a character entity of your own creation. 使用replace方法将特殊字符替换为您自己创建的字符实体。 Then after you have evaluated all the code use the replace method again to revert the special character conversion. 然后,在评估完所有代码之后,再次使用replace方法还原特殊字符转换。 I found I had to do this in my Pretty Diff tool because JavaScript cannot evaluate the difference between single and double quotes passed as string literals. 我发现必须在Pretty Diff工具中执行此操作,因为JavaScript无法评估作为字符串文字传递的单引号和双引号之间的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM