{"id":21525301,"url":"https://github.com/superraytin/duckjs","last_synced_at":"2025-03-17T18:18:52.606Z","repository":{"id":6095529,"uuid":"7322616","full_name":"superRaytin/duckJS","owner":"superRaytin","description":"A Module Loader For JavaScript - Javascript模块加载器","archived":false,"fork":false,"pushed_at":"2014-01-20T05:57:19.000Z","size":228,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T05:25:17.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/superRaytin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-26T03:05:39.000Z","updated_at":"2016-07-30T12:00:56.000Z","dependencies_parsed_at":"2022-08-30T15:52:38.425Z","dependency_job_id":null,"html_url":"https://github.com/superRaytin/duckJS","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2FduckJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2FduckJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2FduckJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2FduckJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superRaytin","download_url":"https://codeload.github.com/superRaytin/duckJS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085008,"owners_count":20395523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T01:34:23.866Z","updated_at":"2025-03-17T18:18:52.582Z","avatar_url":"https://github.com/superRaytin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# duckJS\nJavaScript模块加载器\n\n\u003e 在遵循AMD规范的基础上，作了一些更加方便的改进，支持定义匿名模块。\n\n# 如何使用\n\n```html\n\u003cscript type=\"text/javascript\" src=\"path/duck.js\" /\u003e\n\u003cscript type=\"text/javascript\"\u003e\n\tD.config({\n\t\talias : {\n\t\t\t'jquery' : 'gallery/jquery-v1.7.2.min.js',\n\t\t\t'style' : 'css/style.css'\n\t\t}\n\t});\n\u003c/script\u003e\n```\n\n# 定义模块\n```html\n// test.js\ndefine( ['jquery'], function($){\n\tD.log('模块已加载');\n\tvar fn = {\n\t\tget : function(){ return 'i am a get method'; },\n\t\tset : function( id, text ){\n\t\t\tdocument.getElementById(id).value = text;\n\t\t\t$('#test').html('');\n\t\t}\n\t};\n\treturn fn;\n});\n```\ndefine是一个全局方法，每一个参数为一个数组，表示此模块的依赖列表，也可以是一个字符串，表示只有一个依赖。\n也可以忽略第一个参数，直接定义一个无依赖的匿名模块。\n\n# 调用模块\n```html\n\u003cscript type=\"text/javascript\"\u003e\n    // 加载一个样式文件\n\tD.use('style');\n\t\n\tD.use(['test','jquery'],function(test,$){\n        // your code...\n    });\n    ... more code of yours ...\n\u003c/script\u003e\n```\n\n解析模块路径将优先从用户设置的config里读取，如果模块未在config里设置，才会对test启动解析过程，比如test模块url最后会被解析为path/test.js，第二个参数是模块加载完成之后的回调，参数依次为依赖模块的输出，即exports。\n\n# 预加载 #\n```html\n\u003cscript type=\"text/javascript\" src=\"path/duck.js\" data-main=\"gallery/jquery-v1.7.2.min.js, path/test.js\" /\u003e\n```\n\n在duckJS对应的script标签设置data-main属性，将会对其中的模块进行预加载（即随着页面初始时一起加载），多个模块用逗号隔开，此时模块相对路径为duckJS的路径，如果模块URL以‘/’开始，则相对于页面根路径。其原理相当于页面一加载即开始运行下面这段代码：\n```html\nduckJS.use(['gallery/jquery-v1.7.2.min.js', 'path/test.js'])\n```\n\n更多架构细节见 [duckJS架构详解](http://www.jsfor.com/qianduan/javascript/javascript-mo-kuai-jia-zai-qi-duckjs-jia-gou-xiang-jie.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperraytin%2Fduckjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperraytin%2Fduckjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperraytin%2Fduckjs/lists"}