Skip to content

Commit

Permalink
try to use zlib.brotliCompressSync if available
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameiswhm committed Jan 26, 2019
1 parent daeb866 commit becfa3e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
include:
- &current
stage: Webpack tests (current node)
node_js: 10
node_js: 11
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART

- <<: *current
node_js: 10
node_js: 11
env: WEBPACK_VERSION=3 JOB_PART=test
script: npm run travis:$JOB_PART

Expand All @@ -23,6 +23,11 @@ jobs:
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART

- <<: *old
node_js: 10
env: WEBPACK_VERSION=3 JOB_PART=test
script: npm run travis:$JOB_PART

- <<: *old
node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=test
Expand All @@ -31,7 +36,7 @@ jobs:
- stage: Webpack tests (canary, current node)
before_script: npm i --no-save git://github.com/webpack/webpack.git#master
script: npm run travis:$JOB_PART
node_js: 10
node_js: 11
env: WEBPACK_VERSION=canary JOB_PART=test
addons:
apt:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

### 1.1.0
Added native brotli support via [zlib.brotliCompressSync](https://nodejs.org/api/zlib.html#zlib_zlib_brotlicompress_buffer_options_callback) for Node v11.7+.

### 1.0.0
Added native support for Webpack 4 hooks API (to avoid `DeprecationWarning`), along with backwards compatibility for legacy Webpack versions.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Greenkeeper badge](https://badges.greenkeeper.io/mynameiswhm/brotli-webpack-plugin.svg)](https://greenkeeper.io/)

This plugin compresses assets with [Brotli](https://github.com/google/brotli) compression algorithm using [iltorb](https://github.com/MayhemYDG/iltorb#brotliencodeparams) library for serving it with [ngx_brotli](https://github.com/google/ngx_brotli) or such.
This plugin compresses assets with [Brotli](https://github.com/google/brotli) compression algorithm using [zlib](https://nodejs.org/api/zlib.html#zlib_zlib_brotlicompress_buffer_options_callback), [iltorb](https://github.com/MayhemYDG/iltorb#brotliencodeparams) or [brotli.js](https://github.com/foliojs/brotli.js) libraries for serving it with [ngx_brotli](https://github.com/google/ngx_brotli) or such.

## Installation

Expand Down
10 changes: 9 additions & 1 deletion compress.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
function adapter() {
try {
var zlib = require('zlib');
if (zlib.hasOwnProperty('brotliCompressSync')) {
return zlib.brotliCompressSync;
}
} catch (err) {}

try {
console.log('warning: couldn\'t find native brotli support in zlib library. trying to fall back to iltorb.');
var iltorb = require('iltorb');
return iltorb.compress;
} catch (err) {
console.log('warning: couldn\'t load iltorb library. trying to fall back to brotli.');
console.log('warning: couldn\'t load iltorb library. trying to fall back to brotli.js.');
console.log(err);

try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brotli-webpack-plugin",
"version": "1.0.0",
"version": "1.1.0",
"author": {
"name": "Ilia Saulenko",
"email": "[email protected]",
Expand Down

0 comments on commit becfa3e

Please sign in to comment.