{"id":19490924,"url":"https://github.com/pandao/gulp-moder","last_synced_at":"2025-08-22T08:13:25.910Z","repository":{"id":87753500,"uuid":"56143569","full_name":"pandao/gulp-moder","owner":"pandao","description":"Gulp plugin for Moder.js","archived":false,"fork":false,"pushed_at":"2016-05-14T03:39:42.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-29T19:40:48.728Z","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/pandao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGE.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-13T10:45:00.000Z","updated_at":"2023-09-08T17:09:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"4da26d1b-87d1-468a-8219-fe3b20ea643e","html_url":"https://github.com/pandao/gulp-moder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pandao/gulp-moder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandao%2Fgulp-moder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandao%2Fgulp-moder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandao%2Fgulp-moder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandao%2Fgulp-moder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pandao","download_url":"https://codeload.github.com/pandao/gulp-moder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandao%2Fgulp-moder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271606595,"owners_count":24788979,"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-08-22T02:00:08.480Z","response_time":65,"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":[],"created_at":"2024-11-10T21:14:48.017Z","updated_at":"2025-08-22T08:13:25.881Z","avatar_url":"https://github.com/pandao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-moder\n\nGulp plugin for [Moder.js](https://github.com/pandao/moder.js)\n\n前端模块加载器 [Moder.js](https://github.com/pandao/moder.js) 构建工具，辅助自动生成模块 Map。\n\n### 使用方法\n\n安装命令：\n\n```shell\n$ npm install gulp-moder --save-dev\n```\n\nGulp 任务配置 `Gulpfile.js`：\n\n```javascript\n/**\n * Gulp.js 构建文件\n * \n * @author Pandao\n * @updateTime 2016-04-17\n */\n\nvar fs      = require(\"fs\");\nvar gulp    = require('gulp');\nvar clean   = require('gulp-clean');\nvar notify  = require('gulp-notify');\nvar uglify  = require('gulp-uglify');\nvar rename  = require('gulp-rename');\nvar conact  = require('gulp-concat');\nvar replace = require('gulp-replace');\nvar header  = require('gulp-header');\nvar moder   = require('../index');\n\n// 定义源文件目录\nmoder.srcPath = \"./modules/\";\n\n// 定义目标输出目录\nmoder.destPath = \"./output/\";\n\n/**\n * 打包一个包模块文件，即一个文件中有多个 define\n */ \n\ngulp.task('pkg', function() {\n    return gulp.src(['modules/*.js'])\n               .pipe(conact('pkg2.js'))\n               .pipe(header(\"//@modulePackage pkgB\\n\")) // 在头部插入一个包名标签\n               .pipe(gulp.dest(\"modules/pkg/\"))\n               .pipe(notify({ message: \"pkg task completed!\" }));\n});\n\n/**\n * 清空目标输出目录\n */ \n\ngulp.task('clean', function() {\n    return gulp.src('./output/**/*.js')\n               .pipe(clean())\n               .pipe(notify({ message: \"clean task completed!\" }));\n});\n\n/**\n * 自动加模块名和生成模块 Map\n */ \n\ngulp.task(\"map\", [\"clean\"], function() {\n    return gulp.src(\"modules/**/*.js\")\n        .on('end', function() { \n            // 追加 Map\n            /*moder.appendMap = {\n                pkg : {\n                    'pkgB' : {\n                        deps : ['a', 'b', 'c', 'c/main'],\n                        url  : 'pkg_d34rbfvh6645.js'\n                    }\n                }\n            };*/\n\n            // 替换模板页中的 Map 标签，并输出最终页面文件\n            moder.replaceMap('./test.tpl.html', './test.html', /({{\\$map}})/g, function(map) {\n                //console.log('moder.replaceMap =\u003e', JSON.stringify(map));\n            });\n\n            // 将模块 Map 输出为 json 文件，方便给 PHP include\n            moder.writeMapToJSON('./map.json', function(map) {\n                //console.log('moder.jsonMap =\u003e', JSON.stringify(map));\n            });\n        })\n        .pipe(moder.build())\n        .pipe(uglify())\n        //.pipe(moder.rename()) // 如果要使用 cart.list_707594a1.js 这种方式重命名文件才调用这个方法\n        .pipe(gulp.dest(moder.destPath))\n        .pipe(notify({ message: \"Map task completed!\" }));\n});\n\ngulp.task('watch', function() {\n    gulp.watch('modules/**/*.js', ['map']);\n    gulp.watch('test.tpl.html', ['map']);\n});\n\ngulp.task(\"default\", [\"pkg\", \"map\"]);\n```\n\n标签语法：\n\n\u003e 用于自动生成模块 Map，注意标签必须靠左边顶格写（左边无空格）。\n\n1、单文件单个模块\n\n```javascript\n//@moduleName xxxx        // 模块名\n//@moduleDeps xxx,xxx,... // 模块依赖\n\ndefine(function(require, exports, module){\n    // 禁止在 define 里 define\n    module.exports = {\n        foo : 'bar'\n    };\n});\n```\n\n\u003e 在 `define` 内通过 `require.async('xxx', function(){//...});` 方式调用的模块不需要定义在 `//@moduleDeps` 模块依赖中。\n\n2、包模块文件，即一个文件内有多个模块 define\n\n```javascript\n//@modulePackage xxxx     // 包名\n\n//@moduleName xxxx        // 模块名\n//@moduleDeps xxx,xxx,... // 模块依赖\n\ndefine(function(require, exports, module){\n    module.exports = {\n        foo : 'bar'\n    };\n});\n\n//@moduleName xxxx        // 模块名\n//@moduleDeps xxx,xxx,... // 模块依赖\n\ndefine(function(require, exports, module){\n    module.exports = {\n        foo : 'bar'\n    };\n});\n\n//@moduleName xxxx        // 模块名\n//@moduleDeps xxx,xxx,... // 模块依赖\n\ndefine(function(require, exports, module){\n    module.exports = {\n        foo : 'bar'\n    };\n});\n```\n\n生成结果：\n\n```\n./output\n    /pkg\n        all_3aa20277.js\n        pkg2_d3903ca2.js\n    /c\n        main_2f3dd68c.js\n    /view\n        info_fd175e15.js\n        ...\n    /component\n        cart.list_707594a1.js\n        ...\n    ...\n```\n\n\u003e 当配置项 `versionQuery = true`（v0.1.4 起新增，默认为 `true`） 且不调用 `moder.rename()` 方法时，模块文件的 URL 形式为 `/component/cart.list.js?v=707594a1`，用于保证文件始终存在，避免无法请求到文件。\n\n调用模块：\n\n```javascript\nrequire(['模块1', '模块2'], function(m1, m2) {\n    console.log(m1, m2);\n});\n```\n\n### License\n\nThe [MIT](https://github.com/pandao/gulp-moder/blob/master/LICENSE) license.\n\nCopyright (c) 2016 Pandao","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandao%2Fgulp-moder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandao%2Fgulp-moder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandao%2Fgulp-moder/lists"}