npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oss-cdn-helper

v0.1.0

Published

将静态资源上传到 OSS,并且可以去掉 html 文件的 `.html` 后缀,并修改 `Content-Type` 为 `text/html` 达到可以用 `/example` 代替 `/example.html` 访问网页的效果

Downloads

10

Readme

oss-cdn-helper

将静态资源上传到 OSS,并且可以去掉 html 文件的 .html 后缀,并修改 Content-Typetext/html 达到可以用 /example 代替 /example.html 访问网页的效果

  1. 安装相关依赖:

    npm install oss-cdn-helper --save-dev
  2. 部署并刷新 CDN

    import path from "path";
    import OssCdnHelper from "oss-cdn-helper";
    
    const process = async () => {
      const files = await OssCdnHelper.upload({
        uploadPath: path.resolve(__dirname, "../build"),
        targetPath: "/target",
        region: "oss-cn-beijing",
        bucket: "tp-hansel-dev",
        removeHtmlSuffix: true,
        removeHtmlSuffixIgnore: [],
        cleanTargetPath: false
      });
      // files:
      // { fileName: '/target/index',
      //   filePath:
      //    '/Users/shianqi/workspace/node/oss-cdn-helper/test/build/index.html',
      //   option: { headers: [Object] } },
      // { fileName: '/target/main',
      //   filePath:
      //    '/Users/shianqi/workspace/node/oss-cdn-helper/test/build/main.html',
      //   option: { headers: [Object] } },
      // ....
      await OssCdnHelper.refresh({
        enabled: true,
        paths: ["http://www.baidu.com/public/", "https://www.baidu.com/public/"],
        files: [
          "http://www.baidu.com/public/index.html",
          "https://www.baidu.com/public/index.html"
        ]
      });
    };
    
    process();

参数

await OssCdnHelper.upload({
  uploadPath: path.resolve(__dirname, "../build"), // 要上传的文件夹,绝对路径
  targetPath: "/target", // 上传到 OSS 上文件夹的位置
  region: "oss-cn-beijing", // OSS 位置
  bucket: "tp-hansel-dev", // bucket 名称
  removeHtmlSuffix: true, // 是否去掉 .html 后缀上传
  removeHtmlSuffixIgnore: [], // 忽略去掉 .html 后缀的路径
  cleanTargetPath: false // 上传前是否先清空 OSS 上的目标文件夹(暂时无效)
});

await OssCdnHelper.refresh({
  enabled: true, // 是否刷新 CDN
  paths: [
    // 要刷新的 CDN 的 URL 地址
    "http://www.baidu.com/public/",
    "https://www.baidu.com/public/"
  ]
});

TODO

  • 上传前清空目标文件夹