{"id":22432539,"url":"https://github.com/zhusiqing/webpack-cdn-replace-plugin","last_synced_at":"2025-03-27T07:42:27.824Z","repository":{"id":65526041,"uuid":"516648381","full_name":"zhusiqing/webpack-cdn-replace-plugin","owner":"zhusiqing","description":"webpack插件，用于cdn上传并替换对应地址","archived":false,"fork":false,"pushed_at":"2022-08-25T07:10:45.000Z","size":2185,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-01T12:45:40.706Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhusiqing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-22T07:10:43.000Z","updated_at":"2024-02-04T07:25:04.000Z","dependencies_parsed_at":"2023-01-27T09:00:33.955Z","dependency_job_id":null,"html_url":"https://github.com/zhusiqing/webpack-cdn-replace-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fwebpack-cdn-replace-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fwebpack-cdn-replace-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fwebpack-cdn-replace-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fwebpack-cdn-replace-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhusiqing","download_url":"https://codeload.github.com/zhusiqing/webpack-cdn-replace-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806025,"owners_count":20675291,"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-12-05T22:12:04.190Z","updated_at":"2025-03-27T07:42:27.806Z","avatar_url":"https://github.com/zhusiqing.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpack-cdn-replace-plugin\n\nwebpack插件，用于解决项目文件上传cdn后需要手动替换地址的问题，无任何上传依赖，让用户灵活使用自己想用的cdn上传服务\n\n## 安装\n\n```bash\n# npm\nnpm i -D webpack-cdn-replace-plugin\n# yarn\nyarn add -D webpack-cdn-replace-plugin\n# pnpm\npnpm add -D webpack-cdn-replace-plugin\n```\n\n## 用法\n\n在你的`webpack.config.js`文件中：\n\n```javascript\nconst { UploadPlugin } = require('webpack-cdn-replace-plugin')\n\nmodule.exports = {\n  mode: 'production',\n  output: {\n    // 这里的publicPath要为空，不然js文件中的cdn地址会出问题\n    publicPath: '',\n    // ...\n  },\n  // ...其他webpack配置\n  plugins: [\n    // ...其他webpack插件\n    new UploadPlugin({\n      uploadFn: async(path, fileName) =\u003e {\n        // 此处调用你要用的cdn上传api，将返回的cdn地址返回\n        return `http://test.cdn/${fileName}`\n      }\n    })\n  ]\n}\n```\n\n\u003e 注意事项：**publicPath**一定要为空，不然cdn地址替换后会有问题\n\n## 参数\n\n#### options.uploadFn: `(path: string, fileName: string) =\u003e string | Promise\u003cstring\u003e`\n\n上传cdn的处理函数\n\n默认值：`(path, fileName) =\u003e fileName`\n\n#### options.cache: `boolean`\n\n是否启用缓存\n\n默认值：`true`\n\n#### options.types: `object`\n\n需要上传cdn处理的文件类型\n\n|参数名|类型|必选|说明|\n|:---- |:--   |:---|:----- |\n|img |string[]| 否 | 需要上传的图片文件类型 |\n|font |string[]| 否 | 需要上传的字体文件类型 |\n|css |string[]| 否 | 需要替换图片和字体并上传的css文件类型 |\n|js |string[]| 否 | 需要替换图片和字体并上传的js文件类型 |\n|html |string[]| 否 | 需要替换css和js的html文件类型 |\n\n默认值：\n```javascript\n{\n  img: ['.png', '.jpg', '.jpeg', '.svg'],\n  font: ['.ttf', '.otf', '.woff', '.woff2', '.eot'],\n  css: ['.css'],\n  js: ['.js'],\n  html: ['.html']\n}\n```\n\n\u003e 注意事项：**html**文件不会上传，这里是用于替换其他上传文件的地址\n\n## License\n\nMIT\n\nCopyright (c) 2022 zhusiqing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhusiqing%2Fwebpack-cdn-replace-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhusiqing%2Fwebpack-cdn-replace-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhusiqing%2Fwebpack-cdn-replace-plugin/lists"}