Conversation
lddubeau
left a comment
There was a problem hiding this comment.
Your configuration does not do what you think it does. shim is only for code that does not call define. If the module for which you define a shim calls define then the shim is ignored.
That rangy-selectionsaverestore refers to "./rangy-core" may be inconvenient because if you refer to Rangy as rangy you're going to have to provide some configuration to tell RequireJS that rangy and rangy-core are the same, but it is not wrong. The proper way to configure RequireJS to handle the fact that your project refers to the rangy-core module as rangy would be to configure it this way:
require.config({
paths: {
"rangy": "https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-core",
"rangy-selectionsaverestore": "https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-selectionsaverestore",
},
map: {
"rangy-selectionsaverestore": {
"rangy-core": "rangy"
},
},
});
Here's a plunker.
And see the comment I made on the code in the PR. This PR would turn an inconvenience into code that is flat out wrong.
| ' if (typeof define == "function" && define.amd) {', | ||
| ' // AMD. Register as an anonymous module with a dependency on Rangy.', | ||
| ' define(["./rangy-core"], factory);', | ||
| ' if ( require && require.s.contexts._.defined.rangy ) {', |
There was a problem hiding this comment.
No way.
require.s is private to RequireJS. If you want to mess with it in your own code, that's on you. But making widely-used library mess with RequireJS' private parts is a non-starter.
if I define the rangy in the requirejs's main.js file like this:
In my code I use it like this:
define(['rangy', 'rangy-selectionsaverestore'], function(rangy) {
// here the rangy is available with the selectionsaverestore module
});
The rangy-selectionsaverestore has dependency on the rangy. So we can not use the AMD as it is righ now, becasuse it forces the define(["./rangy-core"], factory); call, which is wrong in this case becase set the path in the main.js
Please test and merge my fix, thanks