Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #640 from kevinzwhuang/weigh-in-gzip-size
Browse files Browse the repository at this point in the history
Add script to create gzipped file in development & report gzip size on weigh in
  • Loading branch information
helfer committed Apr 20, 2017
2 parents c7d560a + 34142cc commit 52d153a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ script:
- npm run compile
- cd examples/create-react-app && npm test && cd ../../
- npm run filesize
- python node_modules/travis-weigh-in/weigh_in.py ./dist/index.min.js || true # ignore size errors
- python node_modules/travis-weigh-in/weigh_in.py ./dist/index.min.js.gz || true # ignore size errors

# Allow Travis tests to run in containers.
sudo: false
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"posttest": "npm run lint",
"filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=20",
"compile": "tsc",
"compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/index.js --i react --i apollo-client -o=./dist/index.js && npm run minify:browser",
"compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/index.js --i react --i apollo-client -o=./dist/index.js && npm run minify:browser && npm run compress:browser",
"minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js",
"compress:browser": "./scripts/gzip.js --file=./dist/index.min.js",
"watch": "tsc -w",
"lint": "tslint 'src/*.ts*' && tslint 'test/*.ts*'"
},
Expand Down Expand Up @@ -97,7 +98,6 @@
"enzyme-to-json": "^1.1.5",
"flow-bin": "^0.44.0",
"graphql": "^0.9.1",
"gzip-size": "^3.0.0",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"jest": "^19.0.2",
Expand Down
3 changes: 1 addition & 2 deletions scripts/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
var Flags = require('minimist')(process.argv.slice(2)),
Fs = require('fs'),
Path = require('path'),
GzipSize = require('gzip-size'),
PrettyBytes = require('pretty-bytes'),
Colors = require('colors');

Expand All @@ -18,7 +17,7 @@ let totalSize = 0,

var rawSize = Fs.statSync(filePath).size;
totalSize = PrettyBytes(rawSize);
var rawGzippedSize = GzipSize.sync(Fs.readFileSync(filePath, 'utf8'));
var rawGzippedSize = Fs.statSync(`${filePath}.gz`).size;
totalGzippedSize = PrettyBytes(rawGzippedSize);

console.log('\n');
Expand Down
15 changes: 15 additions & 0 deletions scripts/gzip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
'use strict';

var Flags = require('minimist')(process.argv.slice(1)),
Fs = require('fs'),
Path = require('path'),
Zlib = require('zlib');

var filePath = Path.resolve(process.cwd(), Flags.file);
var gzip = Zlib.createGzip({level: 9});

var readStream = Fs.createReadStream(filePath);
var writeStream = Fs.createWriteStream(`${filePath}.gz`);

readStream.pipe(gzip).pipe(writeStream);

0 comments on commit 52d153a

Please sign in to comment.