diff --git a/README.md b/README.md index 8ef592e6..1d224d17 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ npx bundlesize #### 1) Add the path and maxSize in your `package.json`. By default the gzipped size is tested. You can use the `compression` option to change this. (`gzip`, `brotli`, or `none`). +To use the `brotli` compression option, you must install the peer dependency: `npm install --save brotli-size` + ```json { "name": "your cool library", diff --git a/package.json b/package.json index ecec9008..03ec0f92 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "license": "MIT", "dependencies": { "axios": "^0.17.0", - "brotli-size": "0.0.1", "bytes": "^3.0.0", "ci-env": "^1.4.0", "commander": "^2.11.0", diff --git a/src/compressed-size.js b/src/compressed-size.js index e7846924..0fd06307 100644 --- a/src/compressed-size.js +++ b/src/compressed-size.js @@ -1,5 +1,6 @@ +const { warn } = require('prettycli') const gzip = require('gzip-size') -const brotli = require('brotli-size') +let brotli const getCompressedSize = (data, compression = 'gzip') => { let size @@ -8,7 +9,13 @@ const getCompressedSize = (data, compression = 'gzip') => { size = gzip.sync(data) break case 'brotli': - size = brotli.sync(data) + try { + brotli = require('brotli-size') + } catch (e) { + warn(`Missing optional dependency. Install it with: + npm install --save brotli-size`) + } + size = brotli ? brotli.sync(data) : 0 break case 'none': default: