2015-12-15 15 views
2

我試圖用角定時器的WebPack,ES6和moment的NPM模塊和humanize-duration角定時器的WebPack

我的實現是:

import 'moment'; 
import 'humanize-duration'; 
import 'angular-timer'; 

而我得到的錯誤ReferenceError: humanizeDuration is not defined

當然,角度計時器需要變量humanizeDuration,並建議在requirements section中使用bower和腳本src。在我的理解中,用webpack導入src與在腳本標記中使用src相同。

+0

你是如何安裝這些庫的?通過npm? (npm是首選) – cspotcode

+0

嗨,@Yves你能解決這個問題嗎? –

回答

0

這幫助我:

  1. 安裝力矩和人性化的持續時間:

    $ npm install moment

    $ npm install humanize-duration

  2. 在webpack.config.js作爲插件安裝:

module.exports = function makeWebpackConfig() { 
 
    /** 
 
    * Config 
 
    * Reference: http://webpack.github.io/docs/configuration.html 
 
    * This is the object where all configuration gets set 
 
    */ 
 
    var config = {}; 
 
    
 
    config.plugins = [ 
 
     new webpack.ProvidePlugin({ 'moment': 'moment', 'humanizeDuration': 'humanize-duration' }) 
 
    ];

在組件
  • 和進口角定時器
  • import 'angular'; 
     
    import 'angular-timer'; 
     
    
     
    let yourModule = angular.module('your', [ 
     
        'timer' 
     
    ]);

    我希望這會幫助你