【问题标题】:angular-timer with webpack带有 webpack 的角度计时器
【发布时间】:2016-03-21 02:30:45
【问题描述】:

我尝试将 angular-timer 与 webpack、es6 以及 momenthumanize-duration 的 npm 模块一起使用

我的实现是:

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

我收到错误ReferenceError: humanizeDuration is not defined

当然,angular-timer 需要变量 humanizeDuration 并在 requirements section 中建议使用 bower 和 script src。在我的理解中,使用 webpack 导入 src 与在脚本标签中使用它作为 src 相同。

【问题讨论】:

  • 您是如何安装这些库的?通过 npm? (首选 npm)
  • 嗨,@Yves 你能解决这个问题吗?

标签: angularjs ecmascript-6 webpack angular-timer


【解决方案1】:

这对我有帮助:

  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' })
    ]; 
  1. 并在您的组件中导入 angular-timer

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

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

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多