Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

好用的webpack插件:webpack-oss-upload-plugin #25

Closed
Vibing opened this issue Jun 8, 2020 · 0 comments
Closed

好用的webpack插件:webpack-oss-upload-plugin #25

Vibing opened this issue Jun 8, 2020 · 0 comments
Labels
webpack webpack

Comments

@Vibing
Copy link
Owner

Vibing commented Jun 8, 2020

该 Webpack 插件用于在本地打包完成后,将打包后的文件上传至 阿里云OSS,并提供上传完成的回调


使用

安装 webpack-oss-upload-plugin

npm install webpack-oss-upload-plugin -D

在 webpack config 中使用

const prefix = `${dir}/${projectName}/${version}/`;

{
  output:{
    publicPath: `http://e-package.oss-cn-shanghai.aliyuncs.com/${prefix}`
  },
  plugins: [
    new WebpackOssUploadPlugin({
      // oss 的配置
      oss: {
        region: 'region',
        endpoint: 'endpoint',
        accessKeyId: 'accessKeyId',
        accessKeySecret: 'accessKeySecret',
        bucket: 'bucket'
      },
      // 上传后的文件路径为:publicPath/{prefix}/your-file.js
      prefix,
      // 上传完成后会调用该回调
      onComplete: (complication) => {
        
      }
    })
  ]
}

onComplete 的参数暴露了 complication 对象,里面包含当前打包的信息,你可以合理使用它

选项说明

  • oss: 阿里 oss 配置,region、endpoint、accessKeyId、accessKeySecret、bucket 这些参数是必须的
  • dir:可选项,默认为空数组,数组中的每一项表示上传至 oss 形成的目录名。比如 prefix: a/c/c/,那么上传后你的文件位置是:publicPath/a/b/c/your-file.js
  • onComplete: 可选项,当 OSS 将所有需要上传的文件上传完成后,会被调用,该方法参数为 complication 对象,里面包含当前打包的信息,你可以合理使用它

项目地址

github 地址:https://github.com/Vibing/webpack-oss-plugin

其他

如果你有其他需求或好的建议,请在 issue 中提给我

@Vibing Vibing closed this as completed Jun 8, 2020
@Vibing Vibing added the webpack webpack label Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
webpack webpack
Projects
None yet
Development

No branches or pull requests

1 participant