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

Add commonjs support #1451

Merged
merged 1 commit into from Jun 26, 2015
Merged

Add commonjs support #1451

merged 1 commit into from Jun 26, 2015

Conversation

zaynetro
Copy link
Contributor

No description provided.

@vsn4ik
Copy link
Member

vsn4ik commented Jun 25, 2015

👍 for merge.

@acrobat
Copy link
Member

acrobat commented Jun 26, 2015

Thanks @zaynetro!

acrobat added a commit that referenced this pull request Jun 26, 2015
@acrobat acrobat merged commit 7bd535d into uxsolutions:master Jun 26, 2015
@acrobat acrobat added this to the 1.5.0 milestone Jun 26, 2015
@acrobat acrobat mentioned this pull request Jun 26, 2015
2 tasks
@vshulev
Copy link

vshulev commented Dec 4, 2015

Hi,
I'm trying to use bootstrap-datepicker with browserify. I get a $(...).datepicker is not a function error. At the top of my file I have:

var $ = require('jquery');
require('bootstrap-datepicker');

Is this the proper way to use it?

@vsn4ik
Copy link
Member

vsn4ik commented Dec 5, 2015

@vshulev use require('bootstrap-datepicker')($);.

@vshulev
Copy link

vshulev commented Dec 5, 2015

@vsn4ik, thanks for the reply! This also doesn't seem to work (tried it and got an error). The issue seems to be that nothing is added to module.exports and therefore require returns just an empty object. I've created a PR for this - #1703, after the changes the syntax you are proposing - require('bootstrap-datepicker')($); works fine.

@zaynetro
Copy link
Contributor Author

zaynetro commented Dec 6, 2015

Could you provide an example when this breaks? I use bootstrap date picker in production and it does work with browserify. Perhaps there might be different between versions in how jquery/npm/browserify manage modules.

@vshulev
Copy link

vshulev commented Dec 6, 2015

I'm using the bootstrap datepicker inside an Angular directive (not sure whether this makes any difference). These are the top 3 lines in my directive file:

var moment = require('moment');
var $ = require('jquery');
require('bootstrap-datepicker');

I also tried require('bootstrap-datepicker')($) - doesn't work either. The datepicker plugin doesn't get attached to jQuery, and so I get an element is undefined error when I try to initialize an element. This is the code for initializing the datepicker:

$(elem).datepicker({
        format: 'dd/mm/yyyy',
        startDate: '-3d',
        autoclose: true,
        startDate: '-100y',
        endDate: '0d',
        startView: scope.startView,
        forceParse: false
});

It used to work before I ported the code to browserify. I'm using the following versions:

  • browserify 12.0.1
  • bootstrap-datepicker 1.5.0
  • jQuery 2.1.4

@zaynetro
Copy link
Contributor Author

zaynetro commented Dec 6, 2015

@vshulev, take a look at this gist https://gist.github.com/zaynetro/b575f0dc428bbbf9c810 . Example there works with out any troubles.

@vshulev
Copy link

vshulev commented Dec 6, 2015

@zaynetro, you're absolutely right! Tried your example, then tried the same thing I was trying yesterday and now it works without a problem... Not quite sure what the issue was, but closing the PR. Thanks for the gist!

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

Successfully merging this pull request may close these issues.

None yet

4 participants