-
Notifications
You must be signed in to change notification settings - Fork 422
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
The amd files in the zip file is not working with requirejs #168
Comments
So what I read from that documentation is that the standard configuration will work (I got it working with Require and the AMD builds at least) but as soon as you add paths or mappings (like map That should be easy to fix (the previous AMD builder removed the .js parts) as long as we have a way to map libraries ( |
Even without mappings or paths (except a path for jquery), the only way to have it work is to have the can/ folder at the root level of the site. Using data-main attribute won't work, even if you have the can/ folder under the js folder:
I get the following error:
It seems to work if I remove all the '.js' in the require() call, even with the data-main, which allows to organise js files. |
If you require a module through a URI that has a file extension attached, then said URI will be used untouched as the direct URL from which to retrieve the resource. That means the URI:
Basically; all URL resolution built into your AMD loader will be skipped. As a rule of thumb, you should never specify the file extension as part of the module URI, unless you are hard-linking to a very particular file location, which is most often when you are loading plain (non-AMD) JS or non-JS resources. (In case of the latter you'd almost exclusively be using a loader plugin for that particular family of non-JS resource as well.) |
@rjgotten , I also think that the js files in amd/ should not specify the file extension as part of the module URI. @daffl : to map util to a specific libray, what about using:
I have to admit that I didn't test it, I will try tomorrow if I have time... or this wend-end. |
@saadtazi This won't work because mapping We have a new AMD build ready that should solve the above issues. Hopefully it will be published with version 1.1.2 tomorrow. |
@daffl If you're worried about path remappings, then a not-so-easy but more bulletproof way out is to create a loader plugin that handles switching between the various selector libraries and to configure it using module config. Given a simple loader plugin define([ "module" ], function( module ) {
var lib = "./" + ( module.config().lib || "jquery" );
return {
load : function( name, require, load, config ) {
require([ lib ], load );
}
}
}); and an application configuration: require.config({
config : {
"can/util/lib" : { lib : "zepto" } // want zepto instead of jquery
}
}) You could have define([ "./lib!" ], function( lib ) {
}); This is similar to how the RequireJS optimizer dynamically loads dependencies for either the NodeJS or RhinoJS environment. (I'd also recommend using module config to decide on whether to inject the Also note the use of relative paths; if you have all the CanJS components use a relative path, then you can easily move the entire library around your project structure. |
I hate to be "that guy" but when will 1.1.2 be released? |
I uploaded a 1.1.2 preview with the new builds. Maybe you can try it out and let me know if it solves the problem. Instead of This build is being used in the CanJS + RequireJS TodoMVC example and seems to work fine (but it doesn't need any mappings, either). |
So you would only need a mapping if you wanted to use a library other than jQuery? |
Yes. For e.g. Mootools you would do
|
I ended up doing this... "paths": {
"can": "can-1.1.2-pre",
"can/util/library": "can-1.1.2-pre/util/jquery"
} Mostly to cut out the I noticed that |
We want to be able to use AMD + jQuery without having to map anything CanJS specific. |
1.1.2 is out and it seems to solve all the AMD problems mentioned above. Closing. |
the zip that can be downloaded from the AMD section of http://canjs.us (https://github.com/downloads/bitovi/canjs/can.js.1.1.1.zip) contains amd/ files that do not work: a lot of files in the require() first array parameter contains '.js' which breaks the loading (generates 404 errors) with requirejs.
Example with amd/can/util/array/each.js in the zip (line 1) - notice the '.js' in 'can/util/can.js:
FYI: The 1.1.0 zip that I downloaded a couple of days ago was also working.
FYI: From http://requirejs.org/docs/api.html:
note: I originally said that rebuilding canjs amd with latestest changes fixes the issue. I just retested it with I fresh clone of donejs and it is actually not the case: I get the '.js' after building - same files that are downloadable.
The text was updated successfully, but these errors were encountered: