{"id":20226223,"url":"https://github.com/steamerjs/steamer-plugin-ak","last_synced_at":"2026-05-31T01:31:12.296Z","repository":{"id":57370589,"uuid":"63337362","full_name":"steamerjs/steamer-plugin-ak","owner":"steamerjs","description":null,"archived":false,"fork":false,"pushed_at":"2018-05-02T16:27:24.000Z","size":550,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T14:01:12.497Z","etag":null,"topics":[],"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/steamerjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-07-14T13:07:50.000Z","updated_at":"2018-11-06T11:02:06.000Z","dependencies_parsed_at":"2022-08-29T18:30:58.143Z","dependency_job_id":null,"html_url":"https://github.com/steamerjs/steamer-plugin-ak","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fsteamer-plugin-ak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fsteamer-plugin-ak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fsteamer-plugin-ak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fsteamer-plugin-ak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steamerjs","download_url":"https://codeload.github.com/steamerjs/steamer-plugin-ak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241670132,"owners_count":20000326,"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-14T07:16:51.383Z","updated_at":"2026-05-31T01:31:12.289Z","avatar_url":"https://github.com/steamerjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# steamer-plugin-ak\n\nAlloyKit平台生成离线包命令\n\n[![NPM Version](https://img.shields.io/npm/v/steamer-plugin-ak.svg?style=flat)](https://www.npmjs.com/package/steamer-plugin-ak)\n[![Travis](https://img.shields.io/travis/steamerjs/steamer-plugin-ak.svg)](https://travis-ci.org/steamerjs/steamer-plugin-ak)\n[![Deps](https://img.shields.io/david/steamerjs/steamer-plugin-ak.svg)](https://david-dm.org/steamerjs/steamer-plugin-ak)\n[![Coverage](https://img.shields.io/coveralls/steamerjs/steamer-plugin-ak.svg)](https://coveralls.io/github/steamerjs/steamer-plugin-ak)\n\n## Webpack 插件\n如果是 `steamer` 系列的 `webpack` 脚手架，可使用 [ak-webpack-plugin](https://github.com/steamerjs/ak-webpack-plugin) 插件。\n\n## 安装\n\n```javascript\nnpm i -g steamerjs\n\nnpm i -g steamer-plugin-ak\n```\n\n## 使用\n\n如果项目的生成环境的代码结构如下：\n\n```javascript\n-- dist\n\t|\n\t-- cdn\n\t|\t|\n\t|\t|-- css\n\t|\t|-- img\n\t|\t|-- js\n\t|\n\t-- webserver\n\t\t|-- index.html\n\t\t|-- detail.html\n\t\t|-- comment.html\n```\n\n初始化：\n\n```javascript\nsteamer ak -i\n\n或\n\nsteamer ak -init\n\n```\n\n它会弹出下面的一些问题：\n\n`Your zip file name`, 意思是最终生成的离线包名称，默认值是 `offline`，**当前文件夹位置以命令执行位置为基准**。\n\n`Your source folder`, 生成环境的代码源，上面的项目结构中是 `dist`，这也是默认值。\n\n后面三个选项会一直循环出现，除非你输入空值，因为项目中可能有多个 `cdn` 对应多个静态资源。例如，你可能会用 `//huayang.qq.com/h5/` 给你的 `html` 文件，而用 `//s1.url.cn/h5/` 给你的其它静态资源。\n\n\n```javascript\nYour zip file name(e.g., offline): (offline)\n\nYour source folder(e.g., build, pub, dist): (dist)\n\nWhether to add webserver url for all resources: (No)\n\nYour resource folder(e.g., cdn, cdn/js, cdn/css, webserver):\n\nYour destination url(e.g.,//huayang.qq.com/h5/):\n\nYour destination folder(e.g., /, /, js, css):\n```\n\n这里是配置文件的范例 (.steamer/steamer-plugin-ak.js).\n\n```javascript\nmodule.exports = {\n    \"plugin\": \"steamer-plugin-ak\",\n    \"config\": {\n        // String, 最终生成的离线包名称，默认值是 `offline`，**当前文件夹位置以命令执行位置为基准**\n        \"zipFileName\": \"dist/offline\", \n        // String, 生成环境的代码源，默认值 `dist`\n        \"src\": \"dist\",\n        // 压缩参数，详参 https://archiverjs.com\n        \"zipConfig\": {\n            zlib: { level: 9 },\n        },  \n        // 具体的文件目录及cdn映射,\n        \"map\": [\n            {\n                \"src\": \"webserver\",\n                \"url\": \"//localhost:9000/\"\n            },\n            {\n                \"src\": \"cdn\",\n                \"url\": \"//localhost:8000/\"\n            }\n        ],\n        // minimatch 配置，以下是默认的配置\n        \"minimatchOpt\": {\n            matchBase: true,\n\t\t    dot: true\n        },\n        // 下列回调方法，可以直接使用this.fs (fs-extra), this.success, this.info, this.warn, this.alert\n        // 在 拷贝文件到 offline 离线文件夹之前\n        beforeCopy: function() {\n            \n        },\n        // 在 拷贝文件到 offline 离线文件夹之后\n        afterCopy: function() {\n            \n        },\n        // 在压缩 offline 离线文件夹之前\n        beforeZip: function(offlineFiles) {\n            // offlineFiles 在离线包文件夹内的文件路径信息\n        },\n        // 在压缩 offline 离线文件夹之后\n        afterZip: function(zipFilePath) {\n            // zipFilePath 最终生成的离线zip包路径\n            \n        }\n    }\n}\n```\n\n然而，有时候你会对 `html` 以外的静态资源再进行细分，使用不同的 `cdn` 域名，例如 `//s1.url.cn/h5/` 给你的 `js`文件，用 `//s2.url.cn/h5/` 给 `css` 文件， 然后用 `//s3.url.cn/h5/` 给其它的文件。\n\nHere is another example config.\n\n```javascript\nmodule.exports = {\n    \"plugin\": \"steamer-plugin-ak\",\n    \"config\": {\n        \"zipFileName\": \"offline\",\n        \"src\": \"dist\",\n        \"map\": [\n            {\n                \"src\": \"cdn/js\",\n                // String, 目标文件路径子文件夹，默认为空字符串\n                \"dest\": \"js\",\n                // Boolean， 默认 false，如果为 true， 则会将 cdn 的 url替换成与 isWebserver 为 true 的 cdn url\n                \"isSameOrigin\": true, \n                \"url\": \"s1.url.cn/huayang/\"\n            },\n            {\n                \"src\": \"cdn/css\",\n                \"dest\": \"css\",\n                \"url\": \"s2.url.cn/huayang/\"\n            },\n            {\n                \"src\": \"cdn/img\",\n                \"dest\": \"img\",\n                \"url\": \"s3.url.cn/huayang/\"\n            },\n            {\n                \"src\": \"cdn/lib\",\n                \"dest\": \"lib\",\n                \"url\": \"s1.url.cn/huayang/\"\n            },\n            {\n                \"src\": \"webserver\",\n                // Boolean， 默认为 false，如果为 true，则这将告诉插件这是 html 的主要 cdn url \n                \"isWebserver\": true,\n                \"url\": \"huayang.qq.com/huayang/activity/\"\n            }\n        ]\n    }\n}\n```\n\n之所以要用 `isSameOrigin` 与 `isWebserver`，是有时候需要 `html` 文件和 `js` 文件的域名一致，例如有时候需要收集js的报错，让两者的 `cdn` 一致会更方便收集到具体的报错信息。\n\n如果你想部份文件走离线包，部份走线上，你在生成离线包的时候，可以 `exclude` 部份文件。 `exclude` 参数，主要是 `Globs` 的写法，可以参考 [minimatch](https://github.com/isaacs/minimatch) 的配置。示例配置如下。对于一些比较长的路径，如 `/a/b/c/d/1.png`，可以尝试如 `**/c/d/*.png` 类似的匹配。\n\n```javascript\nmodule.exports = {\n    \"plugin\": \"steamer-plugin-ak\",\n    \"config\": {\n        \"zipFileName\": \"dist/offline\",\n        \"src\": \"dist\",\n        \"map\": [\n            {\n                \"src\": \"webserver\",\n                \"dest\": \"\",\n                \"url\": \"//huayang.qq.com/h5/\"\n            },\n            {\n                \"src\": \"cdn\",\n                \"dest\": \"\",\n                \"url\": \"//s1.url.cn/h5/\",\n                \"exclude\": ['*.png', '*ell.jpg'],\n            }\n        ]\n    }\n}\n\n```\n\n下面的命令，会进行压缩，并生成 `offline` 文件夹，还有 `offline.zip` 文件。\n\n```javascript\nsteamer ak -c\n\nor\n\nsteamer ak -compress\n```\n\n## 测试\n\n```javascript\n// 安装eslint工具\nnpm i -g eslint\n\nnpm run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteamerjs%2Fsteamer-plugin-ak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteamerjs%2Fsteamer-plugin-ak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteamerjs%2Fsteamer-plugin-ak/lists"}