Skip to content

Commit c41c382

Browse files
authored
Upgrade build (#102)
- replaced size-snapshot plugin with custom implementation - transpile only for `> 1%, not ie 11` - dropped umd bundles support (use codesandbox) Size before minified: 1610 b gzipped: 768 b Size now min: 1480 b gzip: 753 b brotli: 684 b
1 parent d337d85 commit c41c382

6 files changed

+4202
-4385
lines changed

.browserslistrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> 1%
2+
not ie 11

.size-snapshot.json

-30
This file was deleted.

package.json

+20-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"build:code": "rollup -c",
1515
"build:flow": "echo \"// @flow\n\nexport * from '../src'\" > dist/rifm.cjs.js.flow",
16-
"build": "rimraf dist && npm run build:code && npm run build:flow",
16+
"build": "rimraf dist && yarn build:code && yarn build:flow",
1717
"dev": "NODE_ICU_DATA=`yarn -s run node-full-icu-path` next dev",
1818
"jest": "NODE_ICU_DATA=`yarn -s run node-full-icu-path` jest",
1919
"test": "eslint --ignore-path .gitignore ./ && flow check && yarn test:ts && yarn jest",
@@ -99,41 +99,42 @@
9999
]
100100
},
101101
"devDependencies": {
102-
"@babel/core": "^7.3.3",
103-
"@babel/preset-env": "^7.3.1",
104-
"@babel/preset-flow": "^7.0.0",
105-
"@babel/preset-react": "^7.0.0",
102+
"@babel/core": "^7.9.6",
103+
"@babel/preset-env": "^7.9.6",
104+
"@babel/preset-flow": "^7.9.0",
105+
"@babel/preset-react": "^7.9.4",
106106
"@material-ui/core": "^4.0.0",
107107
"@material-ui/styles": "^4.0.0",
108-
"@rollup/plugin-replace": "^2.3.1",
108+
"@rollup/plugin-babel": "^5.0.2",
109+
"@rollup/plugin-replace": "^2.3.2",
109110
"@typescript-eslint/parser": "^1.9.0",
110111
"alea": "^0.0.9",
111112
"babel-core": "^7.0.0-bridge.0",
112-
"babel-eslint": "^9.0.0",
113-
"babel-jest": "^23.2.0",
113+
"babel-eslint": "^10.1.0",
114+
"babel-jest": "^26.0.1",
115+
"brotli-size": "^4.0.0",
114116
"emotion": "^10.0.17",
115-
"eslint": "^5.0.1",
116-
"eslint-plugin-flowtype": "^2.49.3",
117-
"eslint-plugin-jest": "^21.22.0",
118-
"eslint-plugin-jsx-a11y": "^6.0.3",
119-
"eslint-plugin-react": "^7.9.1",
117+
"eslint": "^7.1.0",
118+
"eslint-plugin-flowtype": "^5.1.0",
119+
"eslint-plugin-jest": "^23.13.1",
120+
"eslint-plugin-jsx-a11y": "^6.2.3",
121+
"eslint-plugin-react": "^7.20.0",
120122
"flow-bin": "^0.109.0",
121123
"full-icu": "^1.3.0",
122124
"gh-pages": "^1.2.0",
125+
"gzip-size": "^5.1.1",
123126
"husky": "^4.2.1",
124-
"jest": "^23.3.0",
127+
"jest": "^26.0.1",
125128
"libphonenumber-js": "^1.2.15",
126129
"lint-staged": "^10.0.7",
127-
"next": "^9.1.1",
130+
"next": "^9.4.2",
128131
"prettier": "^1.19.1",
129132
"react": "^16.8.2",
130133
"react-dom": "^16.8.2",
131134
"react-test-renderer": "^16.8.2",
132135
"rimraf": "^2.6.1",
133-
"rollup": "^1.31.0",
134-
"rollup-plugin-babel": "^4.3.3",
135-
"rollup-plugin-size-snapshot": "^0.11.0",
136-
"rollup-plugin-terser": "^5.2.0",
136+
"rollup": "^2.10.8",
137+
"rollup-plugin-terser": "^6.0.1",
137138
"typescript": "^3.4.5"
138139
},
139140
"peerDependencies": {

rollup.config.js

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
1+
import fs from 'fs';
2+
import path from 'path';
13
import replace from '@rollup/plugin-replace';
2-
import babel from 'rollup-plugin-babel';
4+
import { babel } from '@rollup/plugin-babel';
35
import { terser } from 'rollup-plugin-terser';
4-
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
6+
import gzipSize from 'gzip-size';
7+
import * as brotliSize from 'brotli-size';
58
import pkg from './package.json';
69

710
const input = './src/index.js';
8-
const name = 'Rifm';
9-
const globals = { react: 'React' };
10-
const external = Object.keys(globals);
11+
const external = id =>
12+
id.startsWith('.') === false && path.isAbsolute(id) === false;
1113

1214
const babelOptions = {
1315
babelrc: false,
14-
presets: [['@babel/env', { loose: true }], '@babel/flow', '@babel/react'],
16+
configFile: false,
17+
babelHelpers: 'bundled',
18+
presets: [
19+
['@babel/preset-env', { bugfixes: true, loose: true }],
20+
'@babel/flow',
21+
'@babel/react',
22+
],
1523
};
1624

1725
export default [
18-
{
19-
input,
20-
output: { file: 'dist/rifm.umd.js', format: 'umd', name, globals },
21-
external,
22-
plugins: [
23-
babel(babelOptions),
24-
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
25-
],
26-
},
27-
28-
{
29-
input,
30-
output: { file: 'dist/rifm.min.js', format: 'umd', name, globals },
31-
external,
32-
plugins: [
33-
babel(babelOptions),
34-
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
35-
terser(),
36-
],
37-
},
38-
3926
{
4027
input,
4128
output: { file: pkg.main, format: 'cjs' },
@@ -47,7 +34,7 @@ export default [
4734
input,
4835
output: { file: pkg.module, format: 'esm' },
4936
external,
50-
plugins: [babel(babelOptions), sizeSnapshot()],
37+
plugins: [babel(babelOptions)],
5138
},
5239

5340
// to check esm production size
@@ -58,7 +45,24 @@ export default [
5845
plugins: [
5946
babel(babelOptions),
6047
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
61-
sizeSnapshot(),
48+
terser(),
49+
{
50+
generateBundle(outputOptions, bundle) {
51+
let sizeInfo = '';
52+
for (const [name, chunk] of Object.entries(bundle)) {
53+
const parsedSize = chunk.code.length;
54+
const gzippedSize = gzipSize.sync(chunk.code);
55+
const brotliedSize = brotliSize.sync(chunk.code);
56+
sizeInfo += `Size of ${name}
57+
=============================
58+
min: ${parsedSize} b
59+
gzip: ${gzippedSize} b
60+
brotli: ${brotliedSize} b\n`.replace(/^\s+/gm, '');
61+
}
62+
console.info(sizeInfo);
63+
fs.writeFileSync('size-snapshot.txt', sizeInfo, 'utf-8');
64+
},
65+
},
6266
],
6367
},
6468
];

size-snapshot.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Size of rifm.esm.production.js
2+
=============================
3+
min: 1480 b
4+
gzip: 753 b
5+
brotli: 684 b

0 commit comments

Comments
 (0)