Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequireJS / AMD Support #75

Open
dshastry opened this issue Aug 23, 2019 · 2 comments
Open

RequireJS / AMD Support #75

dshastry opened this issue Aug 23, 2019 · 2 comments

Comments

@dshastry
Copy link

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?

@mcdado
Copy link
Collaborator

mcdado commented Aug 30, 2019

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

@ntoombs19
Copy link

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']
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants