OSS Plugin
This plugin will upload all built assets to OSS
Install Instructions
$ npm i webpack-oss-plugin
Note: This plugin needs NodeJS > 0.12.0
Usage Instructions
I notice a lot of people are setting the directory option when the files are part of their build. Please don't set directory if your uploading your build. Using the directory option reads the files after compilation to upload instead of from the build process.
webpack-oss-plugin
Require You will need babel-polyfill to use this plugin
var OSSPlugin =
With exclude
var config = plugins: // Exclude uploading of html exclude: /.*\.html$/ // ossOptions are required ossOptions: accessKeyId: processenvOSS_ACCESS_KEY accessKeySecret: processenvOSS_ACCESS_KEY_SECRET region: 'oss-cn-shanghai' bucket: processenvOSS_BUCKET ossUploadOptions:
With include
var config = plugins: // Only upload css and js include: /.*\./ // ossOptions are required ossOptions: accessKeyId: processenvOSS_ACCESS_KEY accessKeySecret: processenvOSS_ACCESS_KEY_SECRET region: 'oss-cn-shanghai' bucket: processenvOSS_BUCKET ossUploadOptions:
With basePathTransform
var { return { }} var config = plugins: ossOptions: accessKeyId: processenvOSS_ACCESS_KEY accessKeySecret: processenvOSS_ACCESS_KEY_SECRET region: 'oss-cn-shanghai' bucket: processenvOSS_BUCKET ossUploadOptions: basePathTransform: addSha // Will output to /${mySha}/${fileName}
With Dynamic Upload Options
var config = plugins: ossOptions: accessKeyId: processenvOSS_ACCESS_KEY accessKeySecret: processenvOSS_ACCESS_KEY_SECRET region: 'oss-cn-shanghai' bucket: processenvOSS_BUCKET ossUploadOptions: { return 'Cache-Control': 'max-age=31536000' ; }
Options
exclude
: Regex to match for excluded contentinclude
: Regex to match for included contentoverwrite
: false will skip uploading if file already exists in oss. Default trueossOptions
: Provide keys for upload extention of ossConfigossUploadOptions
: Provide upload options putbasePath
: Provide the namespace where upload files on OSSbasePathTransform
: transform the base path to add a folder name. Can return a promise or a string
Contributing
All contributions are welcome. Please make a pull request and make sure things still pass after running npm run test
For tests you will need to either have the environment variables set or setup a .env file. There's a .env.sample so you can cp .env.sample .env
and fill it in. Make sure to add any new environment variables.
Commands to be aware of
WARNING: The test suit generates random files for certain checks. Ensure you delete files leftover on your Bucket.
npm run test
- Run test suit (You must have the .env file setup)npm run build
- Run build
Publish
npm run prep:patch
- Prepare for patch releasenpm run prep:minor
- Prepare for minor releasenpm run prep:major
- Prepare for major release Push a tag will automatically publish a version to NPM by travis
Thanks
Thanks to s3-plugin-webpack