In general though, it is best to use the baseUrl and "paths" config to set paths for module IDs. Contains an URL protocol, like "http:" or "https:".If a module ID has one of the following characteristics, the ID will not be passed through the "baseUrl + paths" configuration, and just be treated like a regular URL that is relative to the document: There may be times when you do want to reference a script directly and not conform to the "baseUrl + paths" rules for finding it. All of these capabilities allow you to use smaller strings for scripts as compared to traditional tags. RequireJS will automatically add it when translating the module ID to a path. RequireJS also assumes by default that all dependencies are scripts, so it does not expect to see a trailing ".js" suffix on module IDs. If there is no explicit config and data-main is not used, then the default baseUrl is the directory that contains the HTML page running RequireJS. Or, baseUrl can be set manually via the RequireJS config. This example will end up with a baseUrl of scripts: The data-main attribute is a special attribute that require.js will check to start script loading. The baseUrl is normally set to the same directory as the script used in a data-main attribute for the top level script to load for a page. RequireJS loads all code relative to a baseUrl. As part of that, it encourages using module IDs instead of URLs for script tags. While it can also run fast and optimize well, the primary goal is to encourage modular code. RequireJS takes a different approach to script loading than traditional tags.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |