{"id":25322712,"url":"https://github.com/qzruncode/sophic-sw-webpack-plugin","last_synced_at":"2025-08-23T01:44:54.422Z","repository":{"id":65188518,"uuid":"586447324","full_name":"qzruncode/sophic-sw-webpack-plugin","owner":"qzruncode","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-27T09:01:28.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-31T11:54:05.438Z","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/qzruncode.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-08T06:52:22.000Z","updated_at":"2023-01-08T13:22:50.000Z","dependencies_parsed_at":"2025-04-07T22:41:41.658Z","dependency_job_id":"e15166a5-1e4c-4cb8-a899-28ed6e37c449","html_url":"https://github.com/qzruncode/sophic-sw-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qzruncode/sophic-sw-webpack-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qzruncode%2Fsophic-sw-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qzruncode%2Fsophic-sw-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qzruncode%2Fsophic-sw-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qzruncode%2Fsophic-sw-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qzruncode","download_url":"https://codeload.github.com/qzruncode/sophic-sw-webpack-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qzruncode%2Fsophic-sw-webpack-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271731591,"owners_count":24811307,"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":"2025-02-13T23:47:44.508Z","updated_at":"2025-08-23T01:44:54.352Z","avatar_url":"https://github.com/qzruncode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version](https://img.shields.io/npm/v/sophic-sw-webpack-plugin.svg)](https://www.npmjs.com/package/sophic-sw-webpack-plugin)\n[![NPM package](https://img.shields.io/npm/dy/sophic-sw-webpack-plugin.svg)](https://www.npmjs.com/package/sophic-sw-webpack-plugin)\n\n## sophic-sw-webpack-plugin\n\n1. 此插件为[sophic](https://www.npmjs.com/package/sophic)而设计，用来生成sw文件，从而使用sophic中的sw缓存模式，存储微应用的静态资源\n2. 此插件最好在[dark-tunnel](https://www.npmjs.com/package/dark-tunnel)脚手架中使用\n3. 提供配置项expirationHour用来设置缓存时效，不建议过长\n\n### 安装\n\n```\nnpm install -D sophic-sw-webpack-plugin\n```\n\n### 使用\n\n```\n在使用dark-tunnel创建的项目根目录新建 darkTunnel.config.js\n\nconst cachewebWebpackPlugin = require('sophic-sw-webpack-plugin');\nmodule.exports = [\n  new cachewebWebpackPlugin({\n    expirationHour: 2\n  }),\n];\n\n在使用dark-tunnel编译项目后，会在build目录下生成sw.js文件\n```\n\n### 注册\n\n```\n在使用dark-tunnel创建的项目根目录新建 static/registerSW.js\n\nfunction registerSW() {\n  if (\"serviceWorker\" in navigator) {\n    navigator.serviceWorker\n      .register(\"/sw.js\", { scope: '/' })\n      .then((registration) =\u003e {\n        let serviceWorker;\n        if (registration.installing) {\n          serviceWorker = registration.installing;\n        } else if (registration.waiting) {\n          serviceWorker = registration.waiting;\n        } else if (registration.active) {\n          serviceWorker = registration.active;\n        }\n        if (serviceWorker) {\n          serviceWorker.addEventListener(\"statechange\", function (e) {\n            console.log(\"sw的状态改变：\" + e.target.state);\n          });\n        }\n      });\n    navigator.serviceWorker.onmessage = (e) =\u003e {\n      console.log(\"onmessage\", e);\n      const { data } = e;\n      if (data.type === \"FetchError\") {\n        // 请求失败;\n      } else if (data.type === \"NetWorkError\") {\n        // 断网\n      } else if (data.type === \"RefreshClient\") {\n        // 刷新页面，有新版本的sw安装\n        location.reload();\n      }\n    };\n  } else {\n    console.log(\"sw不支持\");\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqzruncode%2Fsophic-sw-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqzruncode%2Fsophic-sw-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqzruncode%2Fsophic-sw-webpack-plugin/lists"}