0
votes

I'm attempting to use LeafletJS with requireJS and some LeafletJS plugins. I know that if you are using files that aren't AMD modules, you need to shim them in the config. Does this mean I will have to shim each individual plugin with the LeafletJS dependency? Ex:

require.config({
    paths: {
        'leaflet':         'vendor/leaflet/leafletjs',
        'leafletplugin1':         'vendor/leaflet/leafletplugin1',
        'leafletplugin2':         'vendor/leaflet/leafletplugin2'
    },
    shim: {
        'leafletplugin1': {
            deps: 'leaflet'
        },
        'leafletplugin2': {
            deps: 'leaflet'
        }
    }
});

The problem is that I plan to have many libraries with many plugins, and this config will get extremely long since I have to not only shim each individual plugin but also provide a path for each. Is there a simpler way to do this? It would be nice if I could even define a require.config inside of a module for use only with that module, that way I could keep my project better organized and less cluttered.

Also, there is no other way to simply require(['leafletplugin1'], function(){}); without shimming it, correct?

EDIT: Just to clarify, this doesn't have to be a LeafletJS-specific question/answer. This is just the current example I'm working with.

1

1 Answers

0
votes

Option 1: depending on your build process and..

  • Number of plugs
  • Total size of plugins

would be concat all of the 'leaf' plugins into a single file.

Option 2: Turn all the plugins into proper modules.

This would mean having a ~/leaf directory and a ~/leafModule directory and having the build process "wrap" each plugin into a proper module.

In a similar situation, I did option 2. Was fairly easy and made the rest of my code far easier to work on.