New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure paths by pattern or module name rewriter? #250
Comments
Hey @mk-pmb, This is a fun problem. First, I have to ask if there's an easier solution: how hard would it be to refactor these modules so they use normal CommonJS/AMD module ids? For instance, use "phorkys/scenetype/landscape" instead of "phorkys-scenetype-landscape"? Replacing I think the best way to resolve this is with a shim (like the dojo18 shim above) or a loader (such as these. First, you'll have to decide if the transformation is an id transform or a url transform. There's a subtle difference:
I'm guessing you need a path transform. A loader can be applied to an entire package, but it has to handle every module in that package. You cannot handle some with the loader (e.g. you can't remap the path of some modules) and not others. A shim overrides some internal function of curl. These are much more flexible, but rely on internals so you'll want to take note during major version changes. Any ideas, thoughts? -- John |
Hi John, thanks for the quick reply. Refactoring will be possible, but must remain compatible to browserify and nodejs. ( Since the path config works and I'm not sure about possible side effects of id transforms, I tend to agree on path transform being the best choice. Do I understand correctly that
means I'd have to move all of phorkys' dependencies into Yours, MK Edit: While we're at it, currently all the phorkys modules have a wrapper in them to detect whether they are loaded from AMD or nodejs, because I failed to configure legacy mode for them. (Probably would have worked with "js!" in front of every module name inside, but that would break node.) With an extra loader, could I enable this legacy mode to save those redundant wrappers in each module? Does legacy mode come at a cost? |
Checked again, nodejs compatibility is already available the other way around, using RequireJS in node. Browserify compatibility should probably be reduced to making browserify work with node's RequireJS if not yet. The remaining compatibility problems seem to be only about future npm publishing, which I'm not yet used to. |
Hey @mk-pmb, I'm getting pretty confused by this conversation. :P I'm not sure I'm on the right path, but here's an attempt at a recommendation/solution...
UMD boilerplate: // boilerplate starts with an IIFE...
(function (define) {
define(function (require, exports, module) {
// inside here is where your code goes. it should be commonjs format
var dep = require('phorkys/core/foo');
module.exports = function bar (val) {
return dep(val);
};
// more boilerplate below...
});
}(typeof define == 'function' && define.amd ? define : function (factory) { module.exports = factory(require, module, exports); })); I hope this helps? -- John |
Thanks for the overview and suggestions! I'll see how far I get with these, probably starting with the cjsm11 loader, and ask again when I find a wall in front of me. I'll try and stay with just npm until I discover its limits. The modules are very fine-grained because there are quite some many types of scenes, furniture, transportation and so on, and I only need a few of those categories in most projects. (For example, I haven't yet had chariots and jetpacks together.) Yours, MK |
Cool. I'm going to close this issue. Feel free to continue to comment on it. If you'd like to start a lengthy discussion, you could also try the #cujojs freenode channel or our google group. |
Hi, thanks for curl! (and
when
, too.)Could there be a way to rewrite module names or configure paths by a function? I'm looking for a pattern matching (here: every module name that starts with "phorkys-") mass solution to replace the long list:
My first idea was to replace
require()
with a proxy that does regexp replace on the module name and then passes it on to the originalrequire()
, but then I realized that it is probably not used as a real function but rather a macro. So where could I hook into, or what would be a better way to give a pattern instead of a long list?Yours, MK
Edit: API might be something like
The text was updated successfully, but these errors were encountered: