Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import path from 'path'
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'

// get the package.json for the current package
const packageDir = path.join(__filename, '..')
const pkg = require(`${packageDir}/package.json`)
const external = [...Object.keys(pkg.peerDependencies || {})]

// name will be used as the global name exposed in the UMD bundles
const generateRollupConfig = name => [
// CommonJS
{
input: 'src/index.js',
output: { file: `lib/${pkg.name}.js`, format: 'cjs', indent: false },
external,
plugins: [babel(), sizeSnapshot()]
},

// ES
{
input: 'src/index.js',
output: { file: `es/${pkg.name}.js`, format: 'es', indent: false },
external,
plugins: [babel(), sizeSnapshot()]
},

// ES for Browsers
{
input: 'src/index.js',
output: { file: `es/${pkg.name}.mjs`, format: 'es', indent: false },
external,
plugins: [
commonjs(),
nodeResolve({
jsnext: true
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
}),
sizeSnapshot()
]
},

// UMD Development
{
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.js`,
format: 'umd',
name,
indent: false
},
external,
plugins: [
commonjs(),
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**'
}),
replace({
'process.env.NODE_ENV': JSON.stringify('development')
}),
sizeSnapshot()
]
},

// UMD Production
{
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.min.js`,
format: 'umd',
name,
indent: false
},
external,
plugins: [
commonjs(),
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**'
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
}),
sizeSnapshot()
]
}
]

export default generateRollupConfig
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
"babel-eslint": "10.0.1",
"babel-jest": "24.1.0",
"coveralls": "3.0.3",
"eslint": "5.15.1",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-react-hooks": "1.4.0",
"eslint-plugin-react": "7.12.4",
"eslint": "5.15.1",
"eslint-plugin-react-hooks": "1.4.0",
"husky": "1.3.1",
"jest": "24.1.0",
"lerna": "3.13.1",
"lint-staged": "8.1.5",
"prettier": "1.16.4"
"prettier": "1.16.4",
"rollup": "1.5.0",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "4.0.1",
"rollup-plugin-replace": "2.1.0",
"rollup-plugin-size-snapshot": "0.8.0",
"rollup-plugin-terser": "4.0.4"
},
"lint-staged": {
"./packages/*/{src,test}/**/*.js": [
Expand Down
45 changes: 45 additions & 0 deletions packages/graphql-hooks-memcache/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"lib/graphql-hooks-memcache.js": {
"bundled": 936,
"minified": 621,
"gzipped": 369
},
"es/graphql-hooks-memcache.js": {
"bundled": 763,
"minified": 490,
"gzipped": 311,
"treeshaked": {
"rollup": {
"code": 45,
"import_statements": 45
},
"webpack": {
"code": 1062
}
}
},
"es/graphql-hooks-memcache.mjs": {
"bundled": 2080,
"minified": 2076,
"gzipped": 886,
"treeshaked": {
"rollup": {
"code": 1471,
"import_statements": 0
},
"webpack": {
"code": 2521
}
}
},
"dist/graphql-hooks-memcache.js": {
"bundled": 4451,
"minified": 2281,
"gzipped": 973
},
"dist/graphql-hooks-memcache.min.js": {
"bundled": 2277,
"minified": 2263,
"gzipped": 969
}
}
12 changes: 10 additions & 2 deletions packages/graphql-hooks-memcache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
"name": "graphql-hooks-memcache",
"version": "1.0.8",
"description": "In memory cache for graphql-hooks",
"main": "index.js",
"main": "lib/graphql-hooks-memcache.js",
"module": "es/graphql-hooks-memcache.js",
"unpkg": "dist/graphql-hooks-memcache.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "cp ../../LICENSE ."
"build": "../../node_modules/.bin/rollup -c",
"prepublishOnly": "npm run build && cp ../../LICENSE ."
},
"files": [
"dist",
"es",
"lib"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should publish the src folder to npm too. It can be useful to devs when debugging. Thoughts? @jackdclark @bmullan91

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, can do 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

],
"keywords": [
"graphql",
"hooks",
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql-hooks-memcache/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import generateRollupConfig from '../../config/rollup.config'

export default generateRollupConfig('GraphQLHooksMemcache')
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const LRU = require('tiny-lru')
const fnv1a = require('@sindresorhus/fnv1a')
import LRU from 'tiny-lru'
import fnv1a from '@sindresorhus/fnv1a'

function generateKey(keyObj) {
return fnv1a(JSON.stringify(keyObj)).toString(36)
}

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

if (initialState) {
Expand Down
30 changes: 15 additions & 15 deletions packages/graphql-hooks/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"lib/graphql-hooks.js": {
"bundled": 11191,
"minified": 5591,
"gzipped": 1912
"bundled": 11781,
"minified": 5768,
"gzipped": 1968
},
"es/graphql-hooks.js": {
"bundled": 10846,
"minified": 5299,
"gzipped": 1837,
"bundled": 11436,
"minified": 5476,
"gzipped": 1896,
"treeshaked": {
"rollup": {
"code": 67,
Expand All @@ -19,9 +19,9 @@
}
},
"es/graphql-hooks.mjs": {
"bundled": 3939,
"minified": 3939,
"gzipped": 1515,
"bundled": 4091,
"minified": 4091,
"gzipped": 1566,
"treeshaked": {
"rollup": {
"code": 67,
Expand All @@ -33,13 +33,13 @@
}
},
"dist/graphql-hooks.js": {
"bundled": 11438,
"minified": 5099,
"gzipped": 1915
"bundled": 12028,
"minified": 5268,
"gzipped": 1975
},
"dist/graphql-hooks.min.js": {
"bundled": 5055,
"minified": 5055,
"gzipped": 1891
"bundled": 5224,
"minified": 5224,
"gzipped": 1948
}
}
9 changes: 2 additions & 7 deletions packages/graphql-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "es/graphql-hooks.js",
"unpkg": "dist/graphql-hooks.min.js",
"scripts": {
"build": "rollup -c",
"build": "../../node_modules/.bin/rollup -c",
"prepublishOnly": "npm run build && cp ../../README.md . && cp ../../LICENSE ."
},
"files": [
Expand Down Expand Up @@ -34,12 +34,7 @@
"react": "16.8.4",
"react-dom": "16.8.4",
"react-hooks-testing-library": "0.3.4",
"react-testing-library": "6.0.0",
"rollup": "1.5.0",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-node-resolve": "4.0.1",
"rollup-plugin-size-snapshot": "0.8.0",
"rollup-plugin-terser": "4.0.4"
"react-testing-library": "6.0.0"
},
"repository": {
"type": "git",
Expand Down
Loading