I am looking to add AMD support to a library although don't fully understand it. I have the following code that adds AMD support:
if (typeof define === "function" && define.amd) {
define(["imagesloaded", "hammer"], defineSequence);
} else {
sequence = defineSequence(imagesLoaded, Hammer);
}
The library depends on third-party libraries imagesLoaded and Hammer. I have listed them as dependencies in define()
but I am concerned as to whether this limits a developer who uses my plugin to a specific file structure and naming convention whereby imagesloaded, hammer, and sequence all have to exist at the same directory level.
Is the above code correctly enabling AMD support and is this restriction to be expected?
Update: An example of my paths config as explained in the correct answer:
require.config({
baseUrl: 'scripts',
paths: {
imagesLoaded: 'imagesloaded.pkgd.min',
Hammer: 'hammer.min'
}
});
Path config can be used for defining the path to the dependencies. So you dont have to worry about users directory structure.
You should only provide information of what AMD module you are expecting as dependency and what functionality it should provide. It may even be abstract like $ (coming from jquery, zepto or sizzle)