https://github.com/kszitt/next-hsuc
Render on the react server, package files and upload them to the cloud to improve the loading speed
https://github.com/kszitt/next-hsuc
aliyun-oss cloud huaweicloud next nextjs obs oss qiniu upyun webpack
Last synced: about 2 months ago
JSON representation
Render on the react server, package files and upload them to the cloud to improve the loading speed
- Host: GitHub
- URL: https://github.com/kszitt/next-hsuc
- Owner: kszitt
- Created: 2020-04-16T09:01:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T07:46:27.000Z (about 5 years ago)
- Last Synced: 2025-03-27T09:52:12.794Z (2 months ago)
- Topics: aliyun-oss, cloud, huaweicloud, next, nextjs, obs, oss, qiniu, upyun, webpack
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 6
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 语言
[中文](https://github.com/kszitt/next-hsuc/blob/master/README_ZH.md)## describe
Upload the files generated by web pack to the cloud to improve the loading speed
Currently, Alibaba cloud, Huawei cloud, Tencent cloud, qiniu cloud and remake cloud, as well as user-defined extensions are supported.## install
```bash
npm install next-hsuc --save-dev
```## required
### Node
Node.js >= 10.10.0## use
#### package.json add script
```bash
// cross-env needs to be installed first, 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 You can use your own. This is just an example
```bash
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
```bash
// 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,
// Alicloud (Choose one)
aliyun: {
region: "",
accessKeyId: "",
accessKeySecret: "",
bucket: ""
}
// Hua Weiyun (Choose one)
huawei: {
accessKeyId: "",
secretAccessKey: "",
server: "",
bucket: ""
},
// Tencent cloud (Choose one)
tencent: {
secretId: "",
secretKey: "",
bucket: "",
region: ""
},
// Qiniu cloud (Choose one)
qiniu: {
accessKey: "",
secretKey: "",
bucket: ""
},
// Clapping clouds again (Choose one)
upyun: {
serviceName: "",
operatorName: "",
operatorPassword: "",
}
}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) supported options
- `aliyun` - Initialize alicloud OSS parameters
- `huawei` - Initialize Huawei cloud OBS parameters.
- `tencent` - Initialize Tencent cloud cos parameters.
- `qiniu` - Initialize the Qiniu cloud parameter.
- `upyun` - Initialize the re shooting cloud parameter.
- `enable[boolean]` - Enable at the beginning, default`true`。
- `removePrevVersion[boolean]` - Delete previous versions of cloud or not, default`false`
- `log[boolean]` - Display log, default`true`
- `cover[boolean|RegExp]` - Overwrite file, default`false`. Please refer to`/\.(png|jpe?g|gif|ico|woff2?|svg|ttf|eot)$/`。
- `custom[js文件,例如require("./template.js")]` - User defined upload file, you can refer to the `template.js` in the project## Object store CORS rule settings
- `aliyun` Set according to [CORS](https://help.aliyun.com/document_detail/44570.html?spm=5176.8465980.0.0.12871450vh6n2z)
- `huawei` Set according to [CORS](https://support.huaweicloud.com/sdk-browserjs-devg-obs/obs_24_0201.html)
- `tencent` Set according to [CORS](https://cloud.tencent.com/document/product/436/13318)
- `qiniu` Set according to [CORS](https://console.upyun.com/services/kszitt/antileechFile/)
- `upyun` Set according to [CORS](http://docs.upyun.com/cdn/feature/#cors)## matters needing attention
- Please set the cloud access to "public read / write" or "public read"
- In the options parameter, `aliyun`, `huawei`, `tencent`, `qiniu` and `upyun` are configured at the same time, only the first one is valid
- The plug-in is disabled in development mode
- `options.deletePrevBuildFile` Enabling this item will delete the previous version. Please be careful.## deploy
``` hash
npm run build
mpm run start
```