Skip to content

Commit c656450

Browse files
committed
incorporate rollup into build system
1 parent 6c58a14 commit c656450

File tree

8 files changed

+480
-53
lines changed

8 files changed

+480
-53
lines changed

.size-snapshot.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"dist/react-popper-tooltip.js": {
3+
"bundled": 16587,
4+
"minified": 7824,
5+
"gzipped": 2402
6+
},
7+
"dist/react-popper-tooltip.min.js": {
8+
"bundled": 7824,
9+
"minified": 7824,
10+
"gzipped": 2402
11+
},
12+
"lib/index.cjs.js": {
13+
"bundled": 12754,
14+
"minified": 7979,
15+
"gzipped": 1986
16+
},
17+
"lib/index.esm.js": {
18+
"bundled": 12342,
19+
"minified": 7648,
20+
"gzipped": 1923,
21+
"treeshaked": {
22+
"rollup": {
23+
"code": 6202,
24+
"import_statements": 697
25+
},
26+
"webpack": {
27+
"code": 7775
28+
}
29+
}
30+
}
31+
}

babel.config.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
const presets = [
2-
[
3-
'@babel/env',
4-
{
5-
useBuiltIns: 'usage'
6-
}
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
modules: false
7+
}
8+
],
9+
['@babel/react']
710
],
8-
[
9-
'@babel/react',
10-
{
11-
useBuiltIns: true
12-
}
11+
plugins: [
12+
'@babel/plugin-proposal-class-properties',
13+
'transform-react-remove-prop-types'
1314
]
14-
];
15-
16-
const plugins = [
17-
'@babel/plugin-transform-runtime',
18-
'@babel/plugin-proposal-class-properties'
19-
];
20-
21-
const env = {
22-
esm: {
23-
presets: [
24-
[
25-
'@babel/env',
26-
{
27-
modules: false,
28-
useBuiltIns: 'usage'
29-
}
30-
]
31-
]
32-
}
3315
};
34-
35-
module.exports = { presets, plugins, env };

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
"type": "git",
88
"url": "https://github.com/mohsinulhaq/react-popper-tooltip"
99
},
10-
"main": "lib/cjs/index.js",
11-
"module": "lib/esm/index.js",
10+
"browser": "dist/react-popper-tooltip.min.js",
11+
"main": "lib/index.cjs.js",
12+
"module": "lib/index.esm.js",
13+
"style": "dist/styles.css",
1214
"typings": "typings/react-popper-tooltip.d.ts",
1315
"files": [
1416
"lib",
1517
"dist",
1618
"typings/react-popper-tooltip.d.ts"
1719
],
1820
"scripts": {
19-
"build": "yarn build:cjs; yarn build:esm; mkdir -p dist && cp src/styles.css dist",
20-
"build:cjs": "babel --delete-dir-on-start src -d lib/cjs",
21-
"build:esm": "babel --delete-dir-on-start --env-name esm src -d lib/esm",
21+
"build": "rimraf dist lib && rollup -c && cp src/styles.css dist",
2222
"prepublishOnly": "yarn lint && yarn build && yarn docs:deploy",
2323
"docs": "docz dev",
2424
"docs:build": "docz build",
@@ -111,6 +111,7 @@
111111
"@babel/preset-env": "^7.1.0",
112112
"@babel/preset-react": "^7.0.0",
113113
"babel-eslint": "^9.0.0",
114+
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
114115
"docz": "^0.11.2",
115116
"docz-plugin-css": "^0.11.0",
116117
"eslint": "^5.6.0",
@@ -123,6 +124,13 @@
123124
"prettier": "^1.14.3",
124125
"prop-types": "^15.6.2",
125126
"react": "^16.5.2",
126-
"react-dom": "^16.5.2"
127+
"react-dom": "^16.5.2",
128+
"rimraf": "^2.6.2",
129+
"rollup": "^0.66.2",
130+
"rollup-plugin-babel": "^4.0.3",
131+
"rollup-plugin-commonjs": "^9.1.8",
132+
"rollup-plugin-node-resolve": "^3.4.0",
133+
"rollup-plugin-size-snapshot": "^0.7.0",
134+
"rollup-plugin-terser": "^3.0.0"
127135
}
128136
}

