webpack-alioss-plugin

阿里 oss-webpack 自动上传插件

MIT License

Downloads
486
Stars
45
Committers
6

webpack-alioss-plugin

eslint

OSS , webpack webpack OSS

** webpack 345**


  • , () -
  • (3)
  • gzip ()
    • CDN gzip - header gzip, CDN gzip
    • ,
    • abc.js hash , existCheck: false

:

  • webpack ( htmlmainfest ) OSS , CDN
  • webpack js``css hash , eg: detail-question.34d71b4.js
  • CDN ,
  • html
  • (300KB ) webpack url-loader js (base64)
  • (300KB ) OSS , OSS
  • OSS : ACL accessKey

npm install -D webpack-alioss-plugin

: webpackConfig.output.publicPath prefix oss url, eg: '//res.xueboren.com/auto_upload_ci/your-project-name/'

: (****)

//  CI :

// WEBPACK_ALIOSS_PLUGIN_ACCESS_KEY_ID  accessKeyId
// WEBPACK_ALIOSS_PLUGIN_ACCESS_KEY_SECRET  accessKeySecret
// WEBPACK_ALIOSS_PLUGIN_BUCKET  bucket
// WEBPACK_ALIOSS_PLUGIN_REGION  region
// (,  'auto_upload_ci') WEBPACK_ALIOSS_PLUGIN_OSS_BASE_DIR  ossBaseDir

const AliOSSPlugin = require('webpack-alioss-plugin')

webpackConfig.plugins.push(new AliOSSPlugin())

:

const AliOSSPlugin = require('webpack-alioss-plugin')

webpackConfig.plugins.push(new AliOSSPlugin({
  auth: {
    accessKeyId: '', //  OSS 
    accessKeySecret: '', //  OSS 
    region: 'oss-cn-hangzhou', // OSS , : oss-cn-hangzhou
    bucket: 'abc', // OSS ,  OSS 
  },
  ossBaseDir: 'auto_upload_ci',
  project: 'my-project-name', // ()
}))

- vue.config.js

const WebpackAliossPlugin = require('webpack-alioss-plugin');

const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
  publicPath: isProduction ? '//res.xueboren.com/auto_upload_ci/your-project-name/' : '',
  configureWebpack: {
    plugins: isProduction ? [
      new WebpackAliossPlugin(),
    ] : [],
  },
};

OSS accessKey accessKeySecret , ,

:

| | | | --- | --- | --- | --- | accessKeyId | WEBPACK_ALIOSS_PLUGIN_ACCESS_KEY_ID | | OSS key | accessKeySecret | WEBPACK_ALIOSS_PLUGIN_ACCESS_KEY_SECRET | | OSS secret | bucket | WEBPACK_ALIOSS_PLUGIN_BUCKET | | OSS | region | WEBPACK_ALIOSS_PLUGIN_REGION | | OSS | exclude | - | /.*\.html$/ | OSS | retry | - | 3 | , 0 | gzip | - | true | gzip | existCheck | - | true | (, ) | enableLog | WEBPACK_ALIOSS_PLUGIN_ENABLE_LOG | false | | ignoreError | WEBPACK_ALIOSS_PLUGIN_IGNORE_ERROR | false | webpack | removeMode | WEBPACK_ALIOSS_PLUGIN_REMOVE_MODE | true | OSS , | prefix() | WEBPACK_ALIOSS_PLUGIN_PREFIX | false | ~~, , accessKey ~~ | ossBaseDir | WEBPACK_ALIOSS_PLUGIN_OSS_BASE_DIR | auto_upload_ci | OSS | project | - | package.json name | OSS , | options | - | undefined | . | envPrefix | - | '' | . key() |

  • prefix: ~~, accessKey ~~
  • ignoreError: webpack
    • true: , , webpack
    • false: , webpack
  • removeMode: OSS ,
    • true: ()
    • false: