2016-09-18 84 views
0

当使用奥里利亚-CLI,在新取得的项目,我想用下面的代码,包括在我的包火力点:无法出口到全球火力

{ 
    "name": "firebase", 
    "path": "../node_modules/firebase", 
    "main":"firebase", 
    "exports": "firebase" 
    } 

根据他们的文档,这应该使火力全球可用在我的应用程序(类似于jQuery的$)。

这是什么原因导致这不起作用?

+2

是否包含其下的依赖和使用'进口火力想使用Firebase? –

+0

嗨@RobinsonCollado,该方法的工作原理,但有什么办法可以在全球范围内使用我的火力点? –

回答

2

在你main.js,请尝试以下操作:

import firebase from 'firebase'; 

export function configure(aurelia) { 

    ... 

    firebase.initializeApp({ 
    apiKey: 'your_api_key', 
    authDomain: 'your_auth_domain', 
    databaseURL: 'your_database_url', 
    storageBucket: 'your_storage_bucket' 
    }); 

    aurelia.start().then(() => aurelia.setRoot()); 
} 

在app.js:从“firebase'`无论你

// Import firebase if the project was created using the Aurelia-CLI 
// If you're using the Aurelia Esnext-Skeleton, you don't have to import firebase 
import firebase from 'firebase'; 

export class App { 
    constructor() { 
    this.some_ref = firebase.database().ref('some_path'); 
    } 
} 
+0

恐怕这是行不通的。我完全像你说的,在main.js中导入了firebase,然后初始化它。之后在app.js构造函数中,我做了一个console.log(firebase);我得到了一个错误,那就是firebase是未定义的! –

+0

你是对的!我更新了我的答案。 Firebase没有像您想要的那样全球化,但它应该可以让您启动并运行Firebase。如果您了解如何在全球范围内使用Firebase(在使用aurelia-cli创建的项目中),我很想知道。 –