From eecc3f95e000608694c5099ae8a1748bfa93ed5d Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 30 Apr 2018 11:51:33 -0400 Subject: [PATCH] Move try/catch around require --- src/compressed-size.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compressed-size.js b/src/compressed-size.js index 6d61f78d..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') +let brotli const getCompressedSize = (data, compression = 'gzip') => { let size @@ -9,12 +10,12 @@ const getCompressedSize = (data, compression = 'gzip') => { break case 'brotli': try { - const brotli = require('brotli-size') - size = brotli.sync(data) + 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: