{"id":25827692,"url":"https://github.com/uojo/requirejs-config-sugar","last_synced_at":"2025-10-11T21:41:07.630Z","repository":{"id":57354414,"uuid":"81314462","full_name":"uojo/requirejs-config-sugar","owner":"uojo","description":"简化 requirejs 打包模块文件的配置","archived":false,"fork":false,"pushed_at":"2019-01-09T03:22:11.000Z","size":68,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-18T00:50:43.982Z","etag":null,"topics":["requirejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uojo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-08T09:54:26.000Z","updated_at":"2023-12-11T06:50:12.000Z","dependencies_parsed_at":"2022-09-12T06:00:46.082Z","dependency_job_id":null,"html_url":"https://github.com/uojo/requirejs-config-sugar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uojo/requirejs-config-sugar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uojo%2Frequirejs-config-sugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uojo%2Frequirejs-config-sugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uojo%2Frequirejs-config-sugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uojo%2Frequirejs-config-sugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uojo","download_url":"https://codeload.github.com/uojo/requirejs-config-sugar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uojo%2Frequirejs-config-sugar/sbom","scorecard":{"id":911183,"data":{"date":"2025-08-11","repo":{"name":"github.com/uojo/requirejs-config-sugar","commit":"3e1f428a4e82776c8ae6a8c798af7f633739d1ea"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-24T19:15:28.069Z","repository_id":57354414,"created_at":"2025-08-24T19:15:28.069Z","updated_at":"2025-08-24T19:15:28.069Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008837,"owners_count":26084517,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["requirejs"],"created_at":"2025-02-28T16:39:07.979Z","updated_at":"2025-10-11T21:41:07.611Z","avatar_url":"https://github.com/uojo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# requirejs-config-sugar\n\n\u003e 作用：简化使用 requirejs 打包时，引用模块文件前的处理操作，参考 jQuery 打包时的处理，即项目会被打包成一个 UMD 的文件，供浏览器、Node 等场景下使用。\n\n## Getting Started\n\n安装\n\n`npm install requirejs-config-sugar`\n\n引入模块\n\n`var rjsCfg_sugar = require(\"requirejs-config-sugar\");`\n\n## 使用\n\n根据模块名称的编译，示例如下\n\n模块名称 | 模块内容 | 编译结果\n:---|:---|:---\ntpl/name1 | function(){} | var tpl_name1 = function(){}\nvar/fn1 | function(){} | var fn1 = function(){}\ntext!var/tpl/name2.html | html字符串... | var tpl_name2 = 'html字符串...'\ntext!obj/name3.html | html字符串... | obj.name3 = 'html字符串...'\nobj/name4 | function(){} | obj.name4 = function(){}\n上方中实现的提前配置如下：\n\n```\n{common:{\n  objectModuleDir:[\"obj\"],\n  varModuleDir:[\"var\",\"tpl\"],\n  ...\n},...}\n```\n\n\u003e 的 obj 目录，需添加配置 objectModuleDir:[\"obj\"]\n\n简要示例如下：\n\n```\n// entry.js\ndefine([\n\"core\",\n\"fn/name1\",\n\"var/fn1\",\n\"text!var/tpl/name2.html\",\n\"text!TPL/name3.html\",\n\"TPL/name4\",\n], function(Fn) {\n  Fn.xxx2 = tpl_name2;\n  \n  // 全局命名空间\n  var spaceName=\"TPL\";\n  // console.log(\"main.complete\");\n  if( window[spaceName] ){\n    $.extend(window[spaceName],Fn);\n  }else{\n    window[spaceName] = Fn;\n  }\n  \n  return Fn;\n});\n\n// core.js\ndefine([], function() {\n  var Fn = {\n    fieldname1:1,\n    fieldname2:function(){\n      \n    }\n  };\n  return Fn;\n});\n\n```\n\n更多写法可以通过阅读项目示例体会 `test/app`\n\n\u003e 其中 var、TPL、Fn ，目前均为保留字段名！\n\n## 方法\n\n### config(options)\n建议配置至少一条记录，`options` 为对象，其中包含如下参数\n| 字段名称        | 作用           | 备注  |\n| :------------- |:-------------| :-----|\n| common | 通用参数设置 | 与 records 字段配置内容相同，只是在此配置后，在每一条记录都会生效 |\n| records | 每条记录参数设置 | 设置对象字段请 [参考](https://github.com/requirejs/r.js/blob/master/build/example.build.js) |\n示例：\n\n```\nrjs_sugar.config({\n  \"common\":{\n    \"name\":\"entry\",\n    \"optimize\":\"none\",\n    // 自义定参数\n    \"speedTaskEnter\":0, // 任务进入执行队列中最小间隔时间 \n    \"onBuildWriteAfter\":function(moduleName, path, contents){\n      // onBuildWrite 之后执行的回调 \n      return contents;\n    },\n    \"varModuleDir\":['var'] // 通过模块名称转化为定义语法，例：var xxx = ...\n    \"objectModuleDir\":[] // 通过模块名称转化为对象注册属性语法，例：Obj.attr = ...\n  },\n  \"records\":{\n    \"recordsName1\":{\n      \"baseUrl\": 'dirname1/',\n      \"out\": 'build/file1_build.js'\n    },\n    \"recordsName2\":{\n      \"baseUrl\": 'dirname2/',\n      \"out\": 'build/file2_build.js'\n    },\n  }\n});\n```\n\n### pack(recordname, callback)\n通过配置记录执行打包\n\n参数 | 作用\n|:---|:---\n|recordName | config设置的记录名称\n|callback | 打包执行后的回调函数\n\n示例：\n```\nrjs_sugar.optimize(\"gf\",cbfn);\n```\n\n### optimize(config, callback)\n通过传入配置参数执行打包\n|参数 | 作用\n|:---|:---\n|config | requirejs 打包配置，请 [参考](https://github.com/requirejs/r.js/blob/master/build/example.build.js)\n|callback | 打包执行后的回调函数\n\n示例：\n```\nrjs_sugar.optimize({\n  name: 'entry',\n  out: 'build.js'\n},cbfn);\n```\n\n### matchRecord( path, runPack, callback)\n通过传入文件的绝对路径，获取匹配的配置记录。且可立即执行打包。\n\n|参数 | 作用 | 默认值\n|:---|:---|:---\n|path | 文件的绝对路径，建议使用 path.resolve() | \"\"\n|runPack | 立即执行打包 | false\n|callback | 打包执行后的回调函数 | \n\n返回：匹配记录的名称\n\n示例：\n```\nvar recordName = rjs_sugar.matchRecord( path.resolve('./dirname1/xxx.js'), true, function(name,options){\n  console.log(name); // recordsName1\n  console.log(options); // { \"baseUrl\":'dirname1/', \"out\":'build/file1_build.js' }\n} );\nconsole.log( recordName ); // recordsName1\n```\n\n## ChangeLog\n### 0.5.0\n- 对 xxx = require(...) 的支持\n### 0.4.0\n- 对rjs参数 findNestedDependencies 的支持\n### 0.3.0\n- 新增自定义配置参数 varModuleDir\n- 重写内部模块解析，放弃原先内置对模板名称中 TPL、Fn 的解析。之前版本可通过配置 varModuleDir、objectModuleDir 来升级\n### 0.2.0 \n- 新增自定义配置参数 onBuildWriteAfter、objectModuleDir\n- 提示：可能不兼容之前的版本\n### 0.1.3\n- fix matchRecord 回调执行的bug\n### 0.1.2\n- 使用 uojo-kit 模块来替换 log，新增参数 speedTaskEnter\n- 互换 pack 与 optimize 的方法的使用\n\n### 0.1.1\n- 修复回调执行\n- 将队列顺序执行更改为队列异步执行\n\n### 0.0.7\n- 新增方法 matchRecord ，用于匹配记录\n\n### 0.0.6\n- 修复当错误时不提示信息的问题\n\n### 0.0.5\n- 修改 console.log 显示方式\n- 新增 require(TPL/xxx) 模板时，打包后的内容为 TPL.xxx = ...\n\n### 0.0.4\n- 添加测试、使用实例\n- 新增 require(text!xxx...) 模板时，打包后的内容挂载方式\n\n### 0.0.3\n- 添加打包成功后的消息输出\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuojo%2Frequirejs-config-sugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuojo%2Frequirejs-config-sugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuojo%2Frequirejs-config-sugar/lists"}