{"id":20226232,"url":"https://github.com/steamerjs/ak-webpack-plugin","last_synced_at":"2025-04-10T17:06:28.436Z","repository":{"id":57175246,"uuid":"79827805","full_name":"steamerjs/ak-webpack-plugin","owner":"steamerjs","description":"ak离线包平台打包webpack插件","archived":false,"fork":false,"pushed_at":"2018-04-09T16:18:12.000Z","size":689,"stargazers_count":48,"open_issues_count":3,"forks_count":10,"subscribers_count":8,"default_branch":"v3","last_synced_at":"2024-04-25T23:21:41.620Z","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":"2017-01-23T17:14:59.000Z","updated_at":"2024-04-24T08:02:47.000Z","dependencies_parsed_at":"2022-09-03T11:01:08.835Z","dependency_job_id":null,"html_url":"https://github.com/steamerjs/ak-webpack-plugin","commit_stats":null,"previous_names":["steamerteam/ak-webpack-plugin"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fak-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fak-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fak-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steamerjs%2Fak-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steamerjs","download_url":"https://codeload.github.com/steamerjs/ak-webpack-plugin/tar.gz/refs/heads/v3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248260485,"owners_count":21074210,"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:52.365Z","updated_at":"2025-04-10T17:06:28.417Z","avatar_url":"https://github.com/steamerjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ak-webpack-plugin\n\nAlloyKit平台生成离线包命令\n\n[![NPM Version](https://img.shields.io/npm/v/ak-webpack-plugin.svg?style=flat)](https://www.npmjs.com/package/ak-webpack-plugin)\n[![Travis](https://img.shields.io/travis/steamerjs/ak-webpack-plugin.svg)](https://travis-ci.org/steamerjs/ak-webpack-plugin)\n[![Deps](https://david-dm.org/steamerjs/ak-webpack-plugin.svg)](https://david-dm.org/steamerjs/ak-webpack-plugin)\n\n## 安装\n\n```javascript\nnpm i --save ak-webpack-plugin\n\nnpm i --save-dev ak-webpack-plugin\n```\n\n##  使用\n\n``` javascript\nvar AkWebpackPlugin = require('ak-webpack-plugin');\n\n// 通用配置，webserver 针对 html 文件，而 cdn 是针对 cdn 文件\nplugins: [\n\tnew AkWebpackPlugin({\n        // String, 最终生成的离线包名称，默认值是 `offline`，**当前文件夹位置以命令执行位置为基准**\n        \"zipFileName\": \"dist/offline\",\n        // String, 生成环境的代码源，默认值 `dist`\n        \"src\": \"dist\",\n        // 是否保留生成的离线包文件夹(zip包的源文件)\n        \"keepOffline\": true,\n        // 压缩参数，详参 https://archiverjs.com\n\t    \"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\t})\n]\n\n```\n\n如果你使用上述的配置，它会在 `dist` 目录下，生成 `offline` 文件夹和 `offline.zip` 文件：\n\n``` javascript\n-- dist\n\t|\n\t|- webserver\n\t|- cdn\n\t|- offline\n\t|- offline.zip\n```\n\n``` javascript\n\n// 多个cdn文件配置\nplugins: [\n\tnew AkWebpackPlugin({\n\t    \"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\t})\n]\n```\n\n之所以要用 `isSameOrigin` 与 `isWebserver`，是有时候需要 `html` 文件和 `js` 文件的域名一致，例如有时候需要收集js的报错，让两者的 `cdn` 一致会更方便收集到具体的报错信息。\n\n**注意** 此功能只对 `js` 文件有效，只会给 `js` 文件进行 `cdn` 的替换。\n\n如果使用上述配置，生成的 `offline` 目录，将会有以下的排布：\n\n```\noffline\n |-- huayang.qq.com\n |    |-- huayang\n |         |-- activity\n |              |-- entry.html\n |              |-- js\n |                  |-- index.js\n |-- s1.url.cn\n |    |-- huayang\n |         |-- lib\n |              |-- react.js\n |\n |-- s2.url.cn\n |    |-- huayang\n |         |-- css\n |              |-- index.css\n |-- s3.url.cn\n      |-- huayang\n           |-- img\n                |-- logo.png\n```\n\n\n如果你想部份文件走离线包，部份走线上，你在生成离线包的时候，可以 `exclude` 部份文件。 `exclude` 参数，主要是 `Globs` 的写法，可以参考 [minimatch](https://github.com/isaacs/minimatch) 的配置。示例配置如下。对于一些比较长的路径，如 `/a/b/c/d/1.png`，可以尝试如 `**/c/d/*.png` 类似的匹配。\n\n```javascript\nplugins: [\n    new AkWebpackPlugin({\n        // String, 最终生成的离线包名称，默认值是 `offline`，**当前文件夹位置以命令执行位置为基准**\n        \"zipFileName\": \"dist/offline\", \n        // String, 生成环境的代码源，默认值 `dist`\n        \"src\": \"dist\",\n        // 具体的文件目录及cdn映射\n        \"map\": [\n            {\n                \"src\": \"webserver\",\n                \"url\": \"//localhost:9000/\"\n            },\n            {\n                \"src\": \"cdn\",\n                \"url\": \"//localhost:8000/\",\n                \"exclude\": ['*.png', '*ell.jpg'],\n            }\n        ]\n    })\n]\n\n```\n\n\n## 测试\n```javascript\n// 安装eslint工具\nnpm i -g eslint\n\nnpm run test\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteamerjs%2Fak-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteamerjs%2Fak-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteamerjs%2Fak-webpack-plugin/lists"}