moment-business-days icon indicating copy to clipboard operation
moment-business-days copied to clipboard

RequireJS / AMD Support

Open dshastry opened this issue 5 years ago • 2 comments

Thanks for writing a great plugin that's been super helpful so far. One issue I just ran into is that the plugin does not work when used in a require JS / AMD environment. Below is the require block in require_config:

define('moment',['moment/2.24.0/moment.min', 'moment/plugins/business-days/plugin'],function (moment) { window.moment = moment; return moment; });

I get a moment is not defined error. If I throw in a require call or a timer that waits for the moment variable in the plugin file it all works. Would it be possible to add amd support to the code?

dshastry avatar Aug 23 '19 05:08 dshastry

Is there any resource on how to develop a proper module, especially a moment plugin? This plugin was developed by @kalmecak a while ago i think, back then there weren't well defined formats I think. On a personal level I would be quite interested in this specification

mcdado avatar Aug 30 '19 09:08 mcdado

You can just add a shim to your requirejs config. This solution assumes you already have momentjs added as an AMD module. If you don't you'll need to add a path for it to your requirejs config.

config = {
    paths: {
        "moment-business-days": "path/to/moment-business-days/index"
    },
    // Add moment-business-days methods to moment.js (https://github.com/kalmecak/moment-business-days)
    shim: {
        "moment-business-days": ['moment']
    }
}

ntoombs19 avatar Jul 02 '20 16:07 ntoombs19