2

I tried using angular-timer with webpack, es6 and the npm modules of moment and humanize-duration

My implementation would be:

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

And I get the error ReferenceError: humanizeDuration is not defined.

Sure, angular-timer needs the variable humanizeDuration and suggests in the requirements section to use bower and script src. In my understanding importing the src with webpack is the same as using it as src in a script tag.

Yves
  • 1,152
  • 1
  • 23
  • 30

1 Answers1

1

This help for me:

  1. Install moment and humanize-duration:

    $ npm install moment

    $ npm install humanize-duration

  2. Install them in your webpack.config.js as plugins:

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' })
    ]; 
  1. And import angular-timer in your component

import 'angular';
import 'angular-timer';

let yourModule = angular.module('your', [
    'timer'
]);

I hope this will help you

Ilya Shapkin
  • 21
  • 1
  • 5