08月22, 2022

upload-file-cos 自动上传静态资源工具开发

缘由:目前有些静态页面是部署在Github Pages服务,带宽有限,再加上GFW对Github限制,所以网站资源加载太慢,体验太差。于是便想把已有的静态资源上传到COS(腾讯云对象存储),通过CDN服务器加速,加快网站静态资源访问速度。但是手动上传静态资源并且替换链接过于麻烦,于是便开发一个小工具,用于解决这些重复的工作。

地址

用法

1.增加配置文件rc.json

{
    "cos_project":"test",
    "file":["index.html","www/"],
    "file_suffix":["html","css"],
    "source_suffix":["jpg","png","pdf","ppt","doc"],
    "dirs":["img","static",],
    "cos_secret_id":"",
    "cos_secret_key":"",
    "bucket":"yonghuc-1304749288",
    "region":"ap-beijing",
    "cdn_domain":"https://cdn.imyoyo.xyz/"
}

2.添加启动命令。

"scripts": {
    "upload": "upload-file-cos"
  },

扩展

可以在每次commit之前,启动命令。需要下载pre-commit

{
  "dependencies": {
    "upload-file-cos": "^1.0.3"
  },
  "scripts": {
    "upload": "upload-file-cos"
  },
  "pre-commit": [
    "upload"
  ],
  "devDependencies": {
    "pre-commit": "^1.2.2"
  }
}

本文链接:https://imyoyo.xyz/post/upload-file-cos-dev.html

-- EOF --

Comments