Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a multiple file library with requireJs

I building a project with requireJs my file structure is the following:

js/
   lib/
       noty/
           layouts/
               bottom.js
               top.js
               ...
           themes/
               default.js
           noty.jquery.js
       jquery.js
       jquery-ui.js
   user/
      user.js
   app.js

And my configuration :

    requirejs.config({
        baseUrl: 'js/lib',
        urlArgs: 'bust=' + (new Date()).getTime(),  //only for dev  : no-cache
        paths: {
            user: '../user'
        },
        shim: {
            'jquery-ui': ['jquery'],
            'jquery-tmpl': ['jquery'],
            'gridy': ['jquery']
        }
    });
    requirejs(['jquery', 'jquery-ui'],  function($){
    ....
    });

My concern is about to integrate noty which is a notification plugin that I may use in any modules. This plugin requires to load :

js/lib/noty/noty.jquery.js
js/lib/noty/layout/top.js
js/lib/noty/themes/bottom.js

I'm not sure what is the way to do that?

  • Concatenate the files ?

  • Load each file as a dependency? :

    requirejs(['jquery', 'jquery-ui', 'noty/noty.jquery.js', 'noty/layout/top.js', etc. ]

  • Creates some kind of plugin/module for requireJs?

Thanks

like image 774
krampstudio Avatar asked Feb 19 '23 11:02

krampstudio


1 Answers

or like this:

paths: {
    'jquery': 'jquery/1.10.2/jquery',
    'noty': 'noty/2.0/jquery.noty',
    'noty.themes.default': 'noty/2.0/themes/default',
    'noty.layouts.topCenter': 'noty/2.0/layouts/topCenter',

    app: '../app',
    util: '../util'
},
shim: {
    'noty': ['jquery'],
    'noty.themes.default': {
        deps: ['jquery', 'noty'],
        exports: 'jquery'
    },
    'noty.layouts.topCenter': {
        deps: ['jquery', 'noty'],
        exports: 'jquery'
    }
}
like image 57
someok Avatar answered Feb 21 '23 01:02

someok