[英]JavaScript compression that preserves public methods?
I'm trying to minimize a library that I've created. 我正在尝试最小化我创建的库。 Unfortunately, because I started developing the library several years ago, it does not use any standard way of declaring methods and private properties.
不幸的是,因为几年前我开始开发该库,所以它没有使用任何标准的方法和私有属性声明方式。 Basically, my code looks like:
基本上,我的代码如下所示:
/** @class Sample abstract class. */
myname.space.AbstractClass = function() {
/** Sample protected property A
* @private
*/
this.longNameProtectedPropertyA = 10;
/** Sample protected property B
* @private
*/
this.longNameProtectedPropertyB = 20;
}
/** Sample public method A.
* @methodOf myname.space.AbstractClass#
*/
myname.space.AbstractClass.prototype.publicMethodA = function() {
return this.longNamePrivatePropertyA;
}
/** Sample public method B.
* @methodOf myname.space.AbstractClass#
*/
myname.space.AbstractClass.prototype.publicMethodB = function() {
return this.longNamePrivatePropertyB;
}
/** @class Sample concrete class.
* @extends myname.space.AbstractClass
*/
myname.space.ConcreteClass = function() {
myname.space.AbstractClass.call(this);
/** Sample protected property C.
* @protected
*/
this.longNameProtectedPropertyC = 30;
}
myname.space.ConcreteClass.trickyExtend(myname.space.AbstractClass);
/** Overrides publicMethodB of the base class.
* @methodOf myname.space.ConcreteClass# */
myname.space.ConcreteClass.prototype.publicMethodB = function() {
return this.longNameProtectedPropertyC * this.longNameProtectedPropertyB;
}
In such a long example I tried to show the coding style that I use. 在这么长的示例中,我试图显示我使用的编码样式。 I realize that today, it is non-standard.
我意识到今天,这是非标准的。 But my library is already written like that and it works perfectly.
但是我的库已经这样写了,并且运行良好。
Now my problem is that I want to minify the code. 现在我的问题是我想缩小代码。 What I need is to compress the long names of private properties, but I need to preserve the names of public methods.
我需要压缩私有属性的长名称,但是我需要保留公共方法的名称。
I've tried the YUI compressor and Google's Closure compiler. 我尝试了YUI压缩器和Google的Closure编译器。 Neither worked as I needed.
都没有按我的需要工作。 Either both private properties' and public methods' names were obfuscated, or none of them were.
私有属性和公共方法的名称都被混淆,或者都不被混淆。
Is there a way how to do that? 有办法吗? I'm ready to spend long time by annotating hundreds of my methods/properties if it would help.
我准备花很长时间通过注释数百个方法/属性来帮助您。 Is there some minifier that could help me?
有没有可以帮助我的缩小器?
You could try rewriting, before minimisation, with associative syntax, eg : 您可以在最小化之前尝试使用关联语法进行重写,例如:
myname.space.AbstractClass.prototype['publicMethodA'] = function() {
return this.longNamePrivatePropertyA;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.