A
A
Al2016-10-18 16:08:32
JavaScript
Al, 2016-10-18 16:08:32

Why are there problems loading jquery plugins that have a factory check?

I'm using typescript , modules are commonjs . Uploading files using SystemJS . I needed to screw this plugin , I did it this way:

SystemJS.config({
    "defaultJSExtensions": true,
    map: {
        css: '/js/system-css.js',
    },
    meta: {
        '*.css': { loader: 'css' }
    },
    baseURL: '/',
    paths: {
        jquery: 'js/jquery',
        scrollbar: 'js/scrollbar',
        datepicker: 'js/datepicker'
    }
});

var systemLocate = System.locate;
System.locate = function (load) {
    var System = this;
    return Promise.resolve(systemLocate.call(this, load)).then(function (address) {
        return address + System.cacheBust;
    });
};
System.cacheBust = '?id=' + CONFIG.version;
System.import('js/bootstrap.js');

Received for this:
SystemJS Multiple anonymous defines in module

The scrollbar plugin , which is connected above - works, because. in the code of the plugin itself there is no factory check as in the datepicker:
(factory) {
    if ( typeof define === 'function' && define.amd ) {
        // AMD. Register as an anonymous module.
        define(['jquery', 'jquery-mousewheel'], factory);
    } else if (typeof exports === 'object') {
        // Node/CommonJS style for Browserify
        module.exports = factory;
    } else {
        // Browser globals
        factory(jQuery);
    }
}


What should I do with this - I don’t understand, but picking out the factory check is not an option, because many plugins have it and this is normal practice.

Who came across, tell me what to do so that systemJS does not swear?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2016-10-18
@lorus

This is a module in UMD format . Angular2, for example, ships its modules in this format.
Use `map` instead of `path`:

SystemJS.config({
    "defaultJSExtensions": true,
    map: {
        css: '/js/system-css.js',
        datepicker: 'js/datepicker.js'
    },
    meta: {
        '*.css': { loader: 'css' }
    },
    baseURL: '/',
    paths: {
        jquery: 'js/jquery',
        scrollbar: 'js/scrollbar'
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question