Firebase ionic2-rc0 和汇总 - “汇总:强烈建议不要使用 `eval`”

Firebase ionic2-rc0 and rollup - “rollup: Use of `eval` is strongly discouraged”

我已将我的 ionic 应用程序从 beta 11 更新到 rc0。所以这意味着我已经从 angular2 rc4 切换到 angular2 stable,从 typescript 1.8 切换到 2 并使用 rollupjs 模块捆绑器。

我已经根据这篇博客配置了AngularFire2 post: Getting Started with Ionic 2 RC0, Firebase 3 + AngularFire 2

我无法编译并收到此错误:

rollup: Use ofeval(in c:\XXX\node_modules\angularfire2\node_modules\firebase\firebase.js) is strongly discouraged, as it poses security risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details

有人知道发生了什么事以及如何解决这个问题吗?

从长远来看,Firebase 的解决方案是从他们的代码中删除直接 eval,因为这里实际上没有必要(它只是用于解析 JSON。JSON.parse速度快得多,现在支持基本上不是问题。

与此同时,一个可能的(尽管很老套)解决方法可能是将 eval 转换为 indirect eval(请参阅 troubleshooting note to understand the difference), using rollup-plugin-replace:

// rollup.config.js
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
// ...etc

export default {
  // ...other config...
  plugins: [
    nodeResolve({...}),
    commonjs({...}),
    replace({
      include: 'node_modules/firebase/firebase.js',
      values: {
        'eval(' : '[eval][0]('
      }
    })
  ]
};

您可以在汇总配置中禁用此警告:

// rollup.config.js

export default {
  // ...other config...
  onwarn: function (message) {
    if (/Use of `eval` \(in .*\/node_modules\/firebase\/.*\) is strongly discouraged/.test(message)) {
      return;
    }
    console.error(message);
  }
};

可以使用 rollup.config.js 来抑制警告:

export default {
    onwarn(warning, warn)
    {
        if (warning.code == 'EVAL' && /[\/]node_modules[\/]firebase[\/]/.test(warning.id)) return;

        warn(warning);
    }
};

模式 [\/] 用于捕获 Windows 和 *nix 上的路径定界符。