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

Treat jQuery & Tether as dependencies in ES6 source code #17201

Closed
skrivle opened this issue Aug 21, 2015 · 28 comments
Closed

Treat jQuery & Tether as dependencies in ES6 source code #17201

skrivle opened this issue Aug 21, 2015 · 28 comments
Labels

Comments

@skrivle
Copy link

skrivle commented Aug 21, 2015

First of all, congrats on the v4 release guys. Looking really nice! I'm especially excited about the new ES6 source code. However, when scanning the source code I noticed that jQuery isn't imported like the other dependencies. Because of this jQuery is also missing in the UMD definitions that are generated via grunt. This causes the UMD modules to be more or less unusable unless you include jQuery globally.

I guess the reason for this is that it's probably difficult to guess how people are going to import jQuery. Import paths and package names may differ between package managers, etc ...

However, since jQuery is the only external dependency here, I think it should be possible. For example you could ask people using requirejs to define a custom path, which they are probably doing already ...

On npm the package for jQuery is 'jquery', so this shouldn't cause any issues. Then the only remaining problem is that babel is converting this:

import $ from 'jquery'

to

factory(mod.exports, mod, global.$);

Which probably will work, but it is kind of risky to use '$' instead of jQuery I guess ... Maybe there is way to hook into babel's compiling step and change module names there ...

Adding jQuery as a dependency will also enable people who are already writing ES6 code to actually import the ES6 code ...

I may be missing a lot of stuff here, so any feedback is more than welcome!

@zacechola
Copy link

FWIW Ember handles this by importing jQuery by default while allowing authors to toggle that default off.

@skrivle
Copy link
Author

skrivle commented Aug 21, 2015

I think the simplest solution would be to just import jQuery as jQuery and then map $ to jQuery. This way you'll get a clean UMD definition, which is usable with bower or npm and requirejs, commonjs or globals ...

import jQuery from 'jquery'

const $ = jQuery

assuming requirejs users create a custom path for 'jquery' ...

@hnrch02
Copy link
Collaborator

hnrch02 commented Aug 21, 2015

CC @fat

@skrivle
Copy link
Author

skrivle commented Aug 24, 2015

Small update:

I was able to get it working just by adding import jQuery as jQuery to every JS file. If you're ok with it, I would suggest to run the unit tests directly on the UMD builds ... I see no need to compile a version without UMD definitions anymore ...

One thing I noticed though while testing this locally, is that there are some additional issues regarding the UMD builds ... I've created a separate issue for this.

Once I fixed these 2 problems I was able to successfully run unit tests against the UMD builds. If you want I can come up with a pull request.

@krnlde
Copy link
Contributor

krnlde commented Aug 24, 2015

@vejersele

import jQuery as $ from 'jquery'

@skrivle
Copy link
Author

skrivle commented Aug 24, 2015

@krnlde That doesn't work ...

import {jQuery as $} from 'jquery'

This does work, but leaves us with the same issue as we had in the first place since it's compiling to global.jquery while we actually want global.jQuery.

@krnlde
Copy link
Contributor

krnlde commented Aug 24, 2015

What about import * as $ from jQuery

@skrivle
Copy link
Author

skrivle commented Aug 24, 2015

I assume you mean import * as $ from 'jQuery' which compiles to global.$ ... Also, it will use require('jQuery') in a node environment, while I don't think require() is case sensitive (at least on a OSX it isn't) it seems like a dangerous guess.

@krnlde
Copy link
Contributor

krnlde commented Aug 24, 2015

Sorry for the errors, I answered from my mobile, which autocorrect, and I correctly assumed you'd guess the correct. This aside, const $ = jQuery doesn't look like a good practice to me.

@skrivle
Copy link
Author

skrivle commented Aug 24, 2015

I'm aware that this isn't the cleanest solution, but at least it works ... I only see two options, either use const $ = jQuery or wrapping the component code within an IIFE with $ as a param (how it's already done right now), which is essentially the same.

@krnlde
Copy link
Contributor

krnlde commented Aug 24, 2015

I don't know enough about destructuring, but this could work also, if you can use the same key twice: import {jQuery as $, jQuery} from 'jquery'

@skrivle
Copy link
Author

skrivle commented Aug 24, 2015

Not sure if I need to create another issue for this, but I also think we should specify jQuery and Tether as dependencies in the package.json and bower.json files ...

@zacechola
Copy link

@vejersele Doesn't hurt. Just x-ref the issue numbers as they're all related anyway.

@fat
Copy link
Member

fat commented Nov 15, 2015

@vejersele if you havne't already, a pr would be rad

@skrivle
Copy link
Author

skrivle commented Nov 25, 2015

Once #18313 is merged I'll put together a pull request.

@cvrebert cvrebert changed the title Treat jQuery as a dependency in ES6 source code Treat jQuery & Tether as dependencies in ES6 source code Dec 23, 2015
@krnlde
Copy link
Contributor

krnlde commented May 17, 2016

There is a "+1"-reaction now, please use this instead.

@DaSchTour
Copy link
Contributor

But the +1 reaction doesn't add you as a participant ;)

@krnlde
Copy link
Contributor

krnlde commented May 17, 2016

So you want to say bombing this thread is better than doing a second click on the subscribe button? Give that man a burrito.

@DaSchTour
Copy link
Contributor

Subscribe isn't the same as participate ;)

@krnlde
Copy link
Contributor

krnlde commented May 17, 2016

But apparently trolling is.

@DaSchTour
Copy link
Contributor

You think that's a joke? Just click on the watch/unwatch button and you will see what I mean ;)

@mdo
Copy link
Member

mdo commented Jan 8, 2017

According to the comment in #20745, I think #19541 took care of this. Correct me if I'm wrong though!

@mdo mdo closed this as completed Jan 8, 2017
@bardiharborow
Copy link
Member

#20745 was replaced by #19541, but neither completely fix this issue. We need to work out how we are going to manage all this, especially given that native module support in Chrome isn't too far off.

@bardiharborow bardiharborow reopened this Jan 21, 2017
@karolyi
Copy link

karolyi commented Jan 21, 2017

Well, injecting tether with webpack works this way, but when you use require('Tether') and webpack is configured correctly, it will import tether for itself.

I don't know anything about chrome native module support, but since it doesn't exist yet, you have to transpile TWBS's modules anyway, and that solves the problem.

or did I miss anything?

@mdo mdo removed the has-pr label Mar 26, 2017
@gijsbotje
Copy link
Contributor

issue can be closed right? #22444

@karolyi
Copy link

karolyi commented Jul 17, 2017

hey, thanks for the heads up for this, changing to Popper was news to me, however I welcome it. I had problems here and there with tether, and looking forward replacing it with the next alpha release.

as for this issue, yes it should be closed.

@Johann-S
Copy link
Member

Hmm I don't think we should close this issue because we should treat jQuery and (now) Popper.js as dependencies and it will be done here #22888

@Johann-S
Copy link
Member

Closed thanks to #23735

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