rollup.config.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import babel from 'rollup-plugin-babel';
2+
import resolve from 'rollup-plugin-node-resolve';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import { terser } from 'rollup-plugin-terser';
5+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
6+
import pkg from './package.json';
7+
8+
const input = 'src/index.js';
9+
const name = 'TooltipTrigger';
10+
const globals = {
11+
react: 'React',
12+
'react-dom': 'ReactDOM',
13+
'prop-types': 'PropTypes',
14+
'react-popper': 'ReactPopper'
15+
};
16+
const external = id => !id.startsWith('.') && !id.startsWith('/');
17+
const getBabelOptions = ({ useESModules = true } = {}) => ({
18+
exclude: 'node_modules/**',
19+
runtimeHelpers: true,
20+
plugins: [['@babel/plugin-transform-runtime', { useESModules }]]
21+
});
22+
23+
export default [
24+
{
25+
input,
26+
output: {
27+
name,
28+
file: 'dist/react-popper-tooltip.js',
29+
format: 'iife',
30+
globals
31+
},
32+
external: Object.keys(globals),
33+
plugins: [
34+
resolve({
35+
browser: true,
36+
modulesOnly: true
37+
}),
38+
commonjs({
39+
include: 'node_modules/**'
40+
}),
41+
babel(getBabelOptions()),
42+
sizeSnapshot()
43+
]
44+
},
45+
{
46+
input,
47+
output: {
48+
name,
49+
file: 'dist/react-popper-tooltip.min.js',
50+
format: 'iife',
51+
globals
52+
},
53+
external: Object.keys(globals),
54+
plugins: [
55+
resolve({
56+
browser: true,
57+
modulesOnly: true
58+
}),
59+
commonjs({
60+
include: 'node_modules/**'
61+
}),
62+
babel(getBabelOptions()),
63+
terser(),
64+
sizeSnapshot()
65+
]
66+
},
67+
{
68+
input,
69+
output: { file: pkg.main, format: 'cjs' },
70+
external,
71+
plugins: [babel(getBabelOptions({ useESModules: false })), sizeSnapshot()]
72+
},
73+
{
74+
input,
75+
output: { file: pkg.module, format: 'esm' },
76+
external,
77+
plugins: [babel(getBabelOptions()), sizeSnapshot()]
78+
}
79+
];

src/Tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { PureComponent } from 'react';
33
import { findDOMNode } from 'react-dom';
44
import T from 'prop-types';
5-
import { TooltipContext } from './TooltipTrigger';
5+
import { TooltipContext } from './utils';
66
import { callAll } from './utils';
77

88
const MUTATION_OBSERVER_CONFIG = {

src/TooltipTrigger.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createPortal } from 'react-dom';
66
import T from 'prop-types';
77
import { Manager, Reference, Popper } from 'react-popper';
88
import Tooltip from './Tooltip';
9-
import { callAll, noop } from './utils';
9+
import { TooltipContext, callAll, noop } from './utils';
1010

1111
const DEFAULT_MODIFIERS = {
1212
preventOverflow: {
@@ -15,8 +15,6 @@ const DEFAULT_MODIFIERS = {
1515
}
1616
};
1717

18-
export const TooltipContext = React.createContext({});
19-
2018
export default class TooltipTrigger extends PureComponent {
2119
static propTypes = {
2220
/**

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import React from 'react';
2+
3+
export const TooltipContext = React.createContext({});
4+
15
export const callAll = (...fns) => (...args) =>
26
fns.forEach(fn => fn && fn(...args));
37

0 commit comments

Comments
 (0)