Skip to content

NPM Module: CommonJS support #450

@antoniobrandao

Description

@antoniobrandao

Hello,

I fetched jquery.form from NPM and noticed it isn't compatible with the CommonJS format.

I managed to make it work here by changing this:

// AMD support
(function (factory) {
    "use strict";
    if (typeof define === 'function' && define.amd) {
        // using AMD; register as anon module
        define(['jquery'], factory);
    } else {
        // no AMD; invoke directly
        factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto );
    }
}

To this:

// AMD and CommonJS support
(function (factory) {
    "use strict";
    if (typeof module !== 'undefined' && module.exports) {
        module.exports = factory;
    } else if (typeof define === 'function' && define.amd) {
        // using AMD; register as anon module
        define(['jquery'], factory);
    } else {
        // no AMD; invoke directly
        factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto );
    }
}

(Attempting to implement UMD format https://github.com/umdjs/umd)

This is unlikely to be sufficient but it is working for me. But I have to keep a separated copy of the file.

Would be great if this transition to the UMD format would exist, then it would fit perfectly into the NPM ecossystem, and allow us to use Browserify with it.

Thanks

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