ganlanyuan / tiny-slider

Vanilla javascript slider for all purposes.
MIT License
5.23k stars 785 forks source link

Compatibility with requirejs #355

Open pierrehenri220 opened 5 years ago

pierrehenri220 commented 5 years ago

Good Day,

I'm currently adding the following code at the end of tiny-slider.min.js to make it work with requirejs:

// For requirejs
define(function(){
    return tns;
});

Then in my main script I'm using it like this:

requirejs.config({
    baseUrl: 'js',
    paths: {
        _: 'lodash-full.min',
        tns: 'tiny-slider.min',
        SmoothScroll: 'smooth-scroll.polyfills.min'
    }
});
requirejs(["_","tns","SmoothScroll"], function(_, tns, SmoothScroll) {
    ...
});

But that would be great if you can add the standard AMD loading code in the script itself to make it compatible by default :-)

Not in a hurry, thank you very much in advance and thank you for your time

Regards

hirbod commented 4 years ago

Yeah @ganlanyuan would be nice to support AMD by default

censys-git commented 4 years ago

So agree. Beautiful slider, but doesn't play well with module definitions. Rather than put tns in the global space, simple UMD wrapper would solve the issue and not break any current implementation.

(function(root, factory) { //figure out the environment... if ( typeof define === 'function' && define.amd ) { //1. amd -- I prefer it be named versus anonymous but either works define([], factory); } else if ( typeof exports === 'object' ) { //2. module.exports module.exports = factory.call(root); } else { //3. browser or global space root.tns = factory.call(root); } }(this, function() { // original code here except replace "var tns = " with "return " }));

sunixzs commented 4 years ago

Would be great - push :-)