Using wildcards into shim configs so deps (eg. JQuery plugins) can be distributed in folders as namespaces #608

Closed
eberhm opened this Issue Jan 22, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@eberhm

eberhm commented Jan 22, 2013

I do not know whether there is actually a way to do this but I'm trying to move to AMD our framework at work and now the only problem as usual is the non AMD third party libraries/plugins. I know I can use shim in my config file but it seems to me really verbose when it comes to add all the different plugins we make use of (about 50). I'd really love to see something like this:

require.config({
    shim: {
        'jquery/*' : ['jquery']
    }
});

in case of multiple matching, I'd simply would get the first dependency matching:

require.config({
    shim: {
        'jquery/bootstrap/*': ['bootstrap'],
        'jquery/*' : ['jquery']
    }
});

//so when requiring
require(['jquery/backbone/myPlugin'], function() {
   //I can use my plugin here since jquery.js and bootstrap has been loaded first
});
@jrburke

This comment has been minimized.

Show comment
Hide comment
@jrburke

jrburke Jan 24, 2013

Member

There are no plans to provide this at this time. This has implications on how module IDs are expressed in config that I do not think is worth the complication, particularly for shim, which is a stop-gap method to getting to more expressive, modules with explicit dependencies.

So closing this, but feel free to continue discussion in the ticket.

Member

jrburke commented Jan 24, 2013

There are no plans to provide this at this time. This has implications on how module IDs are expressed in config that I do not think is worth the complication, particularly for shim, which is a stop-gap method to getting to more expressive, modules with explicit dependencies.

So closing this, but feel free to continue discussion in the ticket.

@jrburke jrburke closed this Jan 24, 2013

@eberhm

This comment has been minimized.

Show comment
Hide comment
@eberhm

eberhm Jan 24, 2013

Hi!,

I was only thinking of wildcards for shims, not regular AMD deps. This I think would ease the transition to requirejs since once your project has grown, you probably has a considerable amount of plugins (mostly jquery). In fact I've already have implemented the change and thought of PR it to you. If you think it won't worth it though, I guess I can always work it out through a plugin (What's your take on this?) but, in any case I'd love you to take a look at the implementation since I think it does not compromise performance (well, just a little...but really, a little) neither complicates the API at all. Please take a look at the tests I've added for shim. (tests/shim/basic-tests.js). I'll try to submit the PR today during the day. Thanks in advance!

eberhm commented Jan 24, 2013

Hi!,

I was only thinking of wildcards for shims, not regular AMD deps. This I think would ease the transition to requirejs since once your project has grown, you probably has a considerable amount of plugins (mostly jquery). In fact I've already have implemented the change and thought of PR it to you. If you think it won't worth it though, I guess I can always work it out through a plugin (What's your take on this?) but, in any case I'd love you to take a look at the implementation since I think it does not compromise performance (well, just a little...but really, a little) neither complicates the API at all. Please take a look at the tests I've added for shim. (tests/shim/basic-tests.js). I'll try to submit the PR today during the day. Thanks in advance!

@jrburke

This comment has been minimized.

Show comment
Hide comment
@jrburke

jrburke Jan 24, 2013

Member

I can see where you could just make a "jq!" plugin that would do this for you, where its load method would be:

{
  load: function (id, require, load, config) {
      require(['jquery'], function ($) {
        require([id], function () {
          load($);
        });
      });
  }
}

Then when referencing the plugins:

define(['jq!plugin1', 'jq!plugin2'], function ($) {
});

My concerns about API are introducing a "*" in config. This will lead to other questions about supporting * in other config values, which would not be appropriate. I really would need to see more demand for it to justify the complication. Even then, the implementation has to stop somewhere. There are ways to get what you are looking for (the above loader plugin an example), so I prefer to use those existing channels.

Member

jrburke commented Jan 24, 2013

I can see where you could just make a "jq!" plugin that would do this for you, where its load method would be:

{
  load: function (id, require, load, config) {
      require(['jquery'], function ($) {
        require([id], function () {
          load($);
        });
      });
  }
}

Then when referencing the plugins:

define(['jq!plugin1', 'jq!plugin2'], function ($) {
});

My concerns about API are introducing a "*" in config. This will lead to other questions about supporting * in other config values, which would not be appropriate. I really would need to see more demand for it to justify the complication. Even then, the implementation has to stop somewhere. There are ways to get what you are looking for (the above loader plugin an example), so I prefer to use those existing channels.

eberhm added a commit to eberhm/requirejs that referenced this issue Jan 24, 2013

Issue #608 Using wildcards into shim configs so deps (eg. JQuery plug…
…ins) can be distributed in folders as namespaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment