0.0.3 • Published 2 years ago

@star-fed/nos-webpack-plugin v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NOS Webpack Plugin

Webpack 编译后的文件上传到 NOS

该插件上传功能依赖NOS Node.js SDK,感谢该插件作者。

功能

  • 支持并行上传
  • 支持不重复上传

安装

yarn add @star-fed/nos-webpack-plugin --dev

使用

webpack.config.js

const NosWebpackPlugin = require('@star-fen/nos-webpack-plugin');

const nosUploadConfig = {
	accessKey: 'test',
	accessSecret: 'test',
	endpoint: 'test',
	bucketName: 'test',
	nosPrefix: 'test',
}
module.exports = {
  // ... Webpack 相关配置
  plugins: [
    new NosWebpackPlugin(nosUploadConfig)
  ]
}

或者在项目目录下新建 .nosconfig 文件,并且在 .gitignore 忽略此文件

.nosconfig

module.exports = {
  accessKey: 'nos access key', // required
  accessSecret: 'nos access secret', // required
  bucketName: 'demo-test', // required
  endpoint: 'https://nos-jd.163yun.com', // required
  excludes: ['assets/**.map4', '*.map'],
  prefix: '',
  cdnName: '',
  parallel: 10,
  force: true
}

Options

NameTypeDefaultRequiredDescription
accessKey{String}trueNOS Access Key
accessSecret{String}trueNOS Secret Key
bucketName{String}trueNOS 空间名
endpoint{String}trueNOS 不同地域不同配置
excludes{Array[string]}'.DS_Store'false忽略的文件类型
prefix{string}''falseNOS 的二级路径 / 文件夹名
cdnName{string}''falseCDN 域名,代替 bucketName 对外使用
parallel{number}10false同时上传文件数,避免产生大量的并发请求
force{Boolean}falsefalse是否强制上传,就不检查文件是否存在
usePublicPath{Boolean}truefalse设置 webpack publicPath,会使用 cdnName 或者 bucketName + prefix
  • bucketName 不需要不携带通信协议: star-dev-test-server
  • excludes 匹配相关文件或文件夹,详细使用请看: micromatch
    • *.map 不上传文件后缀为 map 的文件
    • assets/**.map 不上传 assets 文件夹下文件后缀为 map 的文件

License

Released under the MIT License.