{"id":27377919,"url":"https://github.com/gp5251/webpack-aliyun-oss","last_synced_at":"2025-04-13T13:08:51.884Z","repository":{"id":37735398,"uuid":"151042196","full_name":"gp5251/webpack-aliyun-oss","owner":"gp5251","description":"一个webpack(version \u003e= 4)插件，上传资源到阿里云oss。可以作为webpack插件使用，也可独立使用","archived":false,"fork":false,"pushed_at":"2023-03-07T20:00:43.000Z","size":1838,"stargazers_count":70,"open_issues_count":14,"forks_count":40,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T18:06:43.350Z","etag":null,"topics":["aliyun","aliyun-oss","webpack","webpack-plugin"],"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/gp5251.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-01T05:51:34.000Z","updated_at":"2024-11-20T02:43:18.000Z","dependencies_parsed_at":"2024-09-22T18:46:32.411Z","dependency_job_id":null,"html_url":"https://github.com/gp5251/webpack-aliyun-oss","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gp5251%2Fwebpack-aliyun-oss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gp5251%2Fwebpack-aliyun-oss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gp5251%2Fwebpack-aliyun-oss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gp5251%2Fwebpack-aliyun-oss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gp5251","download_url":"https://codeload.github.com/gp5251/webpack-aliyun-oss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717241,"owners_count":21150389,"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":["aliyun","aliyun-oss","webpack","webpack-plugin"],"created_at":"2025-04-13T13:08:51.349Z","updated_at":"2025-04-13T13:08:51.870Z","avatar_url":"https://github.com/gp5251.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpack-aliyun-oss\nA webpack(version\u003e=4) plugin to upload assets to aliyun oss, u can use it with or without webpack.\n\n一个webpack(version\u003e=4)插件，上传资源到阿里云oss。可以作为webpack插件使用，也可独立使用\n\n- 以插件方式使用时，默认按output.path (webpack.config.js) 目录下的文件路径上传(保留原文件路径的层级结构)。\n- 独立使用时，按`buildRoot`的文件路径上传(保留原文件路径的层级结构)。\n- 以上两种方式，都可以通过`setOssPath`重新配置不同的上传路径。\n\nInstall\n------------------------\n```shell\n$ npm i webpack-aliyun-oss -D\n```\n\nOptions\n------------------------\n\n- `from`: 上传哪些文件，支持glob方式，如'./build/**', 可以为glob字符串或者数组。\n  - 作为插件使用时：可选。默认为output.path下所有的文件。\n  - 独立使用时：必传\n- `dist`: 上传到oss哪个目录下，默认为oss根目录。可作为路径前缀使用。\n- `ossOptions`: OSS相关参数配置。\n  - `region`: 阿里云上传区域\n  - `accessKeyId`: 阿里云的授权accessKeyId\n  - `accessKeySecret`: 阿里云的授权accessKeySecret\n  - `bucket`: 上传到哪个bucket\n  - `stsToken`: security-token, 可选\n  - 以及oss其他可能的参数都可以在这里配置\n- `timeout`: oss超时设置，默认为30秒(30000)\n- `overwrite`: 是否覆盖oss同名文件。默认false\n- `parallel`: 并发上传个数。默认5\n- `deleteOrigin`: 上传完成是否删除原文件，默认false\n- `setOssPath`: 自定义每个文件上传路径。接收参数为当前文件路径。不传，或者所传函数返回false则按默认方式上传。\n- `setHeaders`: 配置headers的函数。接收参数为当前文件路径。不传，或者所传函数返回false则不设置header。\n- `buildRoot`: 构建目录。如：path/to/your/files。独立使用时候需要传。如果已传`setOssPath`可忽略。默认为当前工作目录。\n- `test`: 测试，仅查看文件和上传路径，但是不执行上传操作。默认false\n- `bail`: 出错是否中断上传。默认false\n- `logToLocal`: 出错信息写入本地upload.error.log。默认false\n\n#### 注意: `accessKeyId, accessKeySecret` 很重要，注意保密!!!\n\nExample\n------------------------\n\n##### 作为webpack插件使用\n```javascript\nconst WebpackAliyunOss = require('webpack-aliyun-oss');\nconst webpackConfig = {\n  // ... 省略其他\n  plugins: [new WebpackAliyunOss({\n    from: ['./build/**', '!./build/**/*.html'], // build目录下除html之外的所有文件\n    dist: '/path/in/alioss', // oss上传目录\n    ossOptions: {\n      region: 'your region',\n      accessKeyId: 'your key',\n      accessKeySecret: 'your secret',\n      bucket: 'your bucket',\n      stsToken: '\u003csecurity-token\u003e', // 可选\n    },\n\n    // 如果希望自定义上传路径，就传这个函数\n    // 否则按 output.path (webpack.config.js) 目录下的文件路径上传\n    setOssPath(filePath) {\n      // filePath为当前文件路径。函数应该返回路径+文件名。\n      // 如果返回/new/path/to/file.js，则最终上传路径为 /path/in/alioss/new/path/to/file.js\n      return '/new/path/to/file.js';\n    },\n\n    // 如果想定义header就传\n    setHeaders(filePath) {\n      // 定义当前文件header，可选\n      return {\n        'Cache-Control': 'max-age=31536000'\n      }\n    }\n  })]\n}\n```\n\n##### 独立使用\n\n```javascript\nconst WebpackAliyunOss = require('webpack-aliyun-oss');\nnew WebpackAliyunOss({\n    from: ['./build/**', '!./build/**/*.html'],\n    dist: '/path/in/alioss',\n    buildRoot: 'build', // 构建目录，如果已传setOssPath，可忽略\n    ossOptions: {\n      region: 'your region',\n      accessKeyId: 'your key',\n      accessKeySecret: 'your secret',\n      bucket: 'your bucket',\n      stsToken: '\u003csecurity-token\u003e', // 可选\n    },\n\n    // 如果希望自定义上传路径，就传这个函数\n    // 否则按`buildRoot`下的文件结构上传\n    setOssPath(filePath) {\n      // filePath为当前文件路径。函数应该返回路径+文件名。\n      // 如果返回/new/path/to/file.js，则最终上传路径为 /path/in/alioss/new/path/to/file.js\n      return '/new/path/to/file.js';\n    },\n\n    // 如果想定义header就传\n    setHeaders(filePath) {\n      return {\n        'Cache-Control': 'max-age=31536000'\n      }\n    }\n}).apply(); \n```   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgp5251%2Fwebpack-aliyun-oss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgp5251%2Fwebpack-aliyun-oss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgp5251%2Fwebpack-aliyun-oss/lists"}