2014-01-29 43 views
10

我在嘗試遷移一個應用程序應用程序以使用ember app-kit。該代碼需要accounting.js庫。在預應用-KIT版本的文件是在index.html如何作爲ES6模塊訪問涼亭軟件包?

<script src="http://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.3.2/accounting.min.js"></script> 

通過腳本標籤加載並在視圖訪問通過全局命名空間

App.MoneyField= Em.TextField.extend({ 
    init: function() { 
    this._super(); 
    var value = accounting.formatMoney(this.get("money")/100, ''); 
    this.set('value', value); 
    }; 
    // other functions omitted 
}); 

在App-套件版本,我ve包括accounting.js作爲涼亭依賴。在bower.json

{ 
    "name": "ember-app-kit", 
    "dependencies": { 
    "handlebars": "~1.1.2", 
    "jquery": "~1.9.1", 
    "qunit": "~1.12.0", 
    "ember": "~1.4.0-beta.2", 
    "ember-data": "~1.0.0-beta.6", 
    "ember-resolver": "git://github.com/stefanpenner/ember-jj-abrams-resolver.git#master", 
    "ic-ajax": "~0.3.0", 
    "ember-testing-httpRespond": "~0.1.1", 
    "accounting":"~0.3.2" 
    }, 
    "resolutions": { 
    "ember": "~1.4.0-beta.2" 
    } 
} 

當我嘗試建立的應用程序,它提供了錯誤

W117: 'accounting' is not defined. 

我明白這是爲什麼,知道我需要某種import accounting from ...聲明。

如何導入通過bower安裝的軟件包作爲ES6模塊?

+0

我猜'從'/供應商/會計/會計'進口會計;'。但是我試了一下,得到了以下錯誤:'未捕獲的錯誤:找不到模塊/供應商/會計/會計資料來源:'http:// localhost:8000/vendor/loader.js:21''。有了requirejs,我會添加一個墊片到配置文件,可惜我不知道如何使用EAK來完成。 –

+0

顯然有一些東西在不久的將來:http://emberjs.com/blog/2013/12/17/whats-coming-in-ember-in-2014.html'ember-cli'能夠使墊片。 –

+0

我爲此功能創建了一個問題:https://github.com/stefanpenner/ember-app-kit/issues/511 –

回答

1

我知道,這是幾個月前問,但自那時以來,恩貝爾應用套件已被ember-cli得手,這提供了一個非常簡單的手段,來訪問涼亭或NPM的依賴。

至於作爲ES6模塊被訪問:

  • 非AMD的資產不能作爲ES6模塊進行訪問,您只需通過訪問它們全球變量,他們出口。
    • 例如moment
  • AMD資產,在另一方面,可以通過ES6 import語法
    • 例如訪問import { raw as icAjaxRaw } from 'ic-ajax';

值得一提的還有,那燼,CLI支持的附加系統,現在,它可以使進口這些東西那麼簡單,將它們添加到您的項目的package.json。一些比較流行的圖書館已經爲它們添加了燼詞。 This post描述你如何寫你自己的。

+0

兩個鏈接不再存在。 – shredding