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

Importing using ES6 but jQuery is loaded externally #132

Closed
dobromir-hristov opened this issue Dec 6, 2016 · 7 comments
Closed

Importing using ES6 but jQuery is loaded externally #132

dobromir-hristov opened this issue Dec 6, 2016 · 7 comments
Labels

Comments

@dobromir-hristov
Copy link

Ok so my situation is a bit sticky. I am developing a WordPress theme for a client, but I am using ES6 with Babel and Browserify for my custom code. Problem is I cant just deregister jQuery because the majority of WP plugins require it.
So in every ES6 module I just const $ = window.jQuery (because I just couldn't make browserify shim to work properly).
But now when I import 'jquery-circle-progress' I jsut get that circleProgress is not a function of jQuery. Any suggestions how I should proceed ?
At this point I just added the whole plugin into my Libraries JS stack, and its available everywhere, but that's not cool.

@kottenator
Copy link
Owner

Seems like a bug. I'll take a closer look.

@kottenator kottenator added the bug label Dec 9, 2016
@andreiglingeanu
Copy link
Contributor

@dobromir-hristov I fixed that problem by marking jquery module as a global variable that comes from window.jQuery, like that. I am using webpack, though. I bet browserify have such an option too.

@andreiglingeanu
Copy link
Contributor

@kottenator And I'm having no problem with jquery-circle-progress picking up window.jQuery, as long as you indicate webpack that jquery module refers to window.jQuery variable. No one even cares about the source of jquery module.

@andreiglingeanu
Copy link
Contributor

I bet browserify have such an option too.

Confirmed.

@kottenator
Copy link
Owner

kottenator commented Dec 18, 2016

@andreiglingeanu - I think I've found a bug in the UMD template I'm using (this line should assign a value, not a function). I'll take care.

@kottenator
Copy link
Owner

kottenator commented Jan 9, 2017

So, after investigation, it's not a UMD bug but rather UMD specific decision.

They decided to export a factory function, not jQuery. The function needs to be called to initialiaze the plugin:

import jcp from 'jquery-circle-progress';
jcp();

I find this decision too complicated, so I've updated the UMD code. Now this will work (as expected):

import 'jquery-circle-progress';
// that's it, plugin is initiated using `$ = require('jquery')`

I'm releasing version 1.2.1 now.

@kottenator
Copy link
Owner

kottenator commented Jan 9, 2017

[email protected] released.

Now few words about browserify-shim configuration: see my gist.

I believe the bug is fixed. I'm closing this ticket. @dobromir-hristov - please, check if everything works now. Feel free to reopen this ticket.

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

No branches or pull requests

3 participants