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

next-hsuc

v0.0.6

Published

react服务端渲染,打包文件上传到云端,提高加载速度

Downloads

51

Readme

描述

将webpack打包生成的文件上传到云端,以提高加载速度
目前,支持阿里云、华为云、腾讯云、七牛云和又拍云,以及自定义扩展。

安装

npm install next-hsuc --save-dev

要求

Node

Node.js >= 10.10.0 required

使用

package.json 添加命令

// cross-env 需要先安装,npm install cross-env --save-dev

"dev": "cross-env PORT=80 PROXY=true node server.js",
"build": "cross-env NODE_ENV=production next build",
"start": "cross-env NODE_ENV=production PORT=80 PROXY=true node server.js"

server.js 可以用自己的,这个只是举例

const express = require('express');
const next = require('next');
const { NODE_ENV, PORT=3000, PROXY } = process.env;
const app = next({dir: '.', dev: NODE_ENV !== "production"});

app.prepare()
  .then(() => {
    const server = express();

    server.listen(PORT, (err) => {
      if (err) {
        throw err
      }
      console.log(`> Ready on port ${PORT} [${NODE_ENV}]`);
    })
  })
  .catch((ex) => {
    console.log('An error occurred, unable to start the server')
    console.log(ex)
  });

next.config.js 配置文件

// webpack.config.js
const withPlugins = require ("next-compose-plugins");
const {PHASE_DEVELOPMENT_SERVER} = require('next-server/constants');
const Hsuc = require('hsuc');
const HsucOptions = {
    cloudFolder: "<云端文件夹>",
    domain: "<域名>",
    enable: true,
    // 阿里云(任选其一)
    aliyun: {
      region: "<OSS region>",
      accessKeyId: "<Your accessKeyId>",
      accessKeySecret: "<Your accessKeySecret>",
      bucket: "<Your bucket name>"
    }
    // 华为云(任选其一)
    huawei: {
      accessKeyId: "<Provide your Access Key>",
      secretAccessKey: "<Provide your Secret Key>",
      server: "<https://your-endpoint>",
      bucket: "<Bucket>"
    },
    // 腾讯云(任选其一)
    tencent: {
      secretId: "<SecretId>",
      secretKey: "<SecretKey>",
      bucket: "<Bucket>",
      region: "<Region>"
    },
    // 七牛云(任选其一)
    qiniu: {
      accessKey: "<ACCESS_KEY>",
      secretKey: "<SECRET_KEY>",
      bucket: "<Bucket>"
    },
    // 又拍云(任选其一)
    upyun: {
      serviceName: "<service name>",
      operatorName: "<operator name>",
      operatorPassword: "<operator password>",
    }
}

const nextConfig = {
  webpack: (config, options) => {
    config.plugins.push(
      new Hsuc(Object.assign(HsucOptions, options))
    )

    return config;
  },
  distDir: "_next",
  ["!" + (HsucOptions.enable ? PHASE_DEVELOPMENT_SERVER : "")]: {
    assetPrefix: `${HsucOptions.domain}/${HsucOptions.cloudFolder}`,
  }
};

module.exports = withPlugins(
    [...], 
    nextConfig);
)

hsuc(options)支持的选项

  • aliyun - 初始化阿里云OSS参数。
  • huawei - 初始化华为云OBS参数。
  • tencent - 初始化腾讯云COS参数。
  • qiniu - 初始化七牛云参数。
  • upyun - 初始化又拍云参数。
  • enable[boolean] - 是否启用,默认true
  • removePrevVersion[boolean] - 是否删除云端以前的版本,默认false
  • log[boolean] - 是否显示日志,默认false
  • cover[boolean|RegExp] - 图片、字体文件是否覆盖,默认false,填写正则时可以参考/\.(png|jpe?g|gif|ico|woff2?|svg|ttf|eot)$/
  • custom[js文件,例如require("./template.js")] - 自定义上传文件,可以参照项目中的文件template.js文件,能够作为除aliyun huawei qiniu upyun之外的扩展或修改。

对象存储CORS规则设置

注意事项

  • 云端访问权限请设置为“公共读写”或者“公共读”
  • options参数中aliyunhuaweitencentqiniuupyun同时配置只有第一个有效
  • 该插件在开发模式时禁用
  • options.deletePrevBuildFile 启用该项会把以前的版本删掉,请谨慎。

部署

npm run build
mpm run start