1

If I'm using webpack or browserify, what's the exact process to be able to import only the necessary modules from jQuery that are listed here?

import {core, dimensions} from 'jquery'

doesn't work.

Filip Petrovic
  • 837
  • 2
  • 11
  • 22
  • I've posted an answer to a very similar question: https://stackoverflow.com/questions/2733879/how-can-i-reduce-jquery/68224584#68224584 – Giorgio Tempesta Jul 02 '21 at 12:57

1 Answers1

0

You can import modules from jQuery's src directory, like so:

import core from 'jquery/src/core';
import dimensions from 'jquery/src/dimensions';

The jQuery sources use asynchronous module definitions to load modules internally (AMD), so you have to use a module bundler to use it. Webpack would be a good choice for this, it supports AMD out of the box.

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
  • My output bundle is larger when I import a couple of modules on their own, rather than when just doing import $ from 'jquery' .... – Filip Petrovic Apr 21 '18 at 23:39