【问题标题】:Preserve already minified code fragments in Google Closure Compiler在 Google Closure Compiler 中保留已经缩小的代码片段
【发布时间】:2013-04-03 08:23:36
【问题描述】:

我有一些代码,我想通过 Google Closure Compiler 运行。

然而,问题是,除了我自己的代码之外,还有一段已经缩小的代码片段,我无法获得其原始来源。

因此,当通过编译器运行此代码时,缩小的代码会再次被编译,从而完全搞砸了。

有人知道防止 Google Closure Compiler 编译代码的某些部分的注解或其他技术吗?

// my code
function someFunction() {
  // some code blabla
}

someFunction();

// already minified code; should be preserved in its state
!function(){window.a='abc'; /* ... */ }();

PS:我知道,一种解决方案是将缩小后的代码移动到另一个文件,但我想知道是否还有其他解决方案。

【问题讨论】:

  • 从编译中排除该部分是我知道的唯一方法。

标签: javascript google-closure-compiler


【解决方案1】:

人们使用两种解决方案: 1) 编译后连接已经编译好的源码。我见过人们为此使用编译器的“输出包装器”选项。 2) 将代码包装在 eval 中(或使用附加脚本标签注入页面):

eval("my precompiled compiled code here");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    相关资源
    最近更新 更多