【问题标题】:Moment.js Plugins should I install both dependencies?Moment.js 插件我应该安装这两个依赖项吗?
【发布时间】:2019-04-04 06:21:40
【问题描述】:

我想使用像 moment-business-days 这样的 moment.js 插件。 我应该安装这两个依赖项吗?

npm install moment-business-days
npm install moment // yes / no / maybe?

或者安装moment.js依赖本身附带的插件就足够了吗?

有最佳实践吗?

【问题讨论】:

    标签: javascript node.js date npm momentjs


    【解决方案1】:

    这取决于,如果您想在浏览器中使用它,您必须将两者都包含在您的 HTML 文件中。

    <!-- Browser -->
    <!-- NB: add after moment.js -->
    <script src="moment.js"></script>
    <script src="moment-business-days.js"></script>
    

    在 Node.js 中使用时,您只需安装一个 moment-business-days

    const moment = require('moment-business-days');
    

    它会自动为您包含momenthttps://github.com/kalmecak/moment-business-days/blob/master/index.js#L4

    它还具有对 moment 的 peerDependency: https://github.com/kalmecak/moment-business-days/blob/master/package.json#L23

    【讨论】:

      【解决方案2】:

      moment.jsDependencies:

      benchmark,coveralls,es6-promise,grunt,grunt-benchmark,grunt-cli,grunt-contrib-clean,grunt-contrib-concat,grunt-contrib-watch31@,grunt-contrib-jshint,grunt-contrib-jshint,@987654332 ,grunt-env,grunt-exec,grunt-jscs,grunt-karma,grunt-nuget,grunt-string-replace,karma,karma-chrome-launcher,karma-firefox-launcher,karma-sauce-launcher,load-grunt-tasks,@9866 987654347@,nyc,qunit,rollup,spacejam,typescript,uglify-js

      moment-business 这是一个 Moment.js 库,允许在西方工作日进行 Moment 操作:每周 7 天,周六和周日是非工作日。

      所以你需要同时安装。

      看到这个doc

      【讨论】: