2016-09-18 80 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創建的項目中),我很想知道。 –