Is it possible to import only Ajax method from jQuery using Webpack?

I am working with Webpack and am trying to figure out if it is possible to import only jQuery Ajax function using name import or some other method.

After I npm install jquery --save

If I try to import only deferred, this seems to succeed:

import { Deferred} from 'jquery'; // returns the $.deferred method

but

import { Ajax } from 'jquery'; // returns undefined

Is there a named export for Deferred but not Ajax?

Thanks for any help. I'm open to any dummy on npm but don't want to use a gazebo. I haven't needed it yet and would rather just import the entire jQuery library using NPM rather than do it all in one module.

+3


source to share


1 answer


It looks like you might just require certain features. This blog post shows you how.

The good news is that since jQuery 2.1 jQuery has been using AMD to organize its dependencies internally. This means that you can use AMD to load individual parts of jQuery rather than the entire library.

Bower is very simple - much the same as NPM, but for the browser, not the server. And you see it all over the place, I'm sure you can get some functionality. You just use the command line to install your files instead of downloading and linking.



I would go for native XHR material. Its easier than people do it. Check this link for some comparison between jQuery and native ajax.

jQuery is very handy, but I feel like it should be an alternative to making things native, not the other way around.

+1


source







All Articles