使用 Firebase 设置 Polymer 以进行生产

Setting up the Polymer with Firebase for production

我在项目中使用 Polymerfire 库和原生 javascript API,我需要设置生产环境。我搜索了多个帖子(例如 ),得出的结论是我需要创建一个单独的项目。但是,由于我使用的是 Polymerfire 库,所以我在整个项目中都指定了我的应用程序名称。

<firebase-auth id="auth" user="{{user}}" app-name="project-name" provider="password"
               signed-in="{{signedIn}}"></firebase-auth>

要在生产中部署,需要在所有地方更改此名称。我在想我可以创建一个 computeAppName 函数,它会根据环境 return 应用程序名称,但我希望有更好的解决方案。

当我使用原生 javascript API 时不会出现同样的问题,因为我只是选择数组中的第一个应用程序(我永远不会在我的项目中使用多个应用程序) .

例子

            var actionCode = this.route.__queryParams["oobCode"],
                auth = firebase.apps[0].auth();

在我看来,理想情况下,Polymerfire 库会自动选择 firebase.apps 数组中唯一存在的应用程序。如果是这种情况,我可以在 index.html 中使用应用程序名称初始化一个 firebase-app 元素,并在 DOM 树的更深处保留未指定的应用程序名称。

如果我完全停止使用 Polymerfire 库,这个问题将被消除,但这不会遵循 "Polymer way" 做事。

另一种选择是在构建系统(如 gulp)中创建一个任务来替换生产环境中的应用程序名称,但这可能过于复杂。

你怎么看?

编辑: 现在我正在使用一个解决方法:

index.html 中的 firebase-app 元素:

<firebase-app id="main_app"
              name="project-id"
              api-key="key"
              auth-domain="project-id.firebaseapp.com"
              database-url="https://project-id.firebaseio.com"
              storage-bucket="project-id.appspot.com">
</firebase-app>

在每个使用 Polymerfire 的元素中,我创建了一个 appName 属性,它使用文档选择器从索引中的元素获取应用程序名称:

        appName: {
            type: String,
            value: function () {
                return document.getElementById("main_app").name;
            }
        }

<firebase-auth id="auth" user="{{user}}" app-name="[[appName]]" provider="password"
               signed-in="{{signedIn}}"></firebase-auth>

谢谢简

firebase-app元素的名称属性仅作为firebase app对象的名称,可以随意,切换到生产项目时无需更改。