Skip to content

Commit 9dd1004

Browse files
authored
feat: cjs, es & umd bundles for graphql-hooks-memcache (#109)
* feat: cjs, es & umd bundles for graphql-hooks-memcache * feat: publish src dir
1 parent f7eed18 commit 9dd1004

File tree

9 files changed

+209
-137
lines changed

9 files changed

+209
-137
lines changed

Diff for: config/rollup.config.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import path from 'path'
2+
import nodeResolve from 'rollup-plugin-node-resolve'
3+
import babel from 'rollup-plugin-babel'
4+
import replace from 'rollup-plugin-replace'
5+
import commonjs from 'rollup-plugin-commonjs'
6+
import { terser } from 'rollup-plugin-terser'
7+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
8+
9+
// get the package.json for the current package
10+
const packageDir = path.join(__filename, '..')
11+
const pkg = require(`${packageDir}/package.json`)
12+
const external = [...Object.keys(pkg.peerDependencies || {})]
13+
14+
// name will be used as the global name exposed in the UMD bundles
15+
const generateRollupConfig = name => [
16+
// CommonJS
17+
{
18+
input: 'src/index.js',
19+
output: { file: `lib/${pkg.name}.js`, format: 'cjs', indent: false },
20+
external,
21+
plugins: [babel(), sizeSnapshot()]
22+
},
23+
24+
// ES
25+
{
26+
input: 'src/index.js',
27+
output: { file: `es/${pkg.name}.js`, format: 'es', indent: false },
28+
external,
29+
plugins: [babel(), sizeSnapshot()]
30+
},
31+
32+
// ES for Browsers
33+
{
34+
input: 'src/index.js',
35+
output: { file: `es/${pkg.name}.mjs`, format: 'es', indent: false },
36+
external,
37+
plugins: [
38+
commonjs(),
39+
nodeResolve({
40+
jsnext: true
41+
}),
42+
replace({
43+
'process.env.NODE_ENV': JSON.stringify('production')
44+
}),
45+
terser({
46+
compress: {
47+
pure_getters: true,
48+
unsafe: true,
49+
unsafe_comps: true,
50+
warnings: false
51+
}
52+
}),
53+
sizeSnapshot()
54+
]
55+
},
56+
57+
// UMD Development
58+
{
59+
input: 'src/index.js',
60+
output: {
61+
file: `dist/${pkg.name}.js`,
62+
format: 'umd',
63+
name,
64+
indent: false
65+
},
66+
external,
67+
plugins: [
68+
commonjs(),
69+
nodeResolve({
70+
jsnext: true
71+
}),
72+
babel({
73+
exclude: 'node_modules/**'
74+
}),
75+
replace({
76+
'process.env.NODE_ENV': JSON.stringify('development')
77+
}),
78+
sizeSnapshot()
79+
]
80+
},
81+
82+
// UMD Production
83+
{
84+
input: 'src/index.js',
85+
output: {
86+
file: `dist/${pkg.name}.min.js`,
87+
format: 'umd',
88+
name,
89+
indent: false
90+
},
91+
external,
92+
plugins: [
93+
commonjs(),
94+
nodeResolve({
95+
jsnext: true
96+
}),
97+
babel({
98+
exclude: 'node_modules/**'
99+
}),
100+
replace({
101+
'process.env.NODE_ENV': JSON.stringify('production')
102+
}),
103+
terser({
104+
compress: {
105+
pure_getters: true,
106+
unsafe: true,
107+
unsafe_comps: true,
108+
warnings: false
109+
}
110+
}),
111+
sizeSnapshot()
112+
]
113+
}
114+
]
115+
116+
export default generateRollupConfig

Diff for: package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@
1616
"babel-eslint": "10.0.1",
1717
"babel-jest": "24.1.0",
1818
"coveralls": "3.0.3",
19+
"eslint": "5.15.1",
1920
"eslint-config-prettier": "4.1.0",
2021
"eslint-plugin-prettier": "3.0.1",
21-
"eslint-plugin-react-hooks": "1.4.0",
2222
"eslint-plugin-react": "7.12.4",
23-
"eslint": "5.15.1",
23+
"eslint-plugin-react-hooks": "1.4.0",
2424
"husky": "1.3.1",
2525
"jest": "24.1.0",
2626
"lerna": "3.13.1",
2727
"lint-staged": "8.1.5",
28-
"prettier": "1.16.4"
28+
"prettier": "1.16.4",
29+
"rollup": "1.5.0",
30+
"rollup-plugin-babel": "4.3.2",
31+
"rollup-plugin-commonjs": "^9.2.1",
32+
"rollup-plugin-node-resolve": "4.0.1",
33+
"rollup-plugin-replace": "2.1.0",
34+
"rollup-plugin-size-snapshot": "0.8.0",
35+
"rollup-plugin-terser": "4.0.4"
2936
},
3037
"lint-staged": {
3138
"./packages/*/{src,test}/**/*.js": [

Diff for: packages/graphql-hooks-memcache/.size-snapshot.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"lib/graphql-hooks-memcache.js": {
3+
"bundled": 936,
4+
"minified": 621,
5+
"gzipped": 369
6+
},
7+
"es/graphql-hooks-memcache.js": {
8+
"bundled": 763,
9+
"minified": 490,
10+
"gzipped": 311,
11+
"treeshaked": {
12+
"rollup": {
13+
"code": 45,
14+
"import_statements": 45
15+
},
16+
"webpack": {
17+
"code": 1062
18+
}
19+
}
20+
},
21+
"es/graphql-hooks-memcache.mjs": {
22+
"bundled": 2080,
23+
"minified": 2076,
24+
"gzipped": 886,
25+
"treeshaked": {
26+
"rollup": {
27+
"code": 1471,
28+
"import_statements": 0
29+
},
30+
"webpack": {
31+
"code": 2521
32+
}
33+
}
34+
},
35+
"dist/graphql-hooks-memcache.js": {
36+
"bundled": 4451,
37+
"minified": 2281,
38+
"gzipped": 973
39+
},
40+
"dist/graphql-hooks-memcache.min.js": {
41+
"bundled": 2277,
42+
"minified": 2263,
43+
"gzipped": 969
44+
}
45+
}

Diff for: packages/graphql-hooks-memcache/package.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
"name": "graphql-hooks-memcache",
33
"version": "1.0.8",
44
"description": "In memory cache for graphql-hooks",
5-
"main": "index.js",
5+
"main": "lib/graphql-hooks-memcache.js",
6+
"module": "es/graphql-hooks-memcache.js",
7+
"unpkg": "dist/graphql-hooks-memcache.min.js",
68
"scripts": {
79
"test": "echo \"Error: no test specified\" && exit 1",
8-
"prepublishOnly": "cp ../../LICENSE ."
10+
"build": "../../node_modules/.bin/rollup -c",
11+
"prepublishOnly": "npm run build && cp ../../LICENSE ."
912
},
13+
"files": [
14+
"dist",
15+
"es",
16+
"lib",
17+
"src"
18+
],
1019
"keywords": [
1120
"graphql",
1221
"hooks",

Diff for: packages/graphql-hooks-memcache/rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import generateRollupConfig from '../../config/rollup.config'
2+
3+
export default generateRollupConfig('GraphQLHooksMemcache')

Diff for: packages/graphql-hooks-memcache/index.js renamed to packages/graphql-hooks-memcache/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const LRU = require('tiny-lru')
2-
const fnv1a = require('@sindresorhus/fnv1a')
1+
import LRU from 'tiny-lru'
2+
import fnv1a from '@sindresorhus/fnv1a'
33

44
function generateKey(keyObj) {
55
return fnv1a(JSON.stringify(keyObj)).toString(36)
66
}
77

8-
module.exports = function memCache({ size = 100, ttl = 0, initialState } = {}) {
8+
export default function memCache({ size = 100, ttl = 0, initialState } = {}) {
99
const lru = LRU(size, ttl)
1010

1111
if (initialState) {

Diff for: packages/graphql-hooks/.size-snapshot.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"lib/graphql-hooks.js": {
3-
"bundled": 11191,
4-
"minified": 5591,
5-
"gzipped": 1912
3+
"bundled": 11781,
4+
"minified": 5768,
5+
"gzipped": 1968
66
},
77
"es/graphql-hooks.js": {
8-
"bundled": 10846,
9-
"minified": 5299,
10-
"gzipped": 1837,
8+
"bundled": 11436,
9+
"minified": 5476,
10+
"gzipped": 1896,
1111
"treeshaked": {
1212
"rollup": {
1313
"code": 67,
@@ -19,9 +19,9 @@
1919
}
2020
},
2121
"es/graphql-hooks.mjs": {
22-
"bundled": 3939,
23-
"minified": 3939,
24-
"gzipped": 1515,
22+
"bundled": 4091,
23+
"minified": 4091,
24+
"gzipped": 1566,
2525
"treeshaked": {
2626
"rollup": {
2727
"code": 67,
@@ -33,13 +33,13 @@
3333
}
3434
},
3535
"dist/graphql-hooks.js": {
36-
"bundled": 11438,
37-
"minified": 5099,
38-
"gzipped": 1915
36+
"bundled": 12028,
37+
"minified": 5268,
38+
"gzipped": 1975
3939
},
4040
"dist/graphql-hooks.min.js": {
41-
"bundled": 5055,
42-
"minified": 5055,
43-
"gzipped": 1891
41+
"bundled": 5224,
42+
"minified": 5224,
43+
"gzipped": 1948
4444
}
4545
}

Diff for: packages/graphql-hooks/package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
"module": "es/graphql-hooks.js",
77
"unpkg": "dist/graphql-hooks.min.js",
88
"scripts": {
9-
"build": "rollup -c",
9+
"build": "../../node_modules/.bin/rollup -c",
1010
"prepublishOnly": "npm run build && cp ../../README.md . && cp ../../LICENSE ."
1111
},
1212
"files": [
1313
"dist",
1414
"es",
15-
"lib"
15+
"lib",
16+
"src"
1617
],
1718
"keywords": [
1819
"graphql",
@@ -34,12 +35,7 @@
3435
"react": "16.8.4",
3536
"react-dom": "16.8.4",
3637
"react-hooks-testing-library": "0.3.4",
37-
"react-testing-library": "6.0.0",
38-
"rollup": "1.5.0",
39-
"rollup-plugin-babel": "4.3.2",
40-
"rollup-plugin-node-resolve": "4.0.1",
41-
"rollup-plugin-size-snapshot": "0.8.0",
42-
"rollup-plugin-terser": "4.0.4"
38+
"react-testing-library": "6.0.0"
4339
},
4440
"repository": {
4541
"type": "git",

0 commit comments

Comments
 (0)