-
-
Save jrburke/1344389 to your computer and use it in GitHub Desktop.
| // Basic approach. Does not try to register in | |
| // a CommonJS environment since jQuery is not likely | |
| // to run in those environments. See next file | |
| // if you want to opt in to CommonJS too. | |
| (function(factory) { | |
| if (typeof define === 'function' && define.amd) { | |
| // AMD. Register as an anonymous module. | |
| define(['jquery'], factory); | |
| } else { | |
| // Browser globals | |
| factory(jQuery); | |
| } | |
| }(function($) { | |
| $.fn.myPlugin = function () {}; | |
| })); |
| // Includes registering in a CommonJS environment, | |
| // but it is unlikely jQuery will run in a CommonJS | |
| // environment. See other file if you do not want | |
| // optional CommonJS registration. | |
| (function(factory) { | |
| if (typeof exports === 'object') { | |
| // Node/CommonJS | |
| factory(require('jquery')); | |
| } else if (typeof define === 'function' && define.amd) { | |
| // AMD. Register as an anonymous module. | |
| define(['jquery'], factory); | |
| } else { | |
| // Browser globals | |
| factory(jQuery); | |
| } | |
| }(function($) { | |
| $.fn.myPlugin = function () {}; | |
| })); |
@jrburke, I tried to change the names of the modules to match the filename and that didn't change anything. I didn't try to add it to the paths. When I made it into an anonymous module it worked as expected. Seems kind of strange that having it as a named module would cause the dependency to fail, even when it matches the name of the file.
I just added a version that does not do optional CommonJS registration, since jQuery is unlikely to run in those environments, but there is also a version with optional CommonJS registration.
@Zoramite, I changed test2.js to be a named module with name 'scripts/test2' and then in index2.htm require 'scripts/test2' and then your previous gist works for me.
@jrburke, I guess that makes sense. It it using the full path as the module name.
@jrburke I have seen the light :)