strues / retinajs

JavaScript, SCSS, Sass, Less, and Stylus helpers for rendering high-resolution image variants
http://retinajs.com
MIT License
4.42k stars 611 forks source link

retinajs should not be defining "exports" if it isn't available #277

Closed niedfelj closed 7 years ago

niedfelj commented 7 years ago

A lot of scripts determine what environment they are running in based on whether exports is defined as an "object". If retinajs is running on a site and defines the exports object, other scripts think they are running in a node environment...example:

JS Cookies Line 14 https://github.com/js-cookie/js-cookie/blob/master/src/js.cookie.js

retinajs should use a similar factory/loading mechanism in retina.min.js so that it attaches retinajs where it's needed on the globa/root/window without defining exports

;(function (factory) {
    var registeredInModuleLoader = false;
    if (typeof define === 'function' && define.amd) {
        define(factory);
        registeredInModuleLoader = true;
    }
    if (typeof exports === 'object') {
        module.exports = factory();
        registeredInModuleLoader = true;
    }
    if (!registeredInModuleLoader) {
        var OldCookies = window.Cookies;
        var api = window.Cookies = factory();
        api.noConflict = function () {
            window.Cookies = OldCookies;
            return api;
        };
    }
}(function () {