diff --git a/.travis.yml b/.travis.yml index 2c1aee12..7719cd1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ before_script: - greenkeeper-lockfile-update script: - npm run lint + - npm test after_script: greenkeeper-lockfile-upload notifications: email: false 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..e676a290 100644 --- a/src/compressed-size.js +++ b/src/compressed-size.js @@ -1,5 +1,5 @@ const gzip = require('gzip-size') -const brotli = require('brotli-size') +let brotli const getCompressedSize = (data, compression = 'gzip') => { let size @@ -8,6 +8,12 @@ const getCompressedSize = (data, compression = 'gzip') => { size = gzip.sync(data) break case 'brotli': + try { + brotli = require('brotli-size') + } catch (e) { + throw new Error(`Missing optional dependency. Install it with: + npm install --save brotli-size`) + } size = brotli.sync(data) break case 'none':