Skip to content

jQuery's AMDness and require() #1066

@IngwiePhoenix

Description

@IngwiePhoenix

While tracing down some biggies within my pack, I realized that jQuery is about 200kb. Ouch.

So in order to attempt to slim it down, I began to read into its source code, and it turned out that jQuery was using AMD style declaration. But when I tried to do the following, it didn't work at all!

define([
    "jquery.js/core",
    "jquery.js/sizzle/dist/sizzle",
    "jquery.js/event",
    "jquery.js/event/alias",
    "jquery.js/traversing",
    "jquery.js/callbacks",
    "jquery.js/deferred",
    "jquery.js/core/ready",
    "jquery.js/data",
    "jquery.js/queue",
    "jquery.js/queue/delay",
    "jquery.js/attributes",
    "jquery.js/manipulation",
    "jquery.js/manipulation/_evalUrl",
    "jquery.js/wrap",
    "jquery.js/css",
    "jquery.js/css/hiddenVisibleSelectors",
    "jquery.js/serialize",
    "jquery.js/ajax",
    "jquery.js/ajax/xhr",
    "jquery.js/ajax/script",
    "jquery.js/ajax/jsonp",
    "jquery.js/ajax/load",
    "jquery.js/event/ajax",
    "jquery.js/effects",
    "jquery.js/effects/animatedSelector",
    "jquery.js/offset",
    "jquery.js/dimensions",
    "jquery.js/deprecated"
], function( jQuery, Sizzle ) {

// Hotfix Sizzle
jQuery.find = Sizzle;
jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.pseudos;
jQuery.unique = Sizzle.uniqueSort;
jQuery.text = Sizzle.getText;
jQuery.isXMLDoc = Sizzle.isXML;
jQuery.contains = Sizzle.contains;

return jQuery;

});

jquery.js is essentially an alias to bower_components/jquery/src. When I load that in the browser, I get a variety of odd errors.

What is the best way to use an AMD module via require()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions