1.0.1 • Published 5 years ago

smarter-qiniu-webpack-plugin v1.0.1

Weekly downloads
6
License
-
Repository
github
Last release
5 years ago

smarter-qiniu-webpack-plugin

Webpack 编译结束后,智能的把文件同步到 七牛云存储

功能

  • 支持并发上传
  • 智能分析,增量上传,不重复上传

安装

npm install --save-dev smarter-qiniu-webpack-plugin

使用

webpack.config.js

const SmarterQiniuWebpackPlugin = require('smarter-qiniu-webpack-plugin');

module.exports = {
  // ... Webpack 相关配置
  plugins: [
    new SmarterQiniuWebpackPlugin()
  ]
}

在项目目录下新建 qiniu_config.js 文件,并且在 .gitignore 忽略此文件

.qiniu_config.js

module.exports = {
  accessKey: 'qiniu access key', // required
  secretKey: 'qiniu secret key', // required
  bucket: 'demo', // required
  bucketDomain: 'https://domain.bkt.clouddn.com', // required
  exclude(path) {
    return /logo.*png/.test(path)
  },
  batch: 10,
  mutilThread: 8,
  root: '/static',
  notFoundPage: 'index.html',
  refresh: true,
  refreshIndexThrottle: 100,
  prefetch: true,
  prefetchSortMax: true
}

Options

NameTypeDefaultRequiredDescription
accessKey{String}true七牛 Access Key
secretKey{String}true七牛 Secret Key
bucket{String}true七牛 空间名
bucketDomain{String}true七牛 空间域名
exclude{Function}false排除文件/文件夹
batch{Number}10false同时上传文件数
mutilThread{Number}cpus.length - 1false计算文件差异的线程并发数
root{String}webpack.outputfalse根目录的位置
notFoundPage{String}false当空间404时使用的文件
refresh{Boolean}truefalse是否刷新新替换的文件
refreshIndexThrottle{Number}100false当刷新文件的数量大于这个值时,直接更新目录
prefetch{Boolean}falsefalse是否预取新的文件
prefetchSortMax{String}truefalse是否优先预取大文件

注意

由于七牛云储存的问题,可能会出现上传未被修改的文件,原因是七牛云返回的qetag值并非是最新的。 解决办法是确认刷新缓存后,用浏览器或其他工具禁用缓存的情况下访问,若能访问到最新的文件内容,那么其qetag值也就能被更新了